gopls/internal/settings: move CodeActionKind values from protocol
Like CodeLensSource, these enum values are gopls extensions (and
their configuration interface) and not part of LSP.
No change to generated files.
Change-Id: I2413fd23acc92450f1f0712f0f77a1c83674505a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/593816
Reviewed-by: Robert Findley <rfindley@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
diff --git a/gopls/internal/golang/codeaction.go b/gopls/internal/golang/codeaction.go
index fa9cb15..c4990ae 100644
--- a/gopls/internal/golang/codeaction.go
+++ b/gopls/internal/golang/codeaction.go
@@ -48,7 +48,7 @@
if wantQuickFixes ||
want[protocol.SourceOrganizeImports] ||
want[protocol.RefactorExtract] ||
- want[protocol.GoFreeSymbols] {
+ want[settings.GoFreeSymbols] {
pgf, err := snapshot.ParseGo(ctx, fh, parsego.Full)
if err != nil {
@@ -102,7 +102,7 @@
actions = append(actions, extractions...)
}
- if want[protocol.GoFreeSymbols] && rng.End != rng.Start {
+ if want[settings.GoFreeSymbols] && rng.End != rng.Start {
loc := protocol.Location{URI: pgf.URI, Range: rng}
cmd, err := command.NewFreeSymbolsCommand("Browse free symbols", snapshot.View().ID(), loc)
if err != nil {
@@ -111,7 +111,7 @@
// For implementation, see commandHandler.FreeSymbols.
actions = append(actions, protocol.CodeAction{
Title: cmd.Title,
- Kind: protocol.GoFreeSymbols,
+ Kind: settings.GoFreeSymbols,
Command: &cmd,
})
}
@@ -120,9 +120,9 @@
// Code actions requiring type information.
if want[protocol.RefactorRewrite] ||
want[protocol.RefactorInline] ||
- want[protocol.GoAssembly] ||
- want[protocol.GoDoc] ||
- want[protocol.GoTest] {
+ want[settings.GoAssembly] ||
+ want[settings.GoDoc] ||
+ want[settings.GoTest] {
pkg, pgf, err := NarrowestPackageForFile(ctx, snapshot, fh.URI())
if err != nil {
return nil, err
@@ -150,7 +150,7 @@
actions = append(actions, rewrites...)
}
- if want[protocol.GoTest] {
+ if want[settings.GoTest] {
fixes, err := getGoTestCodeActions(pkg, pgf, rng)
if err != nil {
return nil, err
@@ -158,7 +158,7 @@
actions = append(actions, fixes...)
}
- if want[protocol.GoDoc] {
+ if want[settings.GoDoc] {
// "Browse documentation for ..."
_, _, title := DocFragment(pkg, pgf, start, end)
loc := protocol.Location{URI: pgf.URI, Range: rng}
@@ -168,12 +168,12 @@
}
actions = append(actions, protocol.CodeAction{
Title: cmd.Title,
- Kind: protocol.GoDoc,
+ Kind: settings.GoDoc,
Command: &cmd,
})
}
- if want[protocol.GoAssembly] {
+ if want[settings.GoAssembly] {
fixes, err := getGoAssemblyAction(snapshot.View(), pkg, pgf, rng)
if err != nil {
return nil, err
@@ -537,7 +537,7 @@
}
return []protocol.CodeAction{{
Title: cmd.Title,
- Kind: protocol.GoTest,
+ Kind: settings.GoTest,
Command: &cmd,
}}, nil
}
@@ -610,7 +610,7 @@
// For handler, see commandHandler.Assembly.
actions = append(actions, protocol.CodeAction{
Title: cmd.Title,
- Kind: protocol.GoAssembly,
+ Kind: settings.GoAssembly,
Command: &cmd,
})
}
diff --git a/gopls/internal/protocol/enums.go b/gopls/internal/protocol/enums.go
index e3f8b51..74a8a31 100644
--- a/gopls/internal/protocol/enums.go
+++ b/gopls/internal/protocol/enums.go
@@ -8,6 +8,11 @@
"fmt"
)
+// CodeActionUnknownTrigger indicates that the trigger for a
+// CodeAction request is unknown. A missing
+// CodeActionContext.TriggerKind should be treated as equivalent.
+const CodeActionUnknownTrigger CodeActionTriggerKind = 0
+
var (
namesTextDocumentSyncKind [int(Incremental) + 1]string
namesMessageType [int(Log) + 1]string
diff --git a/gopls/internal/server/code_action.go b/gopls/internal/server/code_action.go
index 7252aa9..5c71be8 100644
--- a/gopls/internal/server/code_action.go
+++ b/gopls/internal/server/code_action.go
@@ -16,6 +16,7 @@
"golang.org/x/tools/gopls/internal/mod"
"golang.org/x/tools/gopls/internal/protocol"
"golang.org/x/tools/gopls/internal/protocol/command"
+ "golang.org/x/tools/gopls/internal/settings"
"golang.org/x/tools/gopls/internal/util/slices"
"golang.org/x/tools/internal/event"
)
@@ -59,7 +60,7 @@
// See https://github.com/joaotavora/eglot/discussions/1402
// for a better solution.
explicit := map[protocol.CodeActionKind]bool{
- protocol.GoTest: true,
+ settings.GoTest: true,
}
for _, only := range params.Context.Only {
@@ -139,10 +140,10 @@
if golang.IsGenerated(ctx, snapshot, uri) {
actions = slices.DeleteFunc(actions, func(a protocol.CodeAction) bool {
switch a.Kind {
- case protocol.GoTest,
- protocol.GoDoc,
- protocol.GoFreeSymbols,
- protocol.GoAssembly:
+ case settings.GoTest,
+ settings.GoDoc,
+ settings.GoFreeSymbols,
+ settings.GoAssembly:
return false // read-only query
}
return true // potential write operation
diff --git a/gopls/internal/protocol/codeactionkind.go b/gopls/internal/settings/codeactionkind.go
similarity index 84%
rename from gopls/internal/protocol/codeactionkind.go
rename to gopls/internal/settings/codeactionkind.go
index 045067d..0731115 100644
--- a/gopls/internal/protocol/codeactionkind.go
+++ b/gopls/internal/settings/codeactionkind.go
@@ -2,13 +2,15 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-package protocol
+package settings
+
+import "golang.org/x/tools/gopls/internal/protocol"
// This file defines constants for non-standard CodeActions.
// CodeAction kinds specific to gopls
//
-// See tsprotocol.go for LSP standard kinds, including
+// See ../protocol/tsprotocol.go for LSP standard kinds, including
//
// "quickfix"
// "refactor"
@@ -74,13 +76,8 @@
// instead of == for CodeActionKinds throughout gopls.
// See golang/go#40438 for related discussion.
const (
- GoAssembly CodeActionKind = "source.assembly"
- GoDoc CodeActionKind = "source.doc"
- GoFreeSymbols CodeActionKind = "source.freesymbols"
- GoTest CodeActionKind = "goTest" // TODO(adonovan): rename "source.test"
+ GoAssembly protocol.CodeActionKind = "source.assembly"
+ GoDoc protocol.CodeActionKind = "source.doc"
+ GoFreeSymbols protocol.CodeActionKind = "source.freesymbols"
+ GoTest protocol.CodeActionKind = "goTest" // TODO(adonovan): rename "source.test"
)
-
-// CodeActionUnknownTrigger indicates that the trigger for a
-// CodeAction request is unknown. A missing
-// CodeActionContext.TriggerKind should be treated as equivalent.
-const CodeActionUnknownTrigger CodeActionTriggerKind = 0
diff --git a/gopls/internal/settings/default.go b/gopls/internal/settings/default.go
index fe7749d..29d49ae 100644
--- a/gopls/internal/settings/default.go
+++ b/gopls/internal/settings/default.go
@@ -49,9 +49,9 @@
protocol.RefactorRewrite: true,
protocol.RefactorInline: true,
protocol.RefactorExtract: true,
- protocol.GoAssembly: true,
- protocol.GoDoc: true,
- protocol.GoFreeSymbols: true,
+ GoAssembly: true,
+ GoDoc: true,
+ GoFreeSymbols: true,
},
file.Mod: {
protocol.SourceOrganizeImports: true,
diff --git a/gopls/internal/test/integration/misc/codeactions_test.go b/gopls/internal/test/integration/misc/codeactions_test.go
index 09629b4..376bbe3 100644
--- a/gopls/internal/test/integration/misc/codeactions_test.go
+++ b/gopls/internal/test/integration/misc/codeactions_test.go
@@ -10,6 +10,7 @@
"github.com/google/go-cmp/cmp"
"golang.org/x/tools/gopls/internal/protocol"
+ "golang.org/x/tools/gopls/internal/settings"
. "golang.org/x/tools/gopls/internal/test/integration"
"golang.org/x/tools/gopls/internal/util/slices"
)
@@ -63,15 +64,15 @@
}
check("src/a.go",
- protocol.GoAssembly,
- protocol.GoDoc,
- protocol.GoFreeSymbols,
+ settings.GoAssembly,
+ settings.GoDoc,
+ settings.GoFreeSymbols,
protocol.RefactorExtract,
protocol.RefactorInline)
check("gen/a.go",
- protocol.GoAssembly,
- protocol.GoDoc,
- protocol.GoFreeSymbols)
+ settings.GoAssembly,
+ settings.GoDoc,
+ settings.GoFreeSymbols)
})
}