-
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: autocompletion is appended to typed word #38600
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. |
Thanks for the report! /cc @muirdm |
I think this is because I'm not sure it would be easy to work around this type of syntax error. Maybe a code action to add in the missing parens? |
@muirdm: No, that's not a syntax error. |
Ah, I see what you're saying. It's not valid syntax in an |
Looks like it generally happens in the presence of syntax errors. For example: expectErr := proto.QueryParseError{Description: "No query"}) // <-- extra parenthesis If you try to autocomplete |
Yup, syntax errors wreak all sorts of havoc. We try to work around "expected" syntax errors you get as you type code (e.g. as you type |
FWIW, GoLand does not have this issue. |
There are two steps to improving this in gopls:
b := bytes.Buffer{}) // syntax error
b.Wr To offer |
@muirdm An example from GoLand. Is the GIF relevant to your question? I'm not sure if I'm understanding it correctly, but in GoLang, it does seem like
is valid in a sense
|
From what I can tell, GoLand's parser is more lenient, and will recover from such parsing errors. I'm not able to make it break on unexpected tokens. For example, if you do: b := bytes.Buffer{}:=
b2 := bytes.Buffer{} then doesn't understand the type of Looking at how parser errors are phrased, it seems GoLand has its own parser, and doesn't reuse Go's. |
Thanks. It makes sense that GoLand has its own parser since the standard library parser wasn't designed to work in the face of syntax errors. |
It makes for any language server to have to its own parser. 😉 Editors aren't compilers, after all. As an aside, this extends beyond just accidental syntax. Losing autocompletion occurs, of course, while just typing code. Here's an example where temporarily missing parantheses cause breakage: That's unrelated to this bug, but it shows how the current parser is a problem. |
I'm experiencing the same issue when typing a comment for documenting a method/function. Typing the first few characters of the method/function name and pressing tab/enter afterwards used to autocomplete properly, but now it just appends the name to the already typed characters. |
@kostaskoukouvis: That is #39262. |
Oops! My bad! :/ |
I'm experiencing the same issue here. The syntax error in my case was this statement: |
What did you do?
In VSCode, typed part of a word to autocomplete it, e.g.
cancel
, then selectedcancelCtx
.What did you expect to see?
I expected the current word to be
cancelCtx
.What did you see instead?
Current word became
canccancelCtx
.Build info
Also getting this behaviour with v0.4.0.
Go info
VSCode
VSCode-Go 0.14.1.
Log
gopls.log.gz
The text was updated successfully, but these errors were encountered: