Skip to content

Commit 38ba9f5

Browse files
h9jiangadonovan
authored andcommitted
gopls/internal/protocol: replace lsp link with experimental comment
Change-Id: Id3faa0b61cd3218f32f43be798f4490e0f82b6e3 Reviewed-on: https://go-review.googlesource.com/c/tools/+/736280 Auto-Submit: Alan Donovan <adonovan@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Madeline Kalil <mkalil@google.com> Reviewed-by: Alan Donovan <adonovan@google.com> Commit-Queue: Alan Donovan <adonovan@google.com>
1 parent 613c127 commit 38ba9f5

File tree

3 files changed

+38
-9
lines changed

3 files changed

+38
-9
lines changed

gopls/internal/protocol/generate/output.go

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,15 @@ var (
3131

3232
func generateOutput(model *Model) {
3333
for _, r := range model.Requests {
34-
genDecl(model, r.Method, r.Params, r.Result, r.Direction)
34+
genDecl(model, r.Method, r.Params, r.Result, r.Direction, r.Line == 0)
3535
genCase(model, r.Method, r.Params, r.Result, r.Direction)
3636
genFunc(model, r.Method, r.Params, r.Result, r.Direction, false)
3737
}
3838
for _, n := range model.Notifications {
3939
if n.Method == "$/cancelRequest" {
4040
continue // handled internally by jsonrpc2
4141
}
42-
genDecl(model, n.Method, n.Params, nil, n.Direction)
42+
genDecl(model, n.Method, n.Params, nil, n.Direction, n.Line == 0)
4343
genCase(model, n.Method, n.Params, nil, n.Direction)
4444
genFunc(model, n.Method, n.Params, nil, n.Direction, true)
4545
}
@@ -50,7 +50,7 @@ func generateOutput(model *Model) {
5050
genMarshal()
5151
}
5252

53-
func genDecl(model *Model, method string, param, result *Type, dir string) {
53+
func genDecl(model *Model, method string, param, result *Type, dir string, experiment bool) {
5454
fname := methodName(method)
5555
p := ""
5656
if notNil(param) {
@@ -72,11 +72,28 @@ func genDecl(model *Model, method string, param, result *Type, dir string) {
7272
p = ", *ParamConfiguration"
7373
ret = "([]LSPAny, error)"
7474
}
75-
fragment := strings.ReplaceAll(strings.TrimPrefix(method, "$/"), "/", "_")
76-
msg := fmt.Sprintf("\t%s\t%s(context.Context%s) %s\n", lspLink(model, fragment), fname, p, ret)
77-
if doc, ok := prependMethodDocComments[fname]; ok {
78-
msg = doc + "\n\t//\n" + msg
75+
76+
var msg string
77+
{
78+
var sb strings.Builder
79+
80+
if doc, ok := prependMethodDocComments[fname]; ok {
81+
sb.WriteString(doc)
82+
sb.WriteString("\n\t//\n")
83+
}
84+
85+
if experiment {
86+
sb.WriteString("\t// Note: This is a non-standard protocol extension.\n")
87+
} else {
88+
fragment := strings.ReplaceAll(strings.TrimPrefix(method, "$/"), "/", "_")
89+
fmt.Fprintf(&sb, "\t%s", lspLink(model, fragment))
90+
}
91+
92+
fmt.Fprintf(&sb, "\t%s(context.Context%s) %s\n", fname, p, ret)
93+
94+
msg = sb.String()
7995
}
96+
8097
switch dir {
8198
case "clientToServer":
8299
sdecls[method] = msg

gopls/internal/protocol/generate/tables.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,13 @@ var prependMethodDocComments = map[string]string{
303303
// filled (re-filled) answers in the form until it obtains an
304304
// ExecuteCommandParams with interactive properties empty (e.g. formFields,
305305
// formAnswers). by then the original properties contains all information,
306-
// the client can call "workspace/executeCommand" with the same param.`,
306+
// the client can call "workspace/executeCommand" with the same param.
307+
//
308+
// Standard resolution (e.g., "codeAction/resolve") cannot be used here because
309+
// it is often triggered eagerly (e.g., for previews), prohibiting interactive
310+
// forms. "command/resolve" is introduced to handle the interactive flow
311+
// strictly *after* the user has explicitly indicated intention (e.g., by
312+
// clicking), making it safe for Code Actions and other refactorings.`,
307313
}
308314

309315
// appendTypeProp specifies block of code (typically properties with doc comment)

gopls/internal/protocol/tsserver.go

Lines changed: 7 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)