Gerrit Bot has uploaded this change for review.
gopls: replace `directory` directive with `use`
### gopls
- Replace `directory` directive with `use` directive in order to make `gopls` follow the latest specification of the [`workspace`](https://go.googlesource.com/proposal/+/master/design/45713-workspace.md)
After this [CL](https://go-review.googlesource.com/c/mod/+/359412/) has been introduced on the gotip, now `directory` directive for `go.work` has been renamed to `use`. Due to this change, current `gopls` does not treat `go.work` file correctly (e.g. `textDocument/definition` does not indicate proper files). So, this PR just renames `directory` directive to `use`.
Change-Id: I5ac452b05a1ec3c2f254b872bec2454998ff3081
GitHub-Last-Rev: d9a6607a13e9b8fc81fa90a5133f47d02318b861
GitHub-Pull-Request: golang/tools#359
---
M internal/mod/modfile/rule.go
M gopls/internal/regtest/workspace/workspace_test.go
M internal/lsp/cache/workspace.go
3 files changed, 35 insertions(+), 17 deletions(-)
diff --git a/gopls/internal/regtest/workspace/workspace_test.go b/gopls/internal/regtest/workspace/workspace_test.go
index 666f023..94c73a6 100644
--- a/gopls/internal/regtest/workspace/workspace_test.go
+++ b/gopls/internal/regtest/workspace/workspace_test.go
@@ -14,12 +14,11 @@
"testing"
"golang.org/x/tools/gopls/internal/hooks"
- . "golang.org/x/tools/internal/lsp/regtest"
- "golang.org/x/tools/internal/lsp/source"
-
"golang.org/x/tools/internal/lsp/command"
"golang.org/x/tools/internal/lsp/fake"
"golang.org/x/tools/internal/lsp/protocol"
+ . "golang.org/x/tools/internal/lsp/regtest"
+ "golang.org/x/tools/internal/lsp/source"
"golang.org/x/tools/internal/testenv"
)
@@ -684,7 +683,7 @@
-- go.work --
go 1.17
-directory (
+use (
./moda/a
)
`
@@ -717,7 +716,7 @@
env.WriteWorkspaceFile("go.work", `
go 1.17
-directory (
+use (
./moda/a
./modb
)
@@ -748,7 +747,7 @@
env.Await(env.DoneWithOpen())
env.SetBufferContent("go.work", `go 1.17
-directory (
+use (
./moda/a
)`)
@@ -1148,7 +1147,7 @@
)
env.WriteWorkspaceFile("go.work", `go 1.16
-directory (
+use (
a
b
)
diff --git a/internal/lsp/cache/workspace.go b/internal/lsp/cache/workspace.go
index bb9125b..c9911dc 100644
--- a/internal/lsp/cache/workspace.go
+++ b/internal/lsp/cache/workspace.go
@@ -14,12 +14,13 @@
"sync"
"golang.org/x/mod/modfile"
+ errors "golang.org/x/xerrors"
+
"golang.org/x/tools/internal/event"
"golang.org/x/tools/internal/lsp/source"
workfile "golang.org/x/tools/internal/mod/modfile"
"golang.org/x/tools/internal/span"
"golang.org/x/tools/internal/xcontext"
- errors "golang.org/x/xerrors"
)
type workspaceSource int
@@ -489,7 +490,7 @@
return nil, nil, errors.Errorf("parsing go.work: %w", err)
}
modFiles := make(map[span.URI]struct{})
- for _, dir := range workFile.Directory {
+ for _, dir := range workFile.Use {
// The resulting modfile must use absolute paths, so that it can be
// written to a temp directory.
dir.DiskPath = absolutePath(root, dir.DiskPath)
diff --git a/internal/mod/modfile/rule.go b/internal/mod/modfile/rule.go
index 163a2db..a5c1304 100644
--- a/internal/mod/modfile/rule.go
+++ b/internal/mod/modfile/rule.go
@@ -29,20 +29,21 @@
"golang.org/x/mod/modfile"
"golang.org/x/mod/module"
+
"golang.org/x/tools/internal/mod/lazyregexp"
)
// A WorkFile is the parsed, interpreted form of a go.work file.
type WorkFile struct {
- Go *modfile.Go
- Directory []*Directory
- Replace []*modfile.Replace
+ Go *modfile.Go
+ Use []*Use
+ Replace []*modfile.Replace
Syntax *modfile.FileSyntax
}
-// A Directory is a single directory statement.
-type Directory struct {
+// A Use is a single use statement.
+type Use struct {
DiskPath string // TODO(matloob): Replace uses module.Version for new. Do that here?
ModulePath string // Module path in the comment.
Syntax *modfile.Line
@@ -99,7 +100,7 @@
})
}
continue
- case "module", "directory", "replace":
+ case "module", "use", "replace":
for _, l := range x.Line {
f.add(&errs, x, l, x.Token[0], l.Token, fix, strict)
}
@@ -169,7 +170,7 @@
f.Go = &modfile.Go{Syntax: line}
f.Go.Version = args[0]
- case "directory":
+ case "use":
if len(args) != 1 {
errorf("usage: %s ../local/directory", verb) // TODO(matloob) better example; most directories will be subdirectories of go.work dir
return
@@ -179,7 +180,7 @@
errorf("invalid quoted string: %v", err)
return
}
- f.Directory = append(f.Directory, &Directory{
+ f.Use = append(f.Use, &Use{
DiskPath: s,
Syntax: line,
})
To view, visit change 378754. To unsubscribe, or for help writing mail filters, visit settings.
Gerrit Bot uploaded patch set #2 to this change.
gopls: replace `directory` directive with `use` for `go.work`
### gopls
- Replace `directory` directive with `use` directive in order to make `gopls` follow the latest specification of the [`workspace`](https://go.googlesource.com/proposal/+/master/design/45713-workspace.md)
After this [CL](https://go-review.googlesource.com/c/mod/+/359412/) has been introduced on the gotip, now `directory` directive for `go.work` has been renamed to `use`. Due to this change, current `gopls` does not treat `go.work` file correctly (e.g. `textDocument/definition` does not indicate proper files). So, this PR just renames `directory` directive to `use`.
Change-Id: I5ac452b05a1ec3c2f254b872bec2454998ff3081
GitHub-Last-Rev: d9a6607a13e9b8fc81fa90a5133f47d02318b861
GitHub-Pull-Request: golang/tools#359
---
M internal/mod/modfile/rule.go
M gopls/internal/regtest/workspace/workspace_test.go
M internal/lsp/cache/workspace.go
3 files changed, 35 insertions(+), 17 deletions(-)
To view, visit change 378754. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Michael Matloob.
Patch set 2:Code-Review -1
1 comment:
Patchset:
We need to switch to using the latest released version of x/mod, rather than updating our outdated copy.
I have an in-progress CL that adds support for go.work here:
https://go.dev/cl/374154
This will be done for our next gopls release (v0.8.0).
To view, visit change 378754. To unsubscribe, or for help writing mail filters, visit settings.
Gopher Robot abandoned this change.
To view, visit change 378754. To unsubscribe, or for help writing mail filters, visit settings.