@@ -218,17 +218,24 @@ 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
228228}
229229
230230func (c * Client ) Close () error {
231- // Close stdin first to signal the server
231+ // Try to close all open files first
232+ ctx , cancel := context .WithTimeout (context .Background (), 5 * time .Second )
233+ defer cancel ()
234+
235+ // Attempt to close files but continue shutdown regardless
236+ c .CloseAllFiles (ctx )
237+
238+ // Close stdin to signal the server
232239 if err := c .stdin .Close (); err != nil {
233240 return fmt .Errorf ("failed to close stdin: %w" , err )
234241 }
@@ -281,6 +288,7 @@ func (c *Client) OpenFile(ctx context.Context, filepath string) error {
281288 }
282289 c .openFilesMu .Unlock ()
283290
291+ // Skip files that do not exist or cannot be read
284292 content , err := os .ReadFile (filepath )
285293 if err != nil {
286294 return fmt .Errorf ("error reading file: %w" , err )
@@ -306,6 +314,10 @@ func (c *Client) OpenFile(ctx context.Context, filepath string) error {
306314 }
307315 c .openFilesMu .Unlock ()
308316
317+ if debug {
318+ log .Printf ("Opened file: %s" , filepath )
319+ }
320+
309321 return nil
310322}
311323
@@ -383,6 +395,32 @@ func (c *Client) IsFileOpen(filepath string) bool {
383395 return exists
384396}
385397
398+ // CloseAllFiles closes all currently open files
399+ func (c * Client ) CloseAllFiles (ctx context.Context ) {
400+ c .openFilesMu .Lock ()
401+ filesToClose := make ([]string , 0 , len (c .openFiles ))
402+
403+ // First collect all URIs that need to be closed
404+ for uri := range c .openFiles {
405+ // Convert URI back to file path by trimming "file://" prefix
406+ filePath := strings .TrimPrefix (uri , "file://" )
407+ filesToClose = append (filesToClose , filePath )
408+ }
409+ c .openFilesMu .Unlock ()
410+
411+ // Then close them all
412+ for _ , filePath := range filesToClose {
413+ err := c .CloseFile (ctx , filePath )
414+ if err != nil && debug {
415+ log .Printf ("Error closing file %s: %v" , filePath , err )
416+ }
417+ }
418+
419+ if debug {
420+ log .Printf ("Closed %d files" , len (filesToClose ))
421+ }
422+ }
423+
386424func (c * Client ) GetFileDiagnostics (uri protocol.DocumentUri ) []protocol.Diagnostic {
387425 c .diagnosticsMu .RLock ()
388426 defer c .diagnosticsMu .RUnlock ()
0 commit comments