Skip to content

Commit

Permalink
decoder: Implement completion for LiteralType
Browse files Browse the repository at this point in the history
  • Loading branch information
radeksimko committed Jan 27, 2023
1 parent 9ff60d5 commit 0358cd7
Show file tree
Hide file tree
Showing 8 changed files with 1,750 additions and 17 deletions.
7 changes: 6 additions & 1 deletion decoder/attribute_candidates.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,14 @@ import (
func attributeSchemaToCandidate(name string, attr *schema.AttributeSchema, rng hcl.Range) lang.Candidate {
var snippet string
var triggerSuggest bool
kind := lang.AttributeCandidateKind

if attr.Constraint != nil {
cData := attr.Constraint.EmptyCompletionData(1)
snippet = fmt.Sprintf("%s = %s", name, cData.Snippet)
if cData.Kind != lang.NilCandidateKind {
kind = cData.Kind
}
triggerSuggest = cData.TriggerSuggest
} else {
snippet = snippetForAttribute(name, attr)
Expand All @@ -28,7 +33,7 @@ func attributeSchemaToCandidate(name string, attr *schema.AttributeSchema, rng h
Detail: detailForAttribute(attr),
Description: attr.Description,
IsDeprecated: attr.IsDeprecated,
Kind: lang.AttributeCandidateKind,
Kind: kind,
TextEdit: lang.TextEdit{
NewText: name,
Snippet: snippet,
Expand Down
18 changes: 9 additions & 9 deletions decoder/attribute_candidates_legacy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/zclconf/go-cty/cty"
)

func TestLegacyDecoder_CompletionAtPos_EmptyCompletionData(t *testing.T) {
func TestDecoder_CompletionAtPos_EmptyCompletionData(t *testing.T) {
testCases := []struct {
testName string
attrName string
Expand All @@ -39,7 +39,7 @@ func TestLegacyDecoder_CompletionAtPos_EmptyCompletionData(t *testing.T) {
NewText: "primitive",
Snippet: `primitive = "${1:value}"`,
},
Kind: lang.AttributeCandidateKind,
Kind: lang.StringCandidateKind,
},
}),
},
Expand All @@ -64,7 +64,7 @@ func TestLegacyDecoder_CompletionAtPos_EmptyCompletionData(t *testing.T) {
"${1:key}" = "${2:value}"
}`,
},
Kind: lang.AttributeCandidateKind,
Kind: lang.MapCandidateKind,
},
}),
},
Expand All @@ -89,7 +89,7 @@ func TestLegacyDecoder_CompletionAtPos_EmptyCompletionData(t *testing.T) {
"${1:key}" = ${2:1}
}`,
},
Kind: lang.AttributeCandidateKind,
Kind: lang.MapCandidateKind,
},
}),
},
Expand All @@ -112,7 +112,7 @@ func TestLegacyDecoder_CompletionAtPos_EmptyCompletionData(t *testing.T) {
NewText: "mylist",
Snippet: `mylist = [ ${1:1} ]`,
},
Kind: lang.AttributeCandidateKind,
Kind: lang.ListCandidateKind,
},
}),
},
Expand Down Expand Up @@ -141,7 +141,7 @@ func TestLegacyDecoder_CompletionAtPos_EmptyCompletionData(t *testing.T) {
second = ${2:1}
} ]`,
},
Kind: lang.AttributeCandidateKind,
Kind: lang.ListCandidateKind,
},
}),
},
Expand All @@ -164,7 +164,7 @@ func TestLegacyDecoder_CompletionAtPos_EmptyCompletionData(t *testing.T) {
NewText: "myset",
Snippet: `myset = [ ${1:1} ]`,
},
Kind: lang.AttributeCandidateKind,
Kind: lang.SetCandidateKind,
},
}),
},
Expand Down Expand Up @@ -195,7 +195,7 @@ func TestLegacyDecoder_CompletionAtPos_EmptyCompletionData(t *testing.T) {
keystr = "${3:value}"
}`,
},
Kind: lang.AttributeCandidateKind,
Kind: lang.ObjectCandidateKind,
},
}),
},
Expand Down Expand Up @@ -253,7 +253,7 @@ func TestLegacyDecoder_CompletionAtPos_EmptyCompletionData(t *testing.T) {
keystr = "${3:value}"
}`,
},
Kind: lang.AttributeCandidateKind,
Kind: lang.ObjectCandidateKind,
},
}),
},
Expand Down
5 changes: 1 addition & 4 deletions decoder/expr_literal_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,8 @@ import (
type LiteralType struct {
expr hcl.Expression
cons schema.LiteralType
}

func (lt LiteralType) CompletionAtPos(ctx context.Context, pos hcl.Pos) []lang.Candidate {
// TODO
return nil
pathCtx *PathContext
}

func (lt LiteralType) HoverAtPos(ctx context.Context, pos hcl.Pos) *lang.HoverData {
Expand Down
Loading

0 comments on commit 0358cd7

Please sign in to comment.