-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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: provide function that gives list of candidate imports matching pattern #32749
Comments
I think this fits into the functionality covered by #31906, or is there anything else that we should add to that issue? |
@stamblerre - I think they're different. In this case I'm looking to provide a command that can be run in normal mode (which is the mode in which you can issue commands to Vim).
Reason being, not everyone does/will think that completion is the way to add an import. But also because this will likely become the primary way of adding named imports, e.g.:
Would be added via:
or similar. |
What LSP request would this command map to? |
That's really part of the reason for me raising the issue. The short answer is: I don't know 😄 Is there not any scope for an LSP implementation providing additional methods, beyond the spec? |
Not that I'm aware of, though we can certainly raise this with https://github.com/microsoft/language-server-protocol. What's the justification behind users wanting to manually add imports rather than using |
As i mentioned in #32749 (comment), because this will be the primary (only?) way of adding a named import. |
My best guess for how this could work with the current state of |
But this won't work where you already have an identifier in scope which has the name of the package being imported, which is exactly why I'd be looking to have a named import. |
Another case where this is required (just stumbled across it again, which reminded me): where you import a package for its side effects. |
It seems like it would require a change to the lsp spec to provide the exact function you are looking for, but there are a few ways I could see something similar potentially fitting in to gopls:
With finer control about what import fixes are applied, which we are working on supporting, these seem like things that would be possible. |
@suzmue - the description talks about providing a Vim command. Vim operates in different modes. Completion is possible in insert mode, at the point of the cursor. Commands operate in normal mode: the cursor position is not within document for such commands. In any case, the intention is to call such a command when elsewhere in the code; i.e. I don't want to have to jump up to the import declarations to perform a completion on an import, only to then jump back. Making a request to the LSP spec team sounds like a big step for something that I would think is better suited to an experiment for now. Is there a means by which we can extend the API of |
@myitcv vim-go provides this kind of functionality. I can help you understand how it works if needed. |
Thanks @bhcleek - understanding how to do this is not where I'm stuck 😄. It's that I think this logic belongs in Of course each editor (plugin) could implement this sort of thing, but that kind of defeats the point of a language server to my mind. As I mentioned in #32749 (comment), there are likely to be ideas/requirements like this that fall outside of the LSP spec. It makes sense to experiment with these at different levels:
For this particular requirement, because it is not covered by the LSP spec, I'm suggesting we explore avenue 2, as a test case if you will. |
We have not yet considered a plan for features outside of LSP in Still, I'm not convinced that this feature is necessarily one that we need to provide separately from existing In the meantime, I would definitely consider filing an issue against the LSP specification, as other languages may also be interested in this type of feature. It takes a while to make changes in the LSP spec, so definitely worth filing the issue, even if its not something they're interested in doing. |
On the back of some work to add e.g. using the proposed advanced query syntax:
where:
would return the results:
|
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
Much like
gopls
offers completion candidates, it should provide a function that allows editors to tab-complete/fuzzy match/whatever packages to import.For example, in
govim
we want to provide the commandGOVIMAddImport
such that when we type:(where
<Tab>
is us looking to complete the import), we should be able to callgopls
and get a list of import candidates matchingen
(according to some algorithm)Reference: govim/govim#317
cc @stamblerre @ianthehat
The text was updated successfully, but these errors were encountered: