Skip to content
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

Open
kzhui125 opened this issue Jun 19, 2020 · 7 comments
Open

x/tools/gopls: bad completion with syntax errors #39721

kzhui125 opened this issue Jun 19, 2020 · 7 comments
Labels
gopls/parsing Issues related to parsing / poor parser recovery. gopls Issues related to the Go language server, gopls. help wanted Tools This label describes issues relating to any tools in the x/tools repository.

Comments

@kzhui125
Copy link

What version of Go, VS Code & VS Code Go extension are you using?

  • Run go version to get version of Go
    • go version go1.14.3 darwin/amd64
  • Run code -v or code-insiders -v to get version of VS Code or VS Code Insiders
    • 1.46.0
    • a5d1cc28bb5da32ec67e86cc50f84c67cc690321
    • x64
  • Check your installed extensions to get the version of the VS Code Go extension
    • 0.14.4

full code:

package main

import "fmt"

type result struct {
	value interface{}
	err   error
}

func getResult() (interface{}, error) {
	return "test", nil
}

func main() {
	var res result
	res.value, res.err = getResult()
	fmt.Println(res)
}

1

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.

@kzhui125 kzhui125 changed the title no code intelessense no code completion Jun 19, 2020
@kzhui125 kzhui125 reopened this Jun 19, 2020
@kzhui125
Copy link
Author

4

another problem: when I type tab here, I expect "getResult()" will appear, but only "getResult" appear now.

@kzhui125 kzhui125 changed the title no code completion missing code completion Jun 19, 2020
@hyangah
Copy link
Contributor

hyangah commented Jun 19, 2020

@kzhui125 Thanks for the issue report.
Can you please run Preferences: Open Settings (JSON) command and Preferences: Open Workspace Settings (JSON) and share all the settings with the go. or ["go"] or gopls prefixes?

@kzhui125
Copy link
Author

kzhui125 commented Jun 19, 2020

    "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
    },

@kzhui125
Copy link
Author

1

@hyangah
Copy link
Contributor

hyangah commented Jun 19, 2020

Thanks @kzhui125!
/cc @stamblerre Can you please take a look and triage in gopls issue tracker? This issue discusses two symptoms and I guess the underlying problem is similar to #38600.

  1. missing completion.
  2. missing () even though "usePlaceholders": true is selected.

@stamblerre stamblerre changed the title missing code completion x/tools/gopls: bad completion with syntax errors Jun 19, 2020
@stamblerre stamblerre transferred this issue from golang/vscode-go Jun 19, 2020
@gopherbot gopherbot added Tools This label describes issues relating to any tools in the x/tools repository. gopls Issues related to the Go language server, gopls. labels Jun 19, 2020
@gopherbot gopherbot added this to the Unreleased milestone Jun 19, 2020
@golang golang deleted a comment from gopherbot Jun 19, 2020
@stamblerre stamblerre modified the milestones: Unreleased, gopls/v0.5.0 Jun 19, 2020
@stamblerre stamblerre added this to the gopls/unplanned milestone Oct 21, 2020
@findleyr
Copy link
Contributor

findleyr commented Apr 6, 2021

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.

@adonovan
Copy link
Member

adonovan commented May 3, 2023

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 SelectorExpr(Ident("res"), Ident("")).

@adonovan adonovan added the gopls/parsing Issues related to parsing / poor parser recovery. label Jul 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
gopls/parsing Issues related to parsing / poor parser recovery. gopls Issues related to the Go language server, gopls. help wanted Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

6 participants