-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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: autocomplete in import blocks #35877
Comments
Is there a use case for this once unimported completions are enabled by default? The only case I can think of is manually correcting an (incorrect) ambiguous import, but even that should be pretty rare. |
I agree the justification for this is weak. Maybe if you're exploring an import hierarchy, like you can't remember the exact package name you're looking for but you know what repo it was in? |
@heschik: That's what I was thinking. Definitely not pressing, but I thought it wasn't a bad idea. |
I can try to take a look into this one, if someone can point me in the right direction so as where to take a look. Thanks! We too have long import names, of which sometimes only a part is valid, eg: |
Another not-mutually-exclusive option is to make unimported package name completion match against the full package path instead of just the package name (i.e. completing package names in the code, not in import specs). Using your example path, the user could type |
Thanks a bunch @stamblerre ! |
Ok I tried asking some questions and figured out some code, however would really appreciate some help in how can I debug the application, via tests. Documentation seems to be missing on how to write my expectations for the following case:
Any direction is highly appreciated, thanks! |
@nbaztec: I saw that you got some guidance on Slack - were you able to figure out the issue? |
Yes, I happened to figure out the above. Also, is a completion snippet the only way to replace the text on the current line? |
Completion items have a |
Change https://golang.org/cl/249419 mentions this issue: |
Add a new autocomplete function that completes based on import path prefix rather than package name prefix. Updates golang/go#35877. Change-Id: Ib768080ee99debfff1c8c870d22dc7b7459deadd Reviewed-on: https://go-review.googlesource.com/c/tools/+/249419 Run-TryBot: Heschi Kreinick <heschi@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Danish Dua <danishdua@google.com>
https://golang.org/cl/250301 implements this feature, but I think there is still some work left here. In my opinion, the biggest blocker is the fact that A few remaining other issues:
/cc @dandua98 |
Maybe we only need to invalidate metadata if we lost or gained a valid package path (?). In other words, if before and after the change the file has the same 5 valid import paths and 1 different invalid import path, we don't need to invalidate the metadata. Adding my last note from CL here since CL is no long active:
I had similar results with "golang.org". For example I could get "golang.org/x/<>" to list candidates sometimes, but after typing "s", "golang.org/x/s<>" did not list anything. If I deleted and retyped the "s" and completed again, it would list things. |
The issue is that we don't really know if the package path was valid until after we've loaded it. But I think in the case of the terminal I'm guessing that the latency you're seeing is that package loads - I was seeing something similar. I basically had to leave the completion request active until |
#36918 is also relevant here. Our package metadata reloading model is generally an obstacle to manually typed imports. I have a small CL that will help when a user types with only one starting quote, but most editors insert the closing quote automatically. @heschik may have some other ideas here. @muirdm: You can see the actual speed of this feature by triggering completions at in an import path that has already been typed out. |
Change https://golang.org/cl/251086 mentions this issue: |
Ah, okay. Maybe it is worth it to do a simple/fast |
Oh that's a great suggestion - let me try it out. We can also detect if the change is on-disk or not, so we can avoid a ton of |
Ah, actually unfortunately, I don't think we'll be able to do that. I completely forgot that |
We may be able to use known packages to see if the user is typing a package path within the main module, but that may be error prone. Something to consider in a follow-up. |
Our metadata reloading model makes typing out import paths manually very slow. We can avoid some of the slowness by not invalidating metadata when a new import path is obviously invalid. Updates golang/go#35877 Change-Id: Ifcf9ebaac0b146a2098ef8d411fa85fefa7ba6ca Reviewed-on: https://go-review.googlesource.com/c/tools/+/251086 Run-TryBot: Rebecca Stambler <rstambler@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Danish Dua <danishdua@google.com> Reviewed-by: Robert Findley <rfindley@google.com>
@heschik has suggested that we might try loading with |
For the record, I think the |
@stamblerre should we close this issue and open new issues for import label and cursor placement? I think it would make it easy to track those bugs. |
Change https://golang.org/cl/255837 mentions this issue: |
Suggested in microsoft/vscode-go#2918.
The text was updated successfully, but these errors were encountered: