@@ -6,9 +6,19 @@ import (
66 lsp "github.com/sourcegraph/go-lsp"
77)
88
9- func CompletionList (candidates lang.Candidates , caps lsp.TextDocumentClientCapabilities ) lsp.CompletionList {
10- list := lsp.CompletionList {
11- Items : make ([]lsp.CompletionItem , len (candidates .List )),
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 )),
1222 IsIncomplete : ! candidates .IsComplete ,
1323 }
1424
@@ -21,13 +31,13 @@ func CompletionList(candidates lang.Candidates, caps lsp.TextDocumentClientCapab
2131 }
2232
2333 for i , c := range candidates .List {
24- list .Items [i ] = CompletionItem (c , snippetSupport , markdown )
34+ list .Items [i ] = toCompletionItem (c , snippetSupport , markdown )
2535 }
2636
2737 return list
2838}
2939
30- func CompletionItem (candidate lang.Candidate , snippet , markdown bool ) lsp. CompletionItem {
40+ func toCompletionItem (candidate lang.Candidate , snippet , markdown bool ) CompletionItem {
3141 doc := candidate .Description .Value
3242
3343 // TODO: revisit once go-lsp supports markdown in CompletionItem
@@ -44,14 +54,24 @@ func CompletionItem(candidate lang.Candidate, snippet, markdown bool) lsp.Comple
4454 }
4555
4656 te , format := textEdit (candidate .TextEdit , snippet )
57+ var cmd * lsp.Command
58+ if candidate .TriggerSuggest {
59+ cmd = & lsp.Command {
60+ Command : "editor.action.triggerSuggest" ,
61+ Title : "Suggest" ,
62+ }
63+ }
4764
48- return lsp.CompletionItem {
49- Label : candidate .Label ,
50- Kind : kind ,
51- InsertTextFormat : format ,
52- Detail : candidate .Detail ,
53- Documentation : doc ,
54- TextEdit : te ,
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 ,
5575 }
5676}
5777
0 commit comments