diff --git a/internal/terraform/lang/parser.go b/internal/terraform/lang/parser.go index 621a3f74..7c8e8f3a 100644 --- a/internal/terraform/lang/parser.go +++ b/internal/terraform/lang/parser.go @@ -222,9 +222,10 @@ func (p *parser) ParseBlockFromTokens(tBlock ihcl.TokenizedBlock) (ConfigBlock, // It is probably excessive to be parsing the whole block just for type // but there is no avoiding it without refactoring the upstream HCL parser // and it should not hurt the performance too much - // - // We ignore diags as we assume incomplete (invalid) configuration - block, _ := hclsyntax.ParseBlockFromTokens(tBlock.Tokens()) + block, diags := hclsyntax.ParseBlockFromTokens(tBlock.Tokens()) + if block == nil { + return nil, diags + } p.logger.Printf("Parsed block type: %q", block.Type) diff --git a/langserver/handlers/handlers_test.go b/langserver/handlers/handlers_test.go index 59eb1459..da7651f0 100644 --- a/langserver/handlers/handlers_test.go +++ b/langserver/handlers/handlers_test.go @@ -109,12 +109,18 @@ func validTfMockCalls() exec.ExecutorFactory { }, ReturnArguments: []interface{}{ version.Must(version.NewVersion("0.12.0")), - map[string]*version.Version{}, nil, }, }, { - Method: "ProvidersSchema", + Method: "GetExecPath", + Repeatability: 1, + ReturnArguments: []interface{}{ + "", + }, + }, + { + Method: "ProviderSchemas", Repeatability: 1, Arguments: []interface{}{ mock.AnythingOfType(""), diff --git a/langserver/handlers/symbols_test.go b/langserver/handlers/symbols_test.go new file mode 100644 index 00000000..c3e80f6e --- /dev/null +++ b/langserver/handlers/symbols_test.go @@ -0,0 +1,54 @@ +package handlers + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform-ls/internal/terraform/rootmodule" + "github.com/hashicorp/terraform-ls/langserver" +) + +func TestLangServer_symbols_basic(t *testing.T) { + tmpDir := TempDir(t) + InitPluginCache(t, tmpDir.Dir()) + + ls := langserver.NewLangServerMock(t, NewMockSession(&MockSessionInput{ + RootModules: map[string]*rootmodule.RootModuleMock{ + tmpDir.Dir(): { + TfExecFactory: validTfMockCalls(), + }, + }, + })) + stop := ls.Start(t) + defer stop() + + ls.Call(t, &langserver.CallRequest{ + Method: "initialize", + ReqParams: fmt.Sprintf(`{ + "capabilities": {}, + "rootUri": %q, + "processId": 12345 + }`, tmpDir.URI())}) + ls.Notify(t, &langserver.CallRequest{ + Method: "initialized", + ReqParams: "{}", + }) + ls.Call(t, &langserver.CallRequest{ + Method: "textDocument/didOpen", + ReqParams: fmt.Sprintf(`{ + "textDocument": { + "version": 0, + "languageId": "terraform", + "text": "provider \"github\"\n\n}\n", + "uri": "%s/main.tf" + } + }`, tmpDir.URI())}) + + ls.Call(t, &langserver.CallRequest{ + Method: "textDocument/documentSymbol", + ReqParams: fmt.Sprintf(`{ + "textDocument": { + "uri": "%s/main.tf" + } + }`, tmpDir.URI())}) +}