Skip to content

Commit 9aabd4b

Browse files
committed
fix: lsp jump to definition
1 parent e0519e4 commit 9aabd4b

6 files changed

+30
-23
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## v0.0.14-next
4+
5+
- lsp: fix jump to definition
6+
37
## v0.0.13
48

59
- lsp: semantic syntax highlighting #28

info/globals.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
package info
22

3-
var Version = "0.0.13"
3+
var Version = "0.0.14-next"

langsrv/handler-definition.go

+10
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,16 @@ func textDocumentDefinition(context *glsp.Context, params *protocol.DefinitionPa
3232
Character: uint32(decl.Meta().Source.End.Line),
3333
},
3434
},
35+
TargetSelectionRange: protocol.Range{
36+
Start: protocol.Position{
37+
Line: uint32(decl.Meta().Source.Start.Line),
38+
Character: uint32(decl.Meta().Source.Start.Column),
39+
},
40+
End: protocol.Position{
41+
Line: uint32(decl.Meta().Source.End.Line),
42+
Character: uint32(decl.Meta().Source.End.Line),
43+
},
44+
},
3545
},
3646
}, nil
3747
}

langsrv/handler-text-document-did-change.go

+5-9
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package langsrv
33
import (
44
"github.com/tliron/glsp"
55
protocol "github.com/tliron/glsp/protocol_3_16"
6+
"github.com/vknabel/lithia/parser"
67
)
78

89
func textDocumentDidChange(context *glsp.Context, params *protocol.DidChangeTextDocumentParams) error {
@@ -17,18 +18,13 @@ func textDocumentDidChange(context *glsp.Context, params *protocol.DidChangeText
1718
}
1819
}
1920
entry.item.Text = text
21+
syntaxErrs := make([]parser.SyntaxError, 0)
2022
fileParser, errs := entry.parser.Parse("default-module", string(params.TextDocument.URI), text)
21-
if len(errs) > 0 {
22-
publishSyntaxErrorDiagnostics(context, params.TextDocument.URI, uint32(params.TextDocument.Version), errs)
23-
return nil
24-
}
23+
syntaxErrs = append(syntaxErrs, errs...)
2524
sourceFile, errs := fileParser.ParseSourceFile()
26-
if len(errs) > 0 {
27-
publishSyntaxErrorDiagnostics(context, params.TextDocument.URI, uint32(params.TextDocument.Version), errs)
28-
return nil
29-
}
25+
syntaxErrs = append(syntaxErrs, errs...)
3026
langserver.documentCache.documents[params.TextDocument.URI].fileParser = fileParser
3127
langserver.documentCache.documents[params.TextDocument.URI].sourceFile = sourceFile
32-
publishSyntaxErrorDiagnostics(context, params.TextDocument.URI, uint32(params.TextDocument.Version), nil)
28+
publishSyntaxErrorDiagnostics(context, params.TextDocument.URI, uint32(params.TextDocument.Version), syntaxErrs)
3329
return nil
3430
}

langsrv/handler-text-document-did-open.go

+5-9
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,18 @@ import (
88

99
func textDocumentDidOpen(context *glsp.Context, params *protocol.DidOpenTextDocumentParams) error {
1010
lithiaParser := parser.NewParser()
11+
12+
syntaxErrs := make([]parser.SyntaxError, 0)
1113
fileParser, errs := lithiaParser.Parse("default-module", string(params.TextDocument.URI), params.TextDocument.Text)
12-
if len(errs) > 0 {
13-
publishSyntaxErrorDiagnostics(context, params.TextDocument.URI, uint32(params.TextDocument.Version), errs)
14-
return nil
15-
}
14+
syntaxErrs = append(syntaxErrs, errs...)
1615
sourceFile, errs := fileParser.ParseSourceFile()
17-
if len(errs) > 0 {
18-
publishSyntaxErrorDiagnostics(context, params.TextDocument.URI, uint32(params.TextDocument.Version), errs)
19-
return nil
20-
}
16+
syntaxErrs = append(syntaxErrs, errs...)
2117
langserver.documentCache.documents[params.TextDocument.URI] = &textDocumentEntry{
2218
item: params.TextDocument,
2319
parser: lithiaParser,
2420
fileParser: fileParser,
2521
sourceFile: sourceFile,
2622
}
27-
publishSyntaxErrorDiagnostics(context, params.TextDocument.URI, uint32(params.TextDocument.Version), nil)
23+
publishSyntaxErrorDiagnostics(context, params.TextDocument.URI, uint32(params.TextDocument.Version), syntaxErrs)
2824
return nil
2925
}

langsrv/handler-text-document-semantic-tokens-full.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func textDocumentSemanticTokensFull(context *glsp.Context, params *protocol.Sema
7070
(import_members (identifier) @variable.import)
7171
(module_declaration name: (identifier) @variable.import)
7272
(complex_invocation_expression function: (identifier) @function)
73-
(simple_invocation_expression function: (identifier) @function)
73+
(simple_invocation_expression function: (identifier) @function.simple)
7474
(string_literal) @string
7575
(escape_sequence) @string.special
7676
(type_expression type: (identifier) @type.enum)
@@ -80,7 +80,7 @@ func textDocumentSemanticTokensFull(context *glsp.Context, params *protocol.Sema
8080
(member_identifier) @property
8181
8282
(ERROR) @error
83-
(identifier) @variable
83+
; (identifier) @variable ; would override every other token
8484
`), syntax.GetLanguage())
8585
if err != nil {
8686
return nil, err
@@ -108,7 +108,6 @@ func textDocumentSemanticTokensFull(context *glsp.Context, params *protocol.Sema
108108
})
109109
}
110110
}
111-
112111
return &protocol.SemanticTokens{
113112
Data: serializeHighlightedTokens(tokens),
114113
}, nil
@@ -125,7 +124,7 @@ func tokenTypeForCaptureName(captureName string) *tokenType {
125124
case "punctuation.bracket":
126125
return &token_operator
127126
case "variable":
128-
return nil
127+
return &token_variable
129128
case "variable.parameter":
130129
return &token_parameter
131130
case "variable.builtin":
@@ -140,6 +139,8 @@ func tokenTypeForCaptureName(captureName string) *tokenType {
140139
return &token_function
141140
case "function.builtin":
142141
return &token_function
142+
case "function.simple":
143+
return &token_decorator
143144
case "method":
144145
return &token_method
145146
case "type":

0 commit comments

Comments
 (0)