mirror of
https://github.com/golang/go
synced 2024-11-18 20:04:52 -07:00
806e1cfd89
Use the packagestest framework to test completion. Add support for a slice of token.Position to packagestest to support this. Change-Id: Ie5ddece4446a3c74419727461a77faa3788cb040 Reviewed-on: https://go-review.googlesource.com/c/148197 Reviewed-by: Ian Cottrell <iancottrell@google.com> Run-TryBot: Rebecca Stambler <rstambler@golang.org>
54 lines
1.5 KiB
Go
54 lines
1.5 KiB
Go
// Copyright 2018 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package lsp
|
|
|
|
import (
|
|
"sort"
|
|
|
|
"golang.org/x/tools/internal/lsp/protocol"
|
|
"golang.org/x/tools/internal/lsp/source"
|
|
)
|
|
|
|
func toProtocolCompletionItems(items []source.CompletionItem) []protocol.CompletionItem {
|
|
var results []protocol.CompletionItem
|
|
sort.Slice(items, func(i, j int) bool {
|
|
return items[i].Score > items[j].Score
|
|
})
|
|
for _, item := range items {
|
|
results = append(results, protocol.CompletionItem{
|
|
Label: item.Label,
|
|
Detail: item.Detail,
|
|
Kind: float64(toProtocolCompletionItemKind(item.Kind)),
|
|
})
|
|
}
|
|
return results
|
|
}
|
|
|
|
func toProtocolCompletionItemKind(kind source.CompletionItemKind) protocol.CompletionItemKind {
|
|
switch kind {
|
|
case source.InterfaceCompletionItem:
|
|
return protocol.InterfaceCompletion
|
|
case source.StructCompletionItem:
|
|
return protocol.StructCompletion
|
|
case source.TypeCompletionItem:
|
|
return protocol.TypeParameterCompletion // ??
|
|
case source.ConstantCompletionItem:
|
|
return protocol.ConstantCompletion
|
|
case source.FieldCompletionItem:
|
|
return protocol.FieldCompletion
|
|
case source.ParameterCompletionItem, source.VariableCompletionItem:
|
|
return protocol.VariableCompletion
|
|
case source.FunctionCompletionItem:
|
|
return protocol.FunctionCompletion
|
|
case source.MethodCompletionItem:
|
|
return protocol.MethodCompletion
|
|
case source.PackageCompletionItem:
|
|
return protocol.ModuleCompletion // ??
|
|
default:
|
|
return protocol.TextCompletion
|
|
}
|
|
|
|
}
|