Skip to content

Commit

Permalink
lsp: ensure completion items is not null (#740)
Browse files Browse the repository at this point in the history
In the spec, items is not optional and so must be an empty list if there
are none.

Signed-off-by: Charlie Egan <charlie@styra.com>
  • Loading branch information
charlieegan3 committed May 23, 2024
1 parent 153f9a0 commit c9d0868
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions internal/lsp/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -691,6 +691,14 @@ func (l *LanguageServer) handleTextDocumentCompletion(
return nil, fmt.Errorf("failed to find completions: %w", err)
}

// make sure the items is always [] instead of null as is required by the spec
if items == nil {
return types.CompletionList{
IsIncomplete: false,
Items: make([]types.CompletionItem, 0),
}, nil
}

return types.CompletionList{
IsIncomplete: false,
Items: items,
Expand Down

0 comments on commit c9d0868

Please sign in to comment.