Skip to content

Commit 5dfedb9

Browse files
authored
Ensure correct usage of language IDs (#147)
Signed-off-by: James Humphries <james@james-humphries.co.uk>
1 parent ffc3733 commit 5dfedb9

5 files changed

Lines changed: 11 additions & 9 deletions

File tree

internal/langserver/handlers/code_lens.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func (svc *service) TextDocumentCodeLens(ctx context.Context, params lsp.CodeLen
3030

3131
path := lang.Path{
3232
Path: doc.Dir.Path(),
33-
LanguageID: doc.LanguageID,
33+
LanguageID: string(ilsp.ParseLanguageID(doc.LanguageID)),
3434
}
3535

3636
lenses, err := svc.decoder.CodeLensesForFile(ctx, path, doc.Filename)

internal/langserver/handlers/did_change.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func (svc *service) TextDocumentDidChange(ctx context.Context, params lsp.DidCha
5959
svc.eventBus.DidChange(eventbus.DidChangeEvent{
6060
Context: ctx, // We pass the context for data here
6161
Dir: dh.Dir,
62-
LanguageID: doc.LanguageID,
62+
LanguageID: string(ilsp.ParseLanguageID(doc.LanguageID)),
6363
})
6464

6565
return nil

internal/langserver/handlers/go_to_ref_target.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
lsp "github.com/opentofu/tofu-ls/internal/protocol"
1515
)
1616

17-
func (svc *service) GoToDefinition(ctx context.Context, params lsp.TextDocumentPositionParams) (interface{}, error) {
17+
func (svc *service) GoToDefinition(ctx context.Context, params lsp.TextDocumentPositionParams) (any, error) {
1818
cc, err := ilsp.ClientCapabilities(ctx)
1919
if err != nil {
2020
return nil, err
@@ -28,7 +28,7 @@ func (svc *service) GoToDefinition(ctx context.Context, params lsp.TextDocumentP
2828
return ilsp.RefTargetsToDefinitionLocationLinks(targets, cc.TextDocument.Definition), nil
2929
}
3030

31-
func (svc *service) GoToDeclaration(ctx context.Context, params lsp.TextDocumentPositionParams) (interface{}, error) {
31+
func (svc *service) GoToDeclaration(ctx context.Context, params lsp.TextDocumentPositionParams) (any, error) {
3232
cc, err := ilsp.ClientCapabilities(ctx)
3333
if err != nil {
3434
return nil, err
@@ -62,7 +62,7 @@ func (svc *service) goToReferenceTarget(ctx context.Context, params lsp.TextDocu
6262

6363
path := lang.Path{
6464
Path: doc.Dir.Path(),
65-
LanguageID: doc.LanguageID,
65+
LanguageID: string(ilsp.ParseLanguageID(doc.LanguageID)),
6666
}
6767

6868
return svc.decoder.ReferenceTargetsForOriginAtPos(path, doc.Filename, pos)

internal/langserver/handlers/references.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func (svc *service) References(ctx context.Context, params lsp.ReferenceParams)
3535

3636
path := lang.Path{
3737
Path: doc.Dir.Path(),
38-
LanguageID: doc.LanguageID,
38+
LanguageID: ilsp.ParseLanguageID(doc.LanguageID).String(),
3939
}
4040
// TODO? maybe kick off indexing of the whole workspace here
4141
origins := svc.decoder.ReferenceOriginsTargetingPos(path, doc.Filename, pos)

internal/langserver/handlers/service.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -620,8 +620,10 @@ func (svc *service) shutdown() {
620620
}
621621
}
622622

623-
const requestCancelled jrpc2.Code = -32800
624-
const tracerName = "github.com/opentofu/tofu-ls/internal/langserver/handlers"
623+
const (
624+
requestCancelled jrpc2.Code = -32800
625+
tracerName = "github.com/opentofu/tofu-ls/internal/langserver/handlers"
626+
)
625627

626628
// handle calls a jrpc2.Func compatible function
627629
func handle(ctx context.Context, req *jrpc2.Request, fn interface{}) (interface{}, error) {
@@ -690,6 +692,6 @@ func handle(ctx context.Context, req *jrpc2.Request, fn interface{}) (interface{
690692
func (svc *service) decoderForDocument(_ context.Context, doc *document.Document) (*decoder.PathDecoder, error) {
691693
return svc.decoder.Path(lang.Path{
692694
Path: doc.Dir.Path(),
693-
LanguageID: doc.LanguageID,
695+
LanguageID: string(ilsp.ParseLanguageID(doc.LanguageID)),
694696
})
695697
}

0 commit comments

Comments
 (0)