gopls/internal/protocol: patch RenameParams to extend PositionParams
The LSP states that RenameParams extends TextDocumentPositionParams.
However, the source json definition flattens the text document and
position fields directly to Renameparams, rather than preserving
the inheritance.
This change manually patches the parsed model ensuring the generated
code correctly embeds PositionParams matching the LSP.
diff --git a/gopls/internal/protocol/generate/main.go b/gopls/internal/protocol/generate/main.go
index 828fddd..9b21b80 100644
--- a/gopls/internal/protocol/generate/main.go
+++ b/gopls/internal/protocol/generate/main.go
@@ -20,6 +20,7 @@
"os"
"os/exec"
"path/filepath"
+ "slices"
"strings"
)
@@ -72,6 +73,28 @@
model := parse(filepath.Join(*repodir, "protocol/metaModel.json"))
+ // Although the LSP specification defines RenameParams as extending
+ // TextDocumentPositionParams, the metaModel.json definition flattens
+ // these properties (likely due to specific comments in the TS definition).
+ for _, s := range model.Structures {
+ if s.Name == "RenameParams" {
+ s.Properties = slices.DeleteFunc(s.Properties,
+ func(t NameType) bool {
+ return t.Name == "position" || t.Name == "textDocument"
+ })
+ if !slices.ContainsFunc(s.Extends, func(t *Type) bool {
+ return t.Kind == "reference" && t.Name == "TextDocumentPositionParams"
+ }) {
+ s.Extends = append(s.Extends,
+ &Type{
+ Kind: "reference",
+ Name: "TextDocumentPositionParams",
+ },
+ )
+ }
+ }
+ }
+
findTypeNames(model)
generateOutput(model)
diff --git a/gopls/internal/protocol/tsprotocol.go b/gopls/internal/protocol/tsprotocol.go
index a409c01..10aa2a4 100644
--- a/gopls/internal/protocol/tsprotocol.go
+++ b/gopls/internal/protocol/tsprotocol.go
@@ -4523,14 +4523,11 @@
//
// See https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification#renameParams
type RenameParams struct {
- // The document to rename.
- TextDocument TextDocumentIdentifier `json:"textDocument"`
- // The position at which this request was sent.
- Position Position `json:"position"`
// The new name of the symbol. If the given name is not valid the
// request must return a {@link ResponseError} with an
// appropriate message set.
NewName string `json:"newName"`
+ TextDocumentPositionParams
WorkDoneProgressParams
}
diff --git a/gopls/internal/protocol/tsserver.go b/gopls/internal/protocol/tsserver.go
index 83841fd..b0c6547 100644
--- a/gopls/internal/protocol/tsserver.go
+++ b/gopls/internal/protocol/tsserver.go
@@ -748,6 +748,11 @@
if err := UnmarshalJSON(raw, ¶ms); err != nil {
return nil, true, fmt.Errorf("%w: %s", jsonrpc2.ErrParse, err)
}
+ if params.Range != (Range{}) {
+ if !params.Range.Contains(params.Position) {
+ return nil, true, fmt.Errorf("position %v is outside the provided range %v.", params.Position, params.Range)
+ }
+ }
resp, err := server.Rename(ctx, ¶ms)
if err != nil {
return nil, true, err
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Commit-Queue | +1 |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Commit-Queue | +1 |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
// these properties (likely due to specific comments in the TS definition).Let's file an upstream issue as well.
s.Properties = slices.DeleteFunc(s.Properties,
func(t NameType) bool {join lines
s.Extends = append(s.Extends,
&Type{join lines
if params.Range != (Range{}) {!params.Range.Empty() && !params.Range.Contains(params.Position)
prepareParams.TextDocument = e.TextDocumentIdentifier(path)
prepareParams.Position = loc.Range.StartDoes PrepareRename need the same treatment?
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Auto-Submit | +1 |
| Commit-Queue | +1 |
// these properties (likely due to specific comments in the TS definition).Let's file an upstream issue as well.
Looks like there is already one that now fixed.
TODO(hxjiang) for deleting this fix after 3.18.
https://github.com/microsoft/vscode-languageserver-node/issues/1698
s.Properties = slices.DeleteFunc(s.Properties,
func(t NameType) bool {Hongxiang Jiangjoin lines
Done
s.Extends = append(s.Extends,
&Type{Hongxiang Jiangjoin lines
Done
if params.Range != (Range{}) {Hongxiang Jiang!params.Range.Empty() && !params.Range.Contains(params.Position)
Done
prepareParams.TextDocument = e.TextDocumentIdentifier(path)
prepareParams.Position = loc.Range.StartDoes PrepareRename need the same treatment?
No, for some reason, the prepare rename extends textdocumentpositionparam. :D
I still change the code so the way we create the parameter looks identical.
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
gopls/internal/protocol: patch RenameParams to extend PositionParams
The LSP states that RenameParams extends TextDocumentPositionParams.
However, the source json definition flattens the text document and
position fields directly to Renameparams, rather than preserving
the inheritance.
This change manually patches the parsed model ensuring the generated
code correctly embeds PositionParams matching the LSP.
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |