Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: missing references for some blocks in a separate config file #829

Merged
merged 2 commits into from
Mar 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ require (
github.com/hashicorp/go-uuid v1.0.2
github.com/hashicorp/go-version v1.4.0
github.com/hashicorp/hc-install v0.3.1
github.com/hashicorp/hcl-lang v0.0.0-20220304112739-b2b314ea7c44
github.com/hashicorp/hcl-lang v0.0.0-20220314150337-d770b425fb22
github.com/hashicorp/hcl/v2 v2.11.1
github.com/hashicorp/terraform-exec v0.16.0
github.com/hashicorp/terraform-json v0.13.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -296,8 +296,8 @@ github.com/hashicorp/hc-install v0.3.1/go.mod h1:3LCdWcCDS1gaHC9mhHCGbkYfoY6vdsK
github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
github.com/hashicorp/hcl-lang v0.0.0-20211118124824-da3a292c5d7a/go.mod h1:0W3+VP07azoS+fCX5hWk1KxwHnqf1s9J7oBg2cFXm1c=
github.com/hashicorp/hcl-lang v0.0.0-20220304112739-b2b314ea7c44 h1:R+ZKsdqgXle9KO2pLE6AwXg6IStjfM8wgQY4u0qPtx0=
github.com/hashicorp/hcl-lang v0.0.0-20220304112739-b2b314ea7c44/go.mod h1:vyszbX6YNHCKIaVUhbh3LIZljxwYOtgWCIkhT5zKfjc=
github.com/hashicorp/hcl-lang v0.0.0-20220314150337-d770b425fb22 h1:u++Zu5hfJPSNuHh7cV1QfTItINnEGRMdOvT9KjaDQUQ=
github.com/hashicorp/hcl-lang v0.0.0-20220314150337-d770b425fb22/go.mod h1:vyszbX6YNHCKIaVUhbh3LIZljxwYOtgWCIkhT5zKfjc=
github.com/hashicorp/hcl/v2 v2.10.1/go.mod h1:FwWsfWEjyV/CMj8s/gqAuiviY72rJ1/oayI9WftqcKg=
github.com/hashicorp/hcl/v2 v2.11.1 h1:yTyWcXcm9XB0TEkyU/JCRU6rYy4K+mgLtzn2wlrJbcc=
github.com/hashicorp/hcl/v2 v2.11.1/go.mod h1:FwWsfWEjyV/CMj8s/gqAuiviY72rJ1/oayI9WftqcKg=
Expand Down
166 changes: 166 additions & 0 deletions internal/langserver/handlers/complete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1231,6 +1231,172 @@ output "test" {
}`)
}

func TestVarReferenceCompletion_withValidData(t *testing.T) {
tmpDir := TempDir(t)
InitPluginCache(t, tmpDir.Path())

variableDecls := `variable "aaa" {}
variable "bbb" {}
variable "ccc" {}
`
f, err := os.Create(filepath.Join(tmpDir.Path(), "variables.tf"))
if err != nil {
t.Fatal(err)
}
_, err = f.WriteString(variableDecls)
if err != nil {
t.Fatal(err)
}
f.Close()

var testSchema tfjson.ProviderSchemas
err = json.Unmarshal([]byte(testModuleSchemaOutput), &testSchema)
if err != nil {
t.Fatal(err)
}

ls := langserver.NewLangServerMock(t, NewMockSession(&MockSessionInput{
TerraformCalls: &exec.TerraformMockCalls{
PerWorkDir: map[string][]*mock.Call{
tmpDir.Path(): {
{
Method: "Version",
Repeatability: 1,
Arguments: []interface{}{
mock.AnythingOfType(""),
},
ReturnArguments: []interface{}{
version.Must(version.NewVersion("0.12.0")),
nil,
nil,
},
},
{
Method: "GetExecPath",
Repeatability: 1,
ReturnArguments: []interface{}{
"",
},
},
{
Method: "ProviderSchemas",
Repeatability: 1,
Arguments: []interface{}{
mock.AnythingOfType(""),
},
ReturnArguments: []interface{}{
&testSchema,
nil,
},
},
},
},
}}))
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": "output \"test\" {\n value = var.\n}\n",
"uri": "%s/outputs.tf"
}
}`, tmpDir.URI)})
ls.CallAndExpectResponse(t, &langserver.CallRequest{
Method: "textDocument/completion",
ReqParams: fmt.Sprintf(`{
"textDocument": {
"uri": "%s/outputs.tf"
},
"position": {
"character": 14,
"line": 1
}
}`, tmpDir.URI)}, `{
"jsonrpc": "2.0",
"id": 3,
"result": {
"isIncomplete": false,
"items": [
{
"label": "var.aaa",
"labelDetails": {},
"kind": 6,
"detail": "dynamic",
"insertTextFormat": 1,
"textEdit": {
"range": {
"start": {
"line": 1,
"character": 10
},
"end": {
"line": 1,
"character": 14
}
},
"newText": "var.aaa"
}
},
{
"label": "var.bbb",
"labelDetails": {},
"kind": 6,
"detail": "dynamic",
"insertTextFormat": 1,
"textEdit": {
"range": {
"start": {
"line": 1,
"character": 10
},
"end": {
"line": 1,
"character": 14
}
},
"newText": "var.bbb"
}
},
{
"label": "var.ccc",
"labelDetails": {},
"kind": 6,
"detail": "dynamic",
"insertTextFormat": 1,
"textEdit": {
"range": {
"start": {
"line": 1,
"character": 10
},
"end": {
"line": 1,
"character": 14
}
},
"newText": "var.ccc"
}
}
]
}
}`)
}

func tfExecutor(t *testing.T, workdir, tfVersion string) exec.TerraformExecutor {
ctx := context.Background()
installDir := filepath.Join(t.TempDir(), "hcinstall")
Expand Down