mirror of
https://github.com/golang/go
synced 2024-11-18 16:44:43 -07:00
internal/lsp: support multi-dereferencing completion candidates
Now we keep a count of how many times to dereference a candidate. For example: var foo ***int var _ int = f<> // Now we offer "***foo" instead of "*foo". Change-Id: I14edc40aeec6884399eceb3dd3b4f85dc74a773c Reviewed-on: https://go-review.googlesource.com/c/tools/+/218580 Run-TryBot: Muir Manders <muir@mnd.rs> Reviewed-by: Rebecca Stambler <rstambler@golang.org>
This commit is contained in:
parent
1e13d9580f
commit
2de505fc53
@ -384,8 +384,9 @@ type candidate struct {
|
||||
// makePointer is true if the candidate type name T should be made into *T.
|
||||
makePointer bool
|
||||
|
||||
// dereference is true if the candidate obj should be made into *obj.
|
||||
dereference bool
|
||||
// dereference is a count of how many times to dereference the candidate obj.
|
||||
// For example, dereference=2 turns "foo" into "**foo" when formatting.
|
||||
dereference int
|
||||
|
||||
// imp is the import that needs to be added to this package in order
|
||||
// for this candidate to be valid. nil if no import needed.
|
||||
@ -1804,9 +1805,10 @@ func (c *completer) matchingCandidate(cand *candidate, seen map[types.Type]struc
|
||||
seen[cand.obj.Type()] = struct{}{}
|
||||
}
|
||||
|
||||
if !saw && c.matchingCandidate(&candidate{obj: c.fakeObj(ptr.Elem())}, seen) {
|
||||
fakeCandidate := candidate{obj: c.fakeObj(ptr.Elem())}
|
||||
if !saw && c.matchingCandidate(&fakeCandidate, seen) {
|
||||
// Mark the candidate so we know to prepend "*" when formatting.
|
||||
cand.dereference = true
|
||||
cand.dereference = 1 + fakeCandidate.dereference
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
@ -134,8 +134,10 @@ func (c *completer) item(cand candidate) (CompletionItem, error) {
|
||||
var prefixOp string
|
||||
if cand.takeAddress {
|
||||
prefixOp = "&"
|
||||
} else if cand.makePointer || cand.dereference {
|
||||
} else if cand.makePointer {
|
||||
prefixOp = "*"
|
||||
} else if cand.dereference > 0 {
|
||||
prefixOp = strings.Repeat("*", cand.dereference)
|
||||
}
|
||||
|
||||
if prefixOp != "" {
|
||||
|
@ -37,6 +37,10 @@ func _() {
|
||||
|
||||
wantsVariadic() //@rank(")", addrCPtr, addrA),snippet(")", addrCPtr, "*c", "*c")
|
||||
|
||||
var d **int
|
||||
**d //@item(addrDPtr, "**d", "**int", "var")
|
||||
var _ int = _ //@rank("_ //", addrDPtr, addrA),snippet("_ //", addrDPtr, "**d", "**d")
|
||||
|
||||
type namedPtr *int
|
||||
var np namedPtr
|
||||
*np //@item(addrNamedPtr, "*np", "namedPtr", "var")
|
||||
|
4
internal/lsp/testdata/lsp/summary.txt.golden
vendored
4
internal/lsp/testdata/lsp/summary.txt.golden
vendored
@ -1,10 +1,10 @@
|
||||
-- summary --
|
||||
CompletionsCount = 227
|
||||
CompletionSnippetCount = 66
|
||||
CompletionSnippetCount = 67
|
||||
UnimportedCompletionsCount = 11
|
||||
DeepCompletionsCount = 5
|
||||
FuzzyCompletionsCount = 8
|
||||
RankedCompletionsCount = 84
|
||||
RankedCompletionsCount = 86
|
||||
CaseSensitiveCompletionsCount = 4
|
||||
DiagnosticsCount = 38
|
||||
FoldingRangesCount = 2
|
||||
|
Loading…
Reference in New Issue
Block a user