@@ -6,27 +6,17 @@ import (
66 lsp "github.com/hashicorp/terraform-ls/internal/protocol"
77)
88
9- type CompletionList struct {
10- IsIncomplete bool `json:"isIncomplete"`
11- Items []CompletionItem `json:"items"`
12- }
13-
14- type CompletionItem struct {
15- lsp.CompletionItem
16- Command * lsp.Command `json:"command,omitempty"`
17- }
18-
19- func ToCompletionList (candidates lang.Candidates , caps lsp.TextDocumentClientCapabilities ) CompletionList {
20- list := CompletionList {
21- Items : make ([]CompletionItem , len (candidates .List )),
9+ func ToCompletionList (candidates lang.Candidates , caps lsp.TextDocumentClientCapabilities ) lsp.CompletionList {
10+ list := lsp.CompletionList {
11+ Items : make ([]lsp.CompletionItem , len (candidates .List )),
2212 IsIncomplete : ! candidates .IsComplete ,
2313 }
2414
2515 snippetSupport := caps .Completion .CompletionItem .SnippetSupport
2616
2717 markdown := false
2818 docsFormat := caps .Completion .CompletionItem .DocumentationFormat
29- if len (docsFormat ) > 0 && docsFormat [0 ] == "markdown" {
19+ if len (docsFormat ) > 0 && docsFormat [0 ] == lsp . Markdown {
3020 markdown = true
3121 }
3222
@@ -37,23 +27,23 @@ func ToCompletionList(candidates lang.Candidates, caps lsp.TextDocumentClientCap
3727 return list
3828}
3929
40- func toCompletionItem (candidate lang.Candidate , snippet , markdown bool ) CompletionItem {
30+ func toCompletionItem (candidate lang.Candidate , snippet , markdown bool ) lsp. CompletionItem {
4131 doc := candidate .Description .Value
4232
43- // TODO: revisit once go-lsp supports markdown in CompletionItem
33+ // TODO: Revisit when MarkupContent is allowed as Documentation
34+ // https://github.com/golang/tools/blob/4783bc9b/internal/lsp/protocol/tsprotocol.go#L753
4435 doc = mdplain .Clean (doc )
4536
4637 var kind lsp.CompletionItemKind
4738 switch candidate .Kind {
4839 case lang .AttributeCandidateKind :
49- kind = lsp .CIKProperty
40+ kind = lsp .PropertyCompletion
5041 case lang .BlockCandidateKind :
51- kind = lsp .CIKClass
42+ kind = lsp .ClassCompletion
5243 case lang .LabelCandidateKind :
53- kind = lsp .CIKField
44+ kind = lsp .FieldCompletion
5445 }
5546
56- te , format := textEdit (candidate .TextEdit , snippet )
5747 var cmd * lsp.Command
5848 if candidate .TriggerSuggest {
5949 cmd = & lsp.Command {
@@ -62,29 +52,14 @@ func toCompletionItem(candidate lang.Candidate, snippet, markdown bool) Completi
6252 }
6353 }
6454
65- return CompletionItem {
66- CompletionItem : lsp.CompletionItem {
67- Label : candidate .Label ,
68- Kind : kind ,
69- InsertTextFormat : format ,
70- Detail : candidate .Detail ,
71- Documentation : doc ,
72- TextEdit : te ,
73- },
74- Command : cmd ,
55+ return lsp.CompletionItem {
56+ Label : candidate .Label ,
57+ Kind : kind ,
58+ InsertTextFormat : insertTextFormat (snippet ),
59+ Detail : candidate .Detail ,
60+ Documentation : doc ,
61+ TextEdit : textEdit (candidate .TextEdit , snippet ),
62+ Command : cmd ,
63+ AdditionalTextEdits : textEdits (candidate .AdditionalTextEdits , snippet ),
7564 }
7665}
77-
78- func textEdit (te lang.TextEdit , snippetSupport bool ) (* lsp.TextEdit , lsp.InsertTextFormat ) {
79- if snippetSupport {
80- return & lsp.TextEdit {
81- NewText : te .Snippet ,
82- Range : HCLRangeToLSP (te .Range ),
83- }, lsp .ITFSnippet
84- }
85-
86- return & lsp.TextEdit {
87- NewText : te .NewText ,
88- Range : HCLRangeToLSP (te .Range ),
89- }, lsp .ITFPlainText
90- }
0 commit comments