Skip to content

Commit d3d2f59

Browse files
committed
fix typescript-language-server
1 parent 83146b1 commit d3d2f59

File tree

2 files changed

+69
-4
lines changed

2 files changed

+69
-4
lines changed

internal/lsp/client.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -218,10 +218,10 @@ func (c *Client) InitializeLSPClient(ctx context.Context, workspaceDir string) (
218218
path := strings.ToLower(c.Cmd.Path)
219219
switch {
220220
case strings.Contains(path, "typescript-language-server"):
221-
// err := initializeTypescriptLanguageServer(ctx, c, workspaceDir)
222-
// if err != nil {
223-
// return nil, err
224-
// }
221+
err := initializeTypescriptLanguageServer(ctx, c, workspaceDir)
222+
if err != nil {
223+
return nil, err
224+
}
225225
}
226226

227227
return &result, nil

internal/lsp/typescript.go

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package lsp
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"os"
7+
"path/filepath"
8+
"strings"
9+
)
10+
11+
// initializeTypescriptLanguageServer initializes the TypeScript language server
12+
// with specific configurations and opens all TypeScript files in the workspace.
13+
func initializeTypescriptLanguageServer(ctx context.Context, client *Client, workspaceDir string) error {
14+
lspLogger.Info("Initializing TypeScript language server with workspace: %s", workspaceDir)
15+
16+
// First, open all TypeScript files in the workspace
17+
if err := openAllTypeScriptFiles(ctx, client, workspaceDir); err != nil {
18+
return fmt.Errorf("failed to open TypeScript files: %w", err)
19+
}
20+
21+
return nil
22+
}
23+
24+
// openAllTypeScriptFiles finds and opens all TypeScript files in the workspace
25+
func openAllTypeScriptFiles(ctx context.Context, client *Client, workspaceDir string) error {
26+
lspLogger.Info("Opening all TypeScript files in workspace: %s", workspaceDir)
27+
28+
// Track count of opened files for logging
29+
fileCount := 0
30+
31+
// Walk the workspace directory
32+
err := filepath.Walk(workspaceDir, func(path string, info os.FileInfo, err error) error {
33+
if err != nil {
34+
return err
35+
}
36+
37+
// Skip directories
38+
if info.IsDir() {
39+
// Skip node_modules, .git, and other common directories to avoid processing too many files
40+
basename := filepath.Base(path)
41+
if basename == "node_modules" || basename == ".git" || strings.HasPrefix(basename, ".") {
42+
return filepath.SkipDir
43+
}
44+
return nil
45+
}
46+
47+
// Check if file is a TypeScript file
48+
if strings.HasSuffix(path, ".ts") || strings.HasSuffix(path, ".tsx") {
49+
if err := client.OpenFile(ctx, path); err != nil {
50+
lspLogger.Warn("Failed to open TypeScript file %s: %v", path, err)
51+
return nil // Continue with other files even if one fails
52+
}
53+
fileCount++
54+
}
55+
56+
return nil
57+
})
58+
59+
if err != nil {
60+
return fmt.Errorf("error walking workspace directory: %w", err)
61+
}
62+
63+
lspLogger.Info("Opened %d TypeScript files", fileCount)
64+
return nil
65+
}

0 commit comments

Comments
 (0)