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
x/tools/gopls: type-conversions are not scored correctly #36015
Comments
Thank you for the report! /cc @muirdm for completion expertise |
What if instead of completing to just |
Change https://golang.org/cl/210288 mentions this issue: |
@quasilyte please try out the above change if possible. |
We could also take it further and offer pre-type converted candidates. For example: func complicatedMath() int { return 0 }
var result float64 = complicat<> // completes straight to "float64(complicatedMath())" It would be cool in some situations, but it runs a bit counter to Go's "no automatic number type conversion" policy. |
Sorry for the late response. It does work as I would have expected, thank you. 👐
That sounds interesting, although I usually omit the explicit type on the left, so the type doesn't need to be repeated: var result = float64(complicatedMath()) |
When the expected type is a basic type, we will now offer a corresponding type conversion candidate. For example: var foo int64 foo = // offer "int64(<>)" as a candidate The type conversion candidate will be ranked below matching concrete candidates but above the sea of non-matching candidates. This change broke almost every completion test. I added a new completion option for literal candidates so tests can selectively ask for literal completions. Updates golang/go#36015. Change-Id: I63fbdb33436d662a666c1ffd3b2d918d840dccc7 Reviewed-on: https://go-review.googlesource.com/c/tools/+/210288 Run-TryBot: Rebecca Stambler <rstambler@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Rebecca Stambler <rstambler@golang.org>
I think this can be closed out now? |
I believe so. |
After CL183137, there is a problem with typenames completion where we want to do a type conversion.
It's caused by this check:
(Although removing it does solve this particular issue, we get other issues out of it, this is why someone more experienced with gopls needs to take a look.)
It bites when we try to autocomplete inside expression context and expect to use a type conversion:
In my understanding, a type name is a valid candidate even when not inside type expression context, since it can be an attempt to write a type-converting expression.
Actual behavior
coordX
is scored with1.0
, as all other "non matching" candidates.Expected behavior
coordX
is at least a little bit higher than1.0
.Note that
a575db70c06744141b7a52bb6c4aff8d860588c6
(a commit before mentioned CL works as expected):If we need to define "when a type name is appropriate outside of wantTypeName", I would say it's "an expression context that expects a type that can be acquired by doing a conversion to the given type name". So, if we autocomplete
Foo
-typed expression,Foo
is a matching candidate (score>1).The text was updated successfully, but these errors were encountered: