[tools] gopls: replace `directory` directive with `use`

44 views
Skip to first unread message

Gerrit Bot (Gerrit)

unread,
Jan 15, 2022, 7:16:16 AM1/15/22
to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

Gerrit Bot has uploaded this change for review.

View Change

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-Project: tools
Gerrit-Branch: master
Gerrit-Change-Id: I5ac452b05a1ec3c2f254b872bec2454998ff3081
Gerrit-Change-Number: 378754
Gerrit-PatchSet: 1
Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
Gerrit-MessageType: newchange

Gerrit Bot (Gerrit)

unread,
Jan 15, 2022, 7:19:20 AM1/15/22
to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

Gerrit Bot uploaded patch set #2 to this change.

View 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.

Gerrit-Project: tools
Gerrit-Branch: master
Gerrit-Change-Id: I5ac452b05a1ec3c2f254b872bec2454998ff3081
Gerrit-Change-Number: 378754
Gerrit-PatchSet: 2
Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
Gerrit-MessageType: newpatchset

Robert Findley (Gerrit)

unread,
Jan 18, 2022, 4:10:34 PM1/18/22
to Gerrit Bot, goph...@pubsubhelper.golang.org, Michael Matloob, Hyang-Ah Hana Kim, golang-co...@googlegroups.com

Attention is currently required from: Michael Matloob.

Patch set 2:Code-Review -1

View Change

1 comment:

  • Patchset:

    • Patch Set #2:

      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.

Gerrit-Project: tools
Gerrit-Branch: master
Gerrit-Change-Id: I5ac452b05a1ec3c2f254b872bec2454998ff3081
Gerrit-Change-Number: 378754
Gerrit-PatchSet: 2
Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
Gerrit-Reviewer: Michael Matloob <mat...@golang.org>
Gerrit-Reviewer: Robert Findley <rfin...@google.com>
Gerrit-CC: Hyang-Ah Hana Kim <hya...@gmail.com>
Gerrit-Attention: Michael Matloob <mat...@golang.org>
Gerrit-Comment-Date: Tue, 18 Jan 2022 21:10:27 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment

Gopher Robot (Gerrit)

unread,
Feb 19, 2022, 2:06:43 AM2/19/22
to Gerrit Bot, goph...@pubsubhelper.golang.org, Robert Findley, Michael Matloob, Hyang-Ah Hana Kim, golang-co...@googlegroups.com

Gopher Robot abandoned this change.

View Change

Abandoned GitHub PR golang/tools#359 has been closed.

To view, visit change 378754. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: tools
Gerrit-Branch: master
Gerrit-Change-Id: I5ac452b05a1ec3c2f254b872bec2454998ff3081
Gerrit-Change-Number: 378754
Gerrit-PatchSet: 2
Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
Gerrit-Reviewer: Michael Matloob <mat...@golang.org>
Gerrit-Reviewer: Robert Findley <rfin...@google.com>
Gerrit-CC: Hyang-Ah Hana Kim <hya...@gmail.com>
Gerrit-MessageType: abandon
Reply all
Reply to author
Forward
0 new messages