Fix LSP go-to-definition for ref command references#331
Fix LSP go-to-definition for ref command references#331
Conversation
There was a problem hiding this comment.
Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.
Reviewer's GuideExtends the LSP YAML parser so go-to-definition also works from Sequence diagram for LSP go-to-definition from ref mappingssequenceDiagram
actor Developer
participant IDE
participant LSPServer
participant Parser
participant DefinitionHandler
Developer->>IDE: Trigger go-to-definition on ref value
IDE->>LSPServer: textDocument/definition(params)
LSPServer->>Parser: getPositionType(document, position)
Parser->>Parser: inMixinsPosition / inDependsPosition / inCommandAliasPosition
Parser->>Parser: inRefPosition(document, position)
Parser-->>LSPServer: PositionTypeRef
LSPServer->>DefinitionHandler: findCommandDefinition(doc, params)
DefinitionHandler->>Parser: extractCommandReference(document, position)
Parser->>Parser: extractAliasCommandReference
Parser->>Parser: extractRefCommandReference(document, position)
Parser-->>DefinitionHandler: commandName
DefinitionHandler->>Parser: findCommandNameByAnchor(document, commandName)
Parser-->>DefinitionHandler: commandDefinitionLocation
DefinitionHandler-->>LSPServer: lsp.Location
LSPServer-->>IDE: textDocument/definition result
IDE-->>Developer: Navigate to command definition
Class diagram for updated LSP parser and definition handlingclassDiagram
class parser {
+log
+getPositionType(document *string, position lsp_Position) PositionType
+inMixinsPosition(document *string, position lsp_Position) bool
+inDependsPosition(document *string, position lsp_Position) bool
+inCommandAliasPosition(document *string, position lsp_Position) bool
+inRefPosition(document *string, position lsp_Position) bool
+extractFilenameFromMixins(document *string, position lsp_Position) string
+extractCommandReference(document *string, position lsp_Position) string
+extractAliasCommandReference(document *string, position lsp_Position) string
+extractRefCommandReference(document *string, position lsp_Position) string
+findCommandNameByAnchor(document *string, anchorName string) string
}
class PositionType {
<<enumeration>>
+PositionTypeMixins
+PositionTypeDepends
+PositionTypeCommandAlias
+PositionTypeRef
+PositionTypeNone
+String() string
}
class lspServer {
+log
+textDocumentDefinition(context glsp_Context, params *lsp_DefinitionParams) interface
}
class definitionHandler {
+findMixinsDefinition(doc *document, params *lsp_DefinitionParams) interface
+findCommandDefinition(doc *document, params *lsp_DefinitionParams) interface
}
parser --> PositionType
lspServer --> parser
lspServer --> definitionHandler
definitionHandler --> parser
File-Level Changes
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 1 issue, and left some high level feedback:
- The tree-sitter query for
refis duplicated in bothinRefPositionandextractRefCommandReference; consider extracting this query (or a small helper that returns the matching node) to avoid repetition and keep the ref-handling behavior in one place.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The tree-sitter query for `ref` is duplicated in both `inRefPosition` and `extractRefCommandReference`; consider extracting this query (or a small helper that returns the matching node) to avoid repetition and keep the ref-handling behavior in one place.
## Individual Comments
### Comment 1
<location path="docs/docs/ide_support.md" line_range="36" />
<code_context>
- [x] Goto definition
- Navigate to definitions of mixins files
- - Navigate to definitions of command from `depends`
+ - Navigate to definitions of command from `depends`, `ref`, and YAML merge aliases
- [x] Completion
- Complete commands in depends
</code_context>
<issue_to_address>
**suggestion (typo):** Consider using the plural 'commands' instead of 'command' for grammatical agreement.
Now that you mention multiple sources (`depends`, `ref`, and YAML merge aliases), please use the plural form “commands” to keep the sentence grammatically correct.
```suggestion
- Navigate to definitions of commands from `depends`, `ref`, and YAML merge aliases
```
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| - [x] Goto definition | ||
| - Navigate to definitions of mixins files | ||
| - Navigate to definitions of command from `depends` | ||
| - Navigate to definitions of command from `depends`, `ref`, and YAML merge aliases |
There was a problem hiding this comment.
suggestion (typo): Consider using the plural 'commands' instead of 'command' for grammatical agreement.
Now that you mention multiple sources (depends, ref, and YAML merge aliases), please use the plural form “commands” to keep the sentence grammatically correct.
| - Navigate to definitions of command from `depends`, `ref`, and YAML merge aliases | |
| - Navigate to definitions of commands from `depends`, `ref`, and YAML merge aliases |
Summary
refcursor detection to the YAML LSP parserref: <command>through the existing command definition lookup pathTesting
lets fmtgo test ./internal/lsp/...go test ./...Summary by Sourcery
Extend LSP go-to-definition support to recognize YAML
refcommand references and resolve them to their command definitions.Bug Fixes:
ref: <command>are correctly resolved in the LSP server.Enhancements:
refvalues and treat them as command references for navigation.Documentation:
depends,ref, and YAML merge aliases, and note the fix in the changelog.Tests:
refcommand references.