1
0
mirror of https://github.com/golang/go synced 2024-11-18 08:14:41 -07:00

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 <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
This commit is contained in:
Rebecca Stambler 2020-07-12 14:56:06 -04:00
parent 7342f9734a
commit fd294ab11a
2 changed files with 37 additions and 2 deletions

View File

@ -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 {

View File

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