-
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: bad completion with syntax errors #39721
Comments
@kzhui125 Thanks for the issue report. |
"files.autoSave": "afterDelay",
"files.autoSaveDelay": 300,
"[golang]": {
"editor.tabSize": 4,
"editor.detectIndentation": false,
"editor.insertSpaces": false,
},
"go.delveConfig": {
"dlvLoadConfig": {
"followPointers": true,
"maxVariableRecurse": 1,
"maxStringLen": 100000,
"maxArrayValues": 1000,
"maxStructFields": -1
},
"apiVersion": 2,
"showGlobalVariables": true
},
"go.formatTool": "goimports",
"go.useLanguageServer": true,
"go.testFlags": [
"-v"
],
"go.languageServerFlags": [
"-rpc.trace",
],
"[go]": {
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.organizeImports": true,
},
},
"[go.mod]": {
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.organizeImports": true,
},
},
"gopls": {
"usePlaceholders": true,
"completeUnimported": true
}, |
Thanks @kzhui125!
|
Just took a look at this. Unlike many of the other completion issues that can be fixed with improved parser error recovery, I don't think this can be done with go/parser alone. There's no obvious way to represent this (invalid) syntax in a valid syntax tree. Perhaps we could have some basic fallback that looks for a preceding selector on an identifier, and then evaluate that identifier in the appropriate scope. I'm not sure how much that technique would generalize, so I'm not convinced it's worth doing. |
I expect this case is so common that it may be worth special casing in gopl's additional recovery (fixAST). In the above example, the sequence [period, newline, "outdent"] is a good sign that the current line is incomplete. It could be repaired to |
What version of Go, VS Code & VS Code Go extension are you using?
go version
to get version of Gocode -v
orcode-insiders -v
to get version of VS Code or VS Code Insidersfull code:
When I type "res.", I expect "err" will appear.
But now the code completion stop working, I have to type "err" manually.
Please fix the bug, thanks.
The text was updated successfully, but these errors were encountered: