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)) +}