Skip to content

Commit

Permalink
Completion: Return a non-nil list when no suggestions (#151)
Browse files Browse the repository at this point in the history
Closes #141
  • Loading branch information
julienduchesne authored Aug 7, 2024
1 parent 71857b2 commit 8cf3395
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
8 changes: 4 additions & 4 deletions pkg/server/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (s *Server) completionFromStack(line string, stack *nodestack.NodeStack, vm
indexes := strings.Split(lastWord, ".")

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

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

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

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

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

for _, field := range ranges {
Expand Down
6 changes: 3 additions & 3 deletions pkg/server/completion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ func TestCompletion(t *testing.T) {
replaceByString: "self.h",
expected: protocol.CompletionList{
IsIncomplete: false,
Items: nil,
Items: []protocol.CompletionItem{},
},
},
{
Expand Down Expand Up @@ -257,7 +257,7 @@ func TestCompletion(t *testing.T) {
replaceByString: "bar: bad",
expected: protocol.CompletionList{
IsIncomplete: false,
Items: nil,
Items: []protocol.CompletionItem{},
},
},
{
Expand Down Expand Up @@ -483,7 +483,7 @@ func TestCompletion(t *testing.T) {
replaceByString: "hello.hell.",
expected: protocol.CompletionList{
IsIncomplete: false,
Items: nil,
Items: []protocol.CompletionItem{},
},
},
{
Expand Down

0 comments on commit 8cf3395

Please sign in to comment.