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

Check for non-object types before calling HasAttribute #76

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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 README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
![Release](https://github.com/juliosueiras/terraform-lsp/workflows/Release/badge.svg)
[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fjuliosueiras%2Fterraform-lsp.svg?type=shield)](https://app.fossa.io/projects/git%2Bgithub.com%2Fjuliosueiras%2Fterraform-lsp?ref=badge_shield)

This is LSP (Language Server Protocol) for Terraform
This is a LSP (Language Server Protocol) for Terraform

**IMPORTANT:** Currently there is two terraform lsp, one is this one and the other one is [terraform-ls](https://github.com/hashicorp/terraform-ls), which contain details about this repo as well.

Expand Down
24 changes: 12 additions & 12 deletions helper/file.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
package helper

import (
"reflect"
"regexp"
"strings"
"unicode/utf8"

"github.com/hashicorp/hcl/v2"
"github.com/hashicorp/hcl/v2/hclsyntax"
"github.com/hashicorp/terraform/configs"
Expand All @@ -9,10 +14,6 @@ import (
"github.com/sourcegraph/go-lsp"
"github.com/spf13/afero"
"github.com/zclconf/go-cty/cty"
"reflect"
"regexp"
"strings"
"unicode/utf8"
)

func CheckAndGetConfig(parser *configs.Parser, originalFile afero.File, line int, character int) (*configs.File, hcl.Diagnostics, int, *hclsyntax.Body, bool) {
Expand All @@ -21,12 +22,12 @@ func CheckAndGetConfig(parser *configs.Parser, originalFile afero.File, line int
pos := FindOffset(string(fileText), line, character)

tempFile, _ := afero.TempFile(memfs.MemFs, "", "check_tf_lsp")
found := false
found := false

if int64(pos) != -1 {
found = true
originalFile.ReadAt(result, int64(pos))
}
if int64(pos) != -1 {
found = true
originalFile.ReadAt(result, int64(pos))
}

defer memfs.MemFs.Remove(tempFile.Name())

Expand Down Expand Up @@ -70,7 +71,7 @@ func FindOffset(fileText string, line, column int) int {
column = 1
}

//variable \"test\" {\n \n}\n\n
//variable \"test\" {\n \n}\n\n
currentCol := 1
currentLine := 1

Expand Down Expand Up @@ -124,7 +125,6 @@ func parseVariables(vars hcl.Traversal, configVarsType *cty.Type, completionItem
return completionItems
}


if !configVarsType.IsObjectType() {
if et := configVarsType.MapElementType(); et != nil {
return parseVariables(vars[1:], et, completionItems)
Expand All @@ -141,7 +141,7 @@ func parseVariables(vars hcl.Traversal, configVarsType *cty.Type, completionItem

if reflect.TypeOf(vars[0]) == hclstructs.TraverseAttr() {
varAttr := vars[0].(hcl.TraverseAttr)
if configVarsType.HasAttribute(varAttr.Name) {
if configVarsType.IsObjectType() && configVarsType.HasAttribute(varAttr.Name) {
attr := configVarsType.AttributeType(varAttr.Name)
return parseVariables(vars[1:], &attr, completionItems)
}
Expand Down
Loading