@@ -319,30 +319,6 @@ func (c *Client) NotifyChange(ctx context.Context, filepath string) error {
319 return c.client.NotifyDidChangeTextDocument(ctx, uri, int(fileInfo.Version), changes)
319 return c.client.NotifyDidChangeTextDocument(ctx, uri, int(fileInfo.Version), changes)
322−// CloseFile closes a file in the LSP server.
324−// NOTE: this is only ever called on LSP shutdown.
325−func (c *Client) CloseFile(ctx context.Context, filepath string) error {
327− uri := string(protocol.URIFromPath(filepath))
329− if _, exists := c.openFiles.Get(uri); !exists {
330− return nil // Already closed
333− if cfg.Options.DebugLSP {
334− slog.Debug("Closing file", "file", filepath)
337− if err := c.client.NotifyDidCloseTextDocument(ctx, uri); err != nil {
341− c.openFiles.Del(uri)
346// IsFileOpen checks if a file is currently open.
322// IsFileOpen checks if a file is currently open.
347func (c *Client) IsFileOpen(filepath string) bool {
323func (c *Client) IsFileOpen(filepath string) bool {
348 uri := string(protocol.URIFromPath(filepath))
324 uri := string(protocol.URIFromPath(filepath))
@@ -353,29 +329,16 @@ func (c *Client) IsFileOpen(filepath string) bool {
353// CloseAllFiles closes all currently open files.
329// CloseAllFiles closes all currently open files.
354func (c *Client) CloseAllFiles(ctx context.Context) {
330func (c *Client) CloseAllFiles(ctx context.Context) {
355 cfg := config.Get()
331 cfg := config.Get()
356− filesToClose := make([]string, 0, c.openFiles.Len())
332+ debugLSP := cfg != nil && cfg.Options.DebugLSP
358− // First collect all URIs that need to be closed
359 for uri := range c.openFiles.Seq2() {
333 for uri := range c.openFiles.Seq2() {
360− // Convert URI back to file path using proper URI handling
334+ if debugLSP {
361− filePath, err := protocol.DocumentURI(uri).Path()
335+ slog.Debug("Closing file", "file", uri)
363− slog.Error("Failed to convert URI to path for file closing", "uri", uri, "error", err)
366− filesToClose = append(filesToClose, filePath)
337+ if err := c.client.NotifyDidCloseTextDocument(ctx, uri); err != nil {
369− // Then close them all
370− for _, filePath := range filesToClose {
371− err := c.CloseFile(ctx, filePath)
372− if err != nil && cfg != nil && cfg.Options.DebugLSP {
373− slog.Warn("Error closing file", "file", filePath, "error", err)
338+ slog.Warn("Error closing rile", "uri", uri, "error", err)
375− }
341+ c.openFiles.Del(uri)
377− if cfg != nil && cfg.Options.DebugLSP {
378− slog.Debug("Closed all files", "files", filesToClose)