1
0
mirror of https://github.com/golang/go synced 2024-11-19 11:14:47 -07:00
go/internal/lsp/testdata/deepcomplete/fuzzymatch/deep_fuzzy.go
Muir Manders 6afc7fcab5 internal/lsp: enable deep completion and fuzzy matching by default
Invert "useDeepCompletions" config flag to "disableDeepCompletion" and
separate out "disableFuzzyMatching" which reverts to the previous
prefix matching behavior.

I separated fuzzy matching tests out to a separate file so they aren't
entangled with deep completion tests. In coming up with representative
test cases I found a couple issues which I fixed:

- We were treating a fuzzy matcher score of 0 as no match, but the
  matcher returns 0 for candidates that match but have no bonuses. I
  changed the matcher interface so that a score of 0 counts as a
  match. For example, this was preventing a pattern of "o" from
  matching "foo".
- When we lower a candidate's score based on its depth, we were
  subtracting a static multiplier which could result in the score
  going negative. A negative score messes up future score weighting
  because multiplying it by a value in the range [0, 1) makes it
  bigger instead of smaller. Fix by scaling a candidate's score based
  on its depth rather than subtracting a constant factor.

Updates golang/go#32754

Change-Id: Ie6f9111f1696b0d067d08f7eed7b0a338ad9cd67
Reviewed-on: https://go-review.googlesource.com/c/tools/+/192137
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-08-30 16:47:54 +00:00

51 lines
1.3 KiB
Go

// Copyright 2019 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 fuzzymatch
func _() {
var a struct {
fabar int
fooBar string
}
a.fabar //@item(fuzzFabarField, "a.fabar", "int", "field")
a.fooBar //@item(fuzzFooBarField, "a.fooBar", "string", "field")
afa //@complete(" //", fuzzFabarField, fuzzFooBarField)
afb //@complete(" //", fuzzFooBarField, fuzzFabarField)
fab //@complete(" //", fuzzFabarField)
o //@complete(" //", fuzzFooBarField)
var myString string
myString = ar //@complete(" //", fuzzFooBarField, fuzzFabarField)
var b struct {
c struct {
d struct {
e struct {
abc string
}
abc float32
}
abc bool
}
abc int
}
b.abc //@item(fuzzABCInt, "b.abc", "int", "field")
b.c.abc //@item(fuzzABCbool, "b.c.abc", "bool", "field")
b.c.d.abc //@item(fuzzABCfloat, "b.c.d.abc", "float32", "field")
b.c.d.e.abc //@item(fuzzABCstring, "b.c.d.e.abc", "string", "field")
// in depth order by default
abc //@complete(" //", fuzzABCInt, fuzzABCbool, fuzzABCfloat)
// deep candidate that matches expected type should still ranked first
var s string
s = abc //@complete(" //", fuzzABCstring, fuzzABCInt, fuzzABCbool)
}