mirror of https://github.com/golang/go.git
internal/lsp: fix go generate command for subdirs
The go generate command was not honoring its dir argument, instead just running in the workspace root. Fixes golang/go#41566 Change-Id: I5fb96a765cf4fb2572e2a8a2e560e02f0760023f Reviewed-on: https://go-review.googlesource.com/c/tools/+/256818 Trust: Robert Findley <rfindley@google.com> Run-TryBot: Robert Findley <rfindley@google.com> Reviewed-by: Rebecca Stambler <rstambler@golang.org> gopls-CI: kokoro <noreply+kokoro@google.com> TryBot-Result: Go Bot <gobot@golang.org>
This commit is contained in:
parent
06f3a46a9d
commit
7bb30d1408
|
|
@ -20,7 +20,7 @@ func TestGenerateProgress(t *testing.T) {
|
|||
module fake.test
|
||||
|
||||
go 1.14
|
||||
-- generate.go --
|
||||
-- lib/generate.go --
|
||||
// +build ignore
|
||||
|
||||
package main
|
||||
|
|
@ -30,7 +30,7 @@ import "io/ioutil"
|
|||
func main() {
|
||||
ioutil.WriteFile("generated.go", []byte("package lib\n\nconst answer = 42"), 0644)
|
||||
}
|
||||
-- lib.go --
|
||||
-- lib/lib.go --
|
||||
package lib
|
||||
|
||||
func GetAnswer() int {
|
||||
|
|
@ -42,13 +42,13 @@ func GetAnswer() int {
|
|||
|
||||
runner.Run(t, generatedWorkspace, func(t *testing.T, env *Env) {
|
||||
env.Await(
|
||||
env.DiagnosticAtRegexp("lib.go", "answer"),
|
||||
env.DiagnosticAtRegexp("lib/lib.go", "answer"),
|
||||
)
|
||||
env.RunGenerate(".")
|
||||
env.RunGenerate("./lib")
|
||||
env.Await(
|
||||
OnceMet(
|
||||
CompletedWork(lsp.DiagnosticWorkTitle(lsp.FromDidChangeWatchedFiles), 1),
|
||||
EmptyDiagnostics("lib.go")),
|
||||
EmptyDiagnostics("lib/lib.go")),
|
||||
)
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -347,9 +347,11 @@ func (s *Server) runGoGenerate(ctx context.Context, snapshot source.Snapshot, ur
|
|||
|
||||
er := &eventWriter{ctx: ctx, operation: "generate"}
|
||||
args := []string{"-x"}
|
||||
dir := uri.Filename()
|
||||
if recursive {
|
||||
args = append(args, "./...")
|
||||
dir = filepath.Join(dir, "...")
|
||||
}
|
||||
args = append(args, dir)
|
||||
|
||||
stderr := io.MultiWriter(er, workDoneWriter{work})
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue