-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: prevent crash when listing symbols (#273)
* add test * fix: prevent crash when listing symbols
- Loading branch information
1 parent
45b12ce
commit 4b1d959
Showing
3 changed files
with
66 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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())}) | ||
} |