From 43817b877abff5cd8f71c46f3f6616289fe67ad6 Mon Sep 17 00:00:00 2001 From: Radek Simko Date: Fri, 1 Sep 2023 10:10:21 +0100 Subject: [PATCH] langserver: Avoid re-processing open files on didChangeWatchedFiles --- .../handlers/did_change_watched_files.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/internal/langserver/handlers/did_change_watched_files.go b/internal/langserver/handlers/did_change_watched_files.go index cc9dc8a7..c91d094f 100644 --- a/internal/langserver/handlers/did_change_watched_files.go +++ b/internal/langserver/handlers/did_change_watched_files.go @@ -146,6 +146,20 @@ func (svc *service) DidChangeWatchedFiles(ctx context.Context, params lsp.DidCha } if change.Type == protocol.Changed { + // Check if document is open and skip running any jobs + // as we already did so as part of textDocument/didChange + // which clients should always send for *open* documents + // even if they change outside of the IDE. + docHandle := document.HandleFromURI(rawURI) + isOpen, err := svc.stateStore.DocumentStore.IsDocumentOpen(docHandle) + if err != nil { + svc.logger.Printf("error when checking open document (%q changed): %s", rawURI, err) + } + if isOpen { + svc.logger.Printf("document is open - ignoring event for %q", rawURI) + continue + } + ph, err := modHandleFromRawOsPath(ctx, rawPath) if err != nil { if err == ErrorSkip {