Skip to content

Commit 8cf3395

Browse files
Completion: Return a non-nil list when no suggestions (#151)
Closes #141
1 parent 71857b2 commit 8cf3395

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

pkg/server/completion.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func (s *Server) completionFromStack(line string, stack *nodestack.NodeStack, vm
6666
indexes := strings.Split(lastWord, ".")
6767

6868
if len(indexes) == 1 {
69-
var items []protocol.CompletionItem
69+
items := []protocol.CompletionItem{}
7070
// firstIndex is a variable (local) completion
7171
for !stack.IsEmpty() {
7272
if curr, ok := stack.Pop().(*ast.Local); ok {
@@ -87,15 +87,15 @@ func (s *Server) completionFromStack(line string, stack *nodestack.NodeStack, vm
8787
ranges, err := processing.FindRangesFromIndexList(stack, indexes, vm, true)
8888
if err != nil {
8989
log.Errorf("Completion: error finding ranges: %v", err)
90-
return nil
90+
return []protocol.CompletionItem{}
9191
}
9292

9393
completionPrefix := strings.Join(indexes[:len(indexes)-1], ".")
9494
return s.createCompletionItemsFromRanges(ranges, completionPrefix, line, position)
9595
}
9696

9797
func (s *Server) completionStdLib(line string) []protocol.CompletionItem {
98-
var items []protocol.CompletionItem
98+
items := []protocol.CompletionItem{}
9999

100100
stdIndex := strings.LastIndex(line, "std.")
101101
if stdIndex != -1 {
@@ -134,7 +134,7 @@ func (s *Server) completionStdLib(line string) []protocol.CompletionItem {
134134
}
135135

136136
func (s *Server) createCompletionItemsFromRanges(ranges []processing.ObjectRange, completionPrefix, currentLine string, position protocol.Position) []protocol.CompletionItem {
137-
var items []protocol.CompletionItem
137+
items := []protocol.CompletionItem{}
138138
labels := make(map[string]bool)
139139

140140
for _, field := range ranges {

pkg/server/completion_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ func TestCompletion(t *testing.T) {
175175
replaceByString: "self.h",
176176
expected: protocol.CompletionList{
177177
IsIncomplete: false,
178-
Items: nil,
178+
Items: []protocol.CompletionItem{},
179179
},
180180
},
181181
{
@@ -257,7 +257,7 @@ func TestCompletion(t *testing.T) {
257257
replaceByString: "bar: bad",
258258
expected: protocol.CompletionList{
259259
IsIncomplete: false,
260-
Items: nil,
260+
Items: []protocol.CompletionItem{},
261261
},
262262
},
263263
{
@@ -483,7 +483,7 @@ func TestCompletion(t *testing.T) {
483483
replaceByString: "hello.hell.",
484484
expected: protocol.CompletionList{
485485
IsIncomplete: false,
486-
Items: nil,
486+
Items: []protocol.CompletionItem{},
487487
},
488488
},
489489
{

0 commit comments

Comments
 (0)