Skip to content

Commit

Permalink
Report deprecated completion items as such (#337)
Browse files Browse the repository at this point in the history
  • Loading branch information
radeksimko authored Jan 4, 2021
1 parent 375ece5 commit 76ce9ad
Showing 1 changed file with 31 additions and 14 deletions.
45 changes: 31 additions & 14 deletions internal/lsp/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,16 @@ func ToCompletionList(candidates lang.Candidates, caps lsp.TextDocumentClientCap
IsIncomplete: !candidates.IsComplete,
}

snippetSupport := caps.Completion.CompletionItem.SnippetSupport

markdown := false
docsFormat := caps.Completion.CompletionItem.DocumentationFormat
if len(docsFormat) > 0 && docsFormat[0] == lsp.Markdown {
markdown = true
}

for i, c := range candidates.List {
list.Items[i] = toCompletionItem(c, snippetSupport, markdown)
list.Items[i] = toCompletionItem(c, caps.Completion)
}

return list
}

func toCompletionItem(candidate lang.Candidate, snippet, markdown bool) lsp.CompletionItem {
func toCompletionItem(candidate lang.Candidate, caps lsp.CompletionClientCapabilities) lsp.CompletionItem {
snippetSupport := caps.CompletionItem.SnippetSupport

doc := candidate.Description.Value

// TODO: Revisit when MarkupContent is allowed as Documentation
Expand All @@ -44,6 +38,8 @@ func toCompletionItem(candidate lang.Candidate, snippet, markdown bool) lsp.Comp
kind = lsp.FieldCompletion
}

// TODO: Omit item which uses kind unsupported by the client

var cmd *lsp.Command
if candidate.TriggerSuggest {
cmd = &lsp.Command{
Expand All @@ -52,14 +48,35 @@ func toCompletionItem(candidate lang.Candidate, snippet, markdown bool) lsp.Comp
}
}

return lsp.CompletionItem{
item := lsp.CompletionItem{
Label: candidate.Label,
Kind: kind,
InsertTextFormat: insertTextFormat(snippet),
InsertTextFormat: insertTextFormat(snippetSupport),
Detail: candidate.Detail,
Documentation: doc,
TextEdit: textEdit(candidate.TextEdit, snippet),
TextEdit: textEdit(candidate.TextEdit, snippetSupport),
Command: cmd,
AdditionalTextEdits: textEdits(candidate.AdditionalTextEdits, snippet),
AdditionalTextEdits: textEdits(candidate.AdditionalTextEdits, snippetSupport),
}

if caps.CompletionItem.DeprecatedSupport {
item.Deprecated = candidate.IsDeprecated
}
if tagSliceContains(caps.CompletionItem.TagSupport.ValueSet,
lsp.ComplDeprecated) && candidate.IsDeprecated {
item.Tags = []lsp.CompletionItemTag{
lsp.ComplDeprecated,
}
}

return item
}

func tagSliceContains(supported []lsp.CompletionItemTag, tag lsp.CompletionItemTag) bool {
for _, item := range supported {
if item == tag {
return true
}
}
return false
}

0 comments on commit 76ce9ad

Please sign in to comment.