From fd294ab11aed8d198f7a12a86dfe0a970fdab143 Mon Sep 17 00:00:00 2001 From: Rebecca Stambler Date: Sun, 12 Jul 2020 14:56:06 -0400 Subject: [PATCH] internal/lsp: watch go.{mod,sum} files, as well as Go files Not sure how this hasn't come up earlier. We aren't noticing file changes on-disk for go.mod/go.sum files. Fixes golang/vscode-go#297 Change-Id: I4532a252f330404515efec244a9c266a765e6bcb Reviewed-on: https://go-review.googlesource.com/c/tools/+/242160 Run-TryBot: Rebecca Stambler TryBot-Result: Gobot Gobot Reviewed-by: Robert Findley --- internal/lsp/general.go | 3 +-- internal/lsp/regtest/modfile_test.go | 36 ++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/internal/lsp/general.go b/internal/lsp/general.go index 83a3bb585d..8d38c57e60 100644 --- a/internal/lsp/general.go +++ b/internal/lsp/general.go @@ -171,7 +171,7 @@ func (s *Server) initialized(ctx context.Context, params *protocol.InitializedPa Method: "workspace/didChangeWatchedFiles", RegisterOptions: protocol.DidChangeWatchedFilesRegistrationOptions{ Watchers: []protocol.FileSystemWatcher{{ - GlobPattern: fmt.Sprintf("%s/**.go", dir), + GlobPattern: fmt.Sprintf("%s/**.{go,mod,sum}", dir), Kind: float64(protocol.WatchChange + protocol.WatchDelete + protocol.WatchCreate), }}, }, @@ -199,7 +199,6 @@ func (s *Server) addFolders(ctx context.Context, folders []protocol.WorkspaceFol wg.Wait() work.End(ctx, "Done.") }() - }() } for _, folder := range folders { diff --git a/internal/lsp/regtest/modfile_test.go b/internal/lsp/regtest/modfile_test.go index 5caf8758b8..692a9f3519 100644 --- a/internal/lsp/regtest/modfile_test.go +++ b/internal/lsp/regtest/modfile_test.go @@ -7,6 +7,7 @@ package regtest import ( "testing" + "golang.org/x/tools/internal/lsp" "golang.org/x/tools/internal/lsp/protocol" "golang.org/x/tools/internal/lsp/tests" "golang.org/x/tools/internal/testenv" @@ -170,3 +171,38 @@ require ( } }, WithProxy(proxy)) } + +// TODO: For this test to be effective, the sandbox's file watcher must respect +// the file watching GlobPattern in the capability registration. See +// golang/go#39384. +func TestModuleChangesOnDisk(t *testing.T) { + testenv.NeedsGo1Point(t, 14) + + const mod = ` +-- go.mod -- +module mod.com + +go 1.12 + +require example.com v1.2.3 +-- main.go -- +package main + +func main() { + fmt.Println(blah.Name) +` + const want = `module mod.com + +go 1.12 +` + runner.Run(t, mod, func(t *testing.T, env *Env) { + env.Await( + CompletedWork(lsp.DiagnosticWorkTitle(lsp.FromInitialWorkspaceLoad), 1), + env.DiagnosticAtRegexp("go.mod", "require"), + ) + env.Sandbox.RunGoCommand(env.Ctx, "mod", "tidy") + env.Await( + EmptyDiagnostics("go.mod"), + ) + }, WithProxy(proxy)) +}