-
Notifications
You must be signed in to change notification settings - Fork 18k
x/tools/gopls: support autocompletion of unimported packages #31906
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
Comments
When this does get into |
@stamblerre |
It would be all available packages, not just stdlib. |
@stamblerre Are you doing now develop this feature? |
I am not actively working on it yet, so you're absolutely welcome to get started on it. |
@stamblerre @saibing I found out that this is a difference between https://github.com/saibing/tools & https://github.com/golang/tools/tree/ : saibing/tools already have this feature:
|
From microsoft/vscode-go#2575: There are really two components to this issue. For example (in both cases,
|
https://golang.org/cl/190338 adds support for autocompletion of unimported standard library packages This supports autocompletions in the first case listed above
|
versions
my settings // go settings
"go.buildOnSave": "off",
"go.lintTool":"golangci-lint",
"go.lintFlags": [
"--fast"
],
"go.useLanguageServer": true,
"go.languageServerExperimentalFeatures": {
"documentLink": false,
"format": true,
"autoComplete": true
},
"[go]": {
"editor.snippetSuggestions": "none",
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.organizeImports": true
}
},
"gopls": {
"usePlaceholders": true,
"completeUnimported": true,
}, when i type this codes go internal package can be auto import, but third party package in my go.mod can not be import. gopls output error
|
We don't yet have the exports loaded for the unimported packages, so it won't complete if you type |
Sorry No suggestions pop up |
@chengyayu: Are you using |
yes! it works! thanks for your suggestions. |
Does anybody know how to make this work for YCM in vim? I've tried to update the code of gopls (in YCM) to master, but the completion of unimported packages still doesn't work. |
When we're using I think it is helpful that |
We haven't yet implemented ranking for unimported candidates, but I think that issue can be solved with improved rankings. The ordering should probably be something like standard library packages are preferred over dependencies in the main module followed by packages in the module cache. We still want to suggest packages from the module cache that haven't been added as dependencies because users may still be interested in importing them. |
Thank you for your response!
It sounds good!
I think we have several different needs for
So, I think it is better that |
I don't think the number of results matters, only the order in which they appear. |
Change https://golang.org/cl/204203 mentions this issue: |
When proposing packages to import, we can propose more relevant packages first. Introduce that concept to the pkg struct, and sort by it when returning candidates. In all cases we prefer stdlib packages first. Then, in module mode, we prefer packages that are in the module's dependencies over those that aren't. We could go further and prefer direct deps over indirect too, but I didn't have the code for that handy. I also changed the alphabetical sort from import path to package name, because that's what the user sees first in the UI. Updates golang/go#31906 Change-Id: Ia981ee9ffe3202e2a68eef3a36f65e81849a4ac2 Reviewed-on: https://go-review.googlesource.com/c/tools/+/204203 Run-TryBot: Heschi Kreinick <heschi@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Change https://golang.org/cl/204204 mentions this issue: |
@110y to @ianthehat's point, why have yet another option (or n+ options), if instead the packages are ranked by some hierarchy? e.g. (autocompletions ranked first to last)
more options = more complexity = harder to maintain and for new users to understand |
Add a function that returns all the exported identifiers associated with a package name that doesn't have an import yet. This will allow completions like rand<> to return rand.Seed (from math/rand) and rand.Prime (from crypto/rand). Updates golang/go#31906 Change-Id: Iee290c786de263d42acbfabd76bf0edbf303afc9 Reviewed-on: https://go-review.googlesource.com/c/tools/+/204204 Run-TryBot: Heschi Kreinick <heschi@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Rebecca Stambler <rstambler@golang.org>
I think the only thing left to do here is turn it on by default. |
What about the increased completion latency when there are a lot of unimported packages? |
@heschik
How to turn it on currently? |
You can add the following to your VSCode settings: "gopls": {
"completeUnimported": true
} |
UPDATE Working now after upgrading to Go 1.13.4 — sorry for the trouble. @stamblerre thank you. Any idea why this popup keeps showing? I already have The popup remains there everytime I opened VS Code. Quitting doesn't help. My environment:
|
Change https://golang.org/cl/214947 mentions this issue: |
See for microsoft/vscode-go#2484 for context.
The text was updated successfully, but these errors were encountered: