x/tools/gopls: improve completion results when they depend on code after the current line in the same file #43471
Labels
FeatureRequest
Issues asking for a new feature that does not need a proposal.
FrozenDueToAge
gopls
Issues related to the Go language server, gopls.
help wanted
Tools
This label describes issues relating to any tools in the x/tools repository.
Milestone
What version of Go are you using (
go version
)?1.15.6 / gopls 0.6.0
Does this issue reproduce with the latest release?
yes
What operating system and processor architecture are you using (
go env
)?linux/amd64
Description
A problem I frequently encounter using gopls is that if the completion target depends on code defined in the same file but after the cursor position, the completion is non-functional unless the expression is extremely simple.
Here are some concrete examples using vscode.
If the type
S
is defined before the current function and I start typing arange
statement, completion works fine:If the type
S
is defined after the current function and I start typing arange
statement, completion is not useful (it suggests some irrelevant packages):An
if
expression has the same problem:But if I only type a simple
s.
, completion works:I understand that the problem of trying to parse partial (i.e., broken) code is, in the general case, impossible. But doing a passable job in the typical cases seems important. ISTM that a heuristic as simple as "try parsing the code after deleting the line that the cursor is on" would cover the examples I showed here and most of the instances I notice day to day.
I looked for an existing issue as best I could with GH issue search but didn't find anything.
The text was updated successfully, but these errors were encountered: