Skip to content
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: offer undeclared names in lexical completion #69993

Closed
findleyr opened this issue Oct 22, 2024 · 3 comments
Closed

x/tools/gopls: offer undeclared names in lexical completion #69993

findleyr opened this issue Oct 22, 2024 · 3 comments
Labels
FeatureRequest Issues asking for a new feature that does not need a proposal. gopls/completion Issues related to auto-completion in gopls. gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository.

Comments

@findleyr
Copy link
Member

This issue is extracted from #69980, where the request is to include undeclared (but used) names in lexical completion results.
We could do this by extracting such names from type errors (see also gopls/internal/analysis/undeclaredname).

I think we're much less likely to implement this feature than we are to offer the fix in #69980. Presumably it's much more important to help users fix their incorrect syntax, than it is to operate as though the syntax were valid. Putting in the unplanned milestone.

func _() {
  myvariable = 2
  foo(myv_) <-- offer 'myvariable' in lexical completion results here
}
@gopherbot gopherbot added Tools This label describes issues relating to any tools in the x/tools repository. gopls Issues related to the Go language server, gopls. labels Oct 22, 2024
@findleyr findleyr added this to the gopls/unplanned milestone Oct 22, 2024
@gopherbot gopherbot modified the milestones: gopls/unplanned, Unreleased Oct 22, 2024
@findleyr findleyr added FeatureRequest Issues asking for a new feature that does not need a proposal. gopls/completion Issues related to auto-completion in gopls. labels Oct 22, 2024
@xzbdmw
Copy link

xzbdmw commented Oct 22, 2024

What I think is that by accepting illegal syntax for completion, some underline error mark would appear, and code actions can be used after confirming, without moving the cursor to where the error really occurs, is it acceptable? I can take a try then.

@findleyr findleyr modified the milestones: Unreleased, gopls/unplanned Oct 23, 2024
@findleyr
Copy link
Member Author

@xzbdmw I think the tricky thing is defining the name in the lexical scope. Right now, gopls looks in the surrounding types.Scope to find available names. If the name is undefined due to the invalid initializer, it won't be available in the scope. So you'd need to either walk the syntax or look at type errors to guess what other names might be intended. While that's doable (see for example the undeclaredname analyzer), it's liable to be tricky, and the value added is not that high. In practice, the user will fix the invalid initializer before moving on to the next line.

So I think this feature is relatively tricky, and not very impactful. Therefore, it is unlikely to be prioritized.
In fact, I think this is so infeasible that we should close this issue: I don't think we'd accept this feature as a contribution.

@findleyr findleyr closed this as not planned Won't fix, can't repro, duplicate, stale Oct 24, 2024
@xzbdmw
Copy link

xzbdmw commented Oct 24, 2024

That’s fair, the alternative would be using buffer completion source for this .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
FeatureRequest Issues asking for a new feature that does not need a proposal. gopls/completion Issues related to auto-completion in gopls. gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

3 participants