-
Notifications
You must be signed in to change notification settings - Fork 18k
x/tools/gopls: improve completion suggestions #37656
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
Thank you for filing a gopls issue! Please take a look at the Troubleshooting guide, and make sure that you have provided all of the relevant information here. |
Thank you for the report. Can you provide a link to the repo where you are seeing these issues? I appreciate the examples, but it is hard to understand them completely without the full context of the package. |
Really, any piece of code will illustrate the problem. consider for example trying to pass in a func literal to something that expects an http.HandlerFunc, or this example:
here, you won't get a But I built the original examples while working on https://github.com/globusdigital/feature-toggles (e.g.: https://github.com/globusdigital/feature-toggles/blob/master/storage/mongo.go#L85, and start typing |
Thanks for the link. We'll take a look. /cc @muirdm |
This is what I see (note the first two candidates): What editor are you using and what do you see as your candidates? I'm guessing the problem is that you don't have snippets enabled. We recently changed literal completions to require the client to support snippets. For your original issue, there is another problem where literal completions don't work for variadic function args. I think we can fix that. |
The assumption is that typing the zero value for basic values is easy enough that you don't need a completion candidate. |
Literal completions (e.g. @stamblerre we may want to reconsider disabling all literal completions when the client doesn't have snippets. |
@muirdm |
@muirdm: I thought we had done that, or do you mean disabling the
This falls in the same category of literal completions, which are disabled if snippets are not supported by the client. @muirdm: Do you think we can come up with some best-effort literal completions that work without snippets? |
Literal completions already have non-snippet versions. We disabled them in https://go-review.googlesource.com/c/tools/+/216299, but there was some confusion in that decision (I had a critical typo in the related issue where I voted for the wrong change). Regarding all the junk candidates that couldn't possibly be useful, I think we can start filtering some of them out. I can make a separate issue for that. |
Ah, I'm sorry I didn't realize that these were our non-snippet versions of the candidates. Maybe they could diverge further from the snippet versions like @myitcv suggested in the original bug (#36655):
|
Since the only issue is having to backtrack with the cursor, maybe we could do |
Either works for me, though maybe we can start with just the opening brace if that's easier? |
I played around with the idea of emulating simple snippets using insert text and additional edits: https://go-review.googlesource.com/c/tools/+/222198 Honestly I don't think it is worth the extra code. I think we should either leave the current behavior and encourage people to use snippets, or revert to the previous behavior where, if you don't have snippets, you get |
Change https://golang.org/cl/222199 mentions this issue: |
Thanks for putting together a CL, @muirdm.
Just to refresh on the reasons I think this is worthwhile:
The code changes didn't look that invasive to my untrained eye? |
tbh, i'm absolutely fine as a user if i just have to move the cursor back a character after insertion. it's an insignificant price to pay to get those suggestions back, at least until the time that neovim gets support for snippets. |
Doesn't vim support the arrow keys these days? 😛 I'd rather the server not jump through hoops if the user can just install another package and get a better/fancier experience anyway. I know you @myitcv (and your users, and maybe other vim users) don't have that option yet, so I leave it up to @stamblerre. |
I agree with @muirdm that the extra code isn't worth it (note that the CL is https://golang.org/cl/222198, not https://golang.org/cl/222199 in #37656 (comment) above). Thank you for doing this work, though! I really appreciate the investigation. If it's possible to install a Vim plugin that supports snippets, I would suggest that as the way forward. |
We now properly offer literal completions when completing the variadic parameter. For example: func foo(...[]int) {} foo(<>) // now offers "[]int{}" Updates golang/go#37656. Change-Id: I91c47d455ae3f8051078c82a308f2b5ad4b3d4cd Reviewed-on: https://go-review.googlesource.com/c/tools/+/222199 Run-TryBot: Muir Manders <muir@mnd.rs> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Rebecca Stambler <rstambler@golang.org>
@stamblerre |
I don't believe so. I think we will stick to the approach @muirdm suggested in #37656 (comment), which is to recommend that Vim users install another package that adds snippet support. |
Hi,
This observation is from using gopls@0.3.3.
Suggestions for field values and function arguments aren't very useful.
If a completion is invoked for a field/func arg, logical suggestions such as empty-bodied functions (for func types), or map/array/struct composite literal expressions are never suggested. Instead, various variables, methods, functions, interfaces and base types that cannot possibly be used as values are suggested instead.
Some real examples:
(*chi.Mux).Use(
| <- expects varargs offunc(http.Handler) http.Handler
I would expect the first (or at least the top 3) suggestion to be
func(http.Handler) { return nil }
. Instead, the second suggestion is for achi.Chain
, which has a type offunc (middlewares ...func(http.Handler) http.Handler) Middlewares
. In fact, only the first suggestion has the correct type. Everything else has a completely different type, including curious suggestions such as module paths and builtin functions and types for some reason.Another example:
(*mongo.Client).Database(
| <- expectsstring
At the very least, I would expect an empty string as one of the top suggestions. Instead, the first suggestion is a function that returns a pointer to something, the second is also a function that accepts a pointer and returns another pointer, the third is a method, and the 4th is
nil
. Then I get various variables that are in scope but are not strings and I end up with the soup of builtins/module paths/interfaces and whatnot.Returning some types or methods could be useful, because you can continue the expression to possibly get to the correct type. But they shouldn't be the first suggestions, and suggesting builtins or interfaces isn't helpful at all, because you cannot keep typing afterwards and end up with the needed type.
The text was updated successfully, but these errors were encountered: