Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Report deprecated completion items as such #337

Merged
merged 1 commit into from
Jan 4, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}