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: autocompletion of struct field of type func from external package omits import identifier in placeholder #50539

Closed
skaldesh opened this issue Jan 9, 2022 · 4 comments
Labels
FrozenDueToAge gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@skaldesh
Copy link

skaldesh commented Jan 9, 2022

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

Version Information
  • Run go version to get version of Go from the VS Code integrated terminal.
    • go version go1.17.6 linux/amd64
  • Run gopls -v version to get version of Gopls from the VS Code integrated terminal.
    • golang.org/x/tools/gopls v0.7.4
      golang.org/x/tools/gopls@v0.7.4 h1:hw8cpqjio1iMwIKbbDkG3MeW4l8R9dY/yqOHqv7HImA=
  • Run code -v or code-insiders -v to get version of VS Code or VS Code Insiders.
    • 1.62.0
      b3318bc0524af3d74034b8bb8a64df0ccf35549a
      x64
  • Check your installed extensions to get the version of the VS Code Go extension
    • v.0.30.0
  • Run Ctrl+Shift+P (Cmd+Shift+P on Mac OS) > Go: Locate Configured Go Tools command.
gopkgs:	/home/skaldesh/go/bin/gopkgs: go1.17
		path	github.com/uudashr/gopkgs/v2/cmd/gopkgs
		mod	github.com/uudashr/gopkgs/v2	v2.1.2	h1:A0+QH6wqNRHORJnxmqfeuBEsK4nYQ7pgcOHhqpqcrpo=
		dep	github.com/karrick/godirwalk	v1.12.0	h1:nkS4xxsjiZMvVlazd0mFyiwD4BR9f3m6LXGhM2TUx3Y=
		dep	github.com/pkg/errors	v0.8.1	h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
	
	go-outline:	/home/skaldesh/go/bin/go-outline: go1.17
		path	github.com/ramya-rao-a/go-outline
		mod	github.com/ramya-rao-a/go-outline	v0.0.0-20210608161538-9736a4bde949	h1:iaD+iVf9xGfajsJp+zYrg9Lrk6gMJ6/hZHO4cYq5D5o=
		dep	golang.org/x/tools	v0.1.1	h1:wGiQel/hW0NnEkJUk8lbzkX2gFJU6PFxf1v5OlCfuOs=
	
	gotests:	not installed
	gomodifytags:	/home/skaldesh/go/bin/gomodifytags: go1.17
		path	github.com/fatih/gomodifytags
		mod	github.com/fatih/gomodifytags	v1.13.0	h1:fmhwoecjZ5c34Q2chjRB9cL8Rgag+1TOSMy+grissMc=
		dep	github.com/fatih/camelcase	v1.0.0	h1:hxNvNX/xYBp0ovncs8WyWZrOrpBNub/JfaMvbURyft8=
		dep	github.com/fatih/structtag	v1.2.0	h1:/OdNE99OxoI/PqaW/SuSK9uxxT3f/tcSZgon/ssNSx4=
		dep	golang.org/x/tools	v0.0.0-20180824175216-6c1c5e93cdc1	h1:EAPsk8kfGCjxQagrkWjzXlUWe2p3gj5MknO+z2o9GKc=
	
	impl:	/home/skaldesh/go/bin/impl: go1.17
		path	github.com/josharian/impl
		mod	github.com/josharian/impl	v1.1.0	h1:gafhg1OFVMq46ifdkBa8wp4hlGogjktjjA5h/2j4+2k=
		dep	golang.org/x/mod	v0.2.0	h1:KU7oHjnv3XNWfa5COkzUifxZmxp1TyI7ImMXqFxLwvQ=
		dep	golang.org/x/tools	v0.0.0-20200522201501-cb1345f3a375	h1:SjQ2+AKWgZLc1xej6WSzL+Dfs5Uyd5xcZH1mGC411IA=
		dep	golang.org/x/xerrors	v0.0.0-20191204190536-9bdfabe68543	h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
	
	goplay:	not installed
	dlv:	/home/skaldesh/go/bin/dlv: go1.17
		path	github.com/go-delve/delve/cmd/dlv
		mod	github.com/go-delve/delve	v1.7.0	h1:MaWAD3LtvjE/LL98urSHPjaMT+OubpQ2sqF3R2Uj1rc=
		dep	github.com/cosiner/argv	v0.1.0	h1:BVDiEL32lwHukgJKP87btEPenzrrHUjajs/8yzaqcXg=
		dep	github.com/cpuguy83/go-md2man	v1.0.10	h1:BSKMNlYxDvnunlTymqtgONjNnaRV1sTpcovwwjF22jk=
		dep	github.com/google/go-dap	v0.5.0	h1:RMHAVn5xeunBakYk65ggHXttk6qjZVdbmi+xhAoL2wY=
		dep	github.com/hashicorp/golang-lru	v0.5.4	h1:YDjusn29QI/Das2iO9M0BHnIbxPeyuCHsjMW+lJfyTc=
		dep	github.com/mattn/go-isatty	v0.0.3	h1:ns/ykhmWi7G9O+8a448SecJU3nSMBXJfqQkl0upE1jI=
		dep	github.com/peterh/liner	v0.0.0-20170317030525-88609521dc4b	h1:8uaXtUkxiy+T/zdLWuxa/PG4so0TPZDZfafFNNSaptE=
		dep	github.com/russross/blackfriday	v1.5.2	h1:HyvC0ARfnZBqnXwABFeSZHpKvJHJJfPz81GNueLj0oo=
		dep	github.com/sirupsen/logrus	v1.6.0	h1:UBcNElsrwanuuMsnGSlYmtmgbb23qDR5dG+6X6Oo89I=
		dep	github.com/spf13/cobra	v0.0.0-20170417170307-b6cb39589372	h1:eRfW1vRS4th8IX2iQeyqQ8cOUNOySvAYJ0IUvTXGoYA=
		dep	github.com/spf13/pflag	v0.0.0-20170417173400-9e4c21054fa1	h1:7bozMfSdo41n2NOc0GsVTTVUiA+Ncaj6pXNpm4UHKys=
		dep	go.starlark.net	v0.0.0-20200821142938-949cc6f4b097	h1:YiRMXXgG+Pg26t1fjq+iAjaauKWMC9cmGFrtOEuwDDg=
		dep	golang.org/x/arch	v0.0.0-20190927153633-4e8777c89be4	h1:QlVATYS7JBoZMVaf+cNjb90WD/beKVHnIxFKT4QaHVI=
		dep	golang.org/x/sys	v0.0.0-20200625212154-ddb9806d33ae	h1:Ih9Yo4hSPImZOpfGuA4bR/ORKTAbhZo2AbWNRCnevdo=
		dep	gopkg.in/yaml.v2	v2.2.1	h1:mUhvW9EsL+naU5Q3cakzfE91YhliOondGd6ZrsDBHQE=
	
	dlv-dap:	/home/skaldesh/go/bin/dlv-dap: go1.17.3
		path	github.com/go-delve/delve/cmd/dlv
		mod	github.com/go-delve/delve	v1.7.3	h1:5I8KjqwKIz6I7JQ4QA+eY5PRB0+INs9h7wEDRzFnuHQ=
		dep	github.com/cilium/ebpf	v0.7.0	h1:1k/q3ATgxSXRdrmPfH8d7YK0GfqVsEKZAX9dQZvs56k=
		dep	github.com/cosiner/argv	v0.1.0	h1:BVDiEL32lwHukgJKP87btEPenzrrHUjajs/8yzaqcXg=
		dep	github.com/cpuguy83/go-md2man/v2	v2.0.0	h1:EoUDS0afbrsXAZ9YQ9jdu/mZ2sXgT1/2yyNng4PGlyM=
		dep	github.com/derekparker/trie	v0.0.0-20200317170641-1fdf38b7b0e9	h1:G765iDCq7bP5opdrPkXk+4V3yfkgV9iGFuheWZ/X/zY=
		dep	github.com/google/go-dap	v0.6.0	h1:Y1RHGUtv3R8y6sXq2dtGRMYrFB2hSqyFVws7jucrzX4=
		dep	github.com/hashicorp/golang-lru	v0.5.4	h1:YDjusn29QI/Das2iO9M0BHnIbxPeyuCHsjMW+lJfyTc=
		dep	github.com/mattn/go-isatty	v0.0.3	h1:ns/ykhmWi7G9O+8a448SecJU3nSMBXJfqQkl0upE1jI=
		dep	github.com/mattn/go-runewidth	v0.0.3	h1:a+kO+98RDGEfo6asOGMmpodZq4FNtnGP54yps8BzLR4=
		dep	github.com/peterh/liner	v1.2.1	h1:O4BlKaq/LWu6VRWmol4ByWfzx6MfXc5Op5HETyIy5yg=
		dep	github.com/russross/blackfriday/v2	v2.0.1	h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q=
		dep	github.com/shurcooL/sanitized_anchor_name	v1.0.0	h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo=
		dep	github.com/sirupsen/logrus	v1.6.0	h1:UBcNElsrwanuuMsnGSlYmtmgbb23qDR5dG+6X6Oo89I=
		dep	github.com/spf13/cobra	v1.1.3	h1:xghbfqPkxzxP3C/f3n5DdpAbdKLj4ZE4BWQI362l53M=
		dep	github.com/spf13/pflag	v1.0.5	h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
		dep	go.starlark.net	v0.0.0-20200821142938-949cc6f4b097	h1:YiRMXXgG+Pg26t1fjq+iAjaauKWMC9cmGFrtOEuwDDg=
		dep	golang.org/x/arch	v0.0.0-20190927153633-4e8777c89be4	h1:QlVATYS7JBoZMVaf+cNjb90WD/beKVHnIxFKT4QaHVI=
		dep	golang.org/x/sys	v0.0.0-20211019181941-9d821ace8654	h1:id054HUawV2/6IGm2IV8KZQjqtwAOo2CYlOToYqa0d0=
		dep	gopkg.in/yaml.v2	v2.4.0	h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
	
	staticcheck:	/home/skaldesh/go/bin/staticcheck: go1.17
		path	honnef.co/go/tools/cmd/staticcheck
		mod	honnef.co/go/tools	v0.2.1	h1:/EPr//+UMMXwMTkXvCCoaJDq8cpjMO80Ou+L4PDo2mY=
		dep	github.com/BurntSushi/toml	v0.3.1	h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
		dep	golang.org/x/mod	v0.3.0	h1:RM4zey1++hCTbCVQfnWeKs9/IEsaBLA8vTkd0WVtmH4=
		dep	golang.org/x/sys	v0.0.0-20210119212857-b64e53b001e4	h1:myAQVi0cGEoqQVR5POX+8RR2mrocKqNN1hmeMqhX27k=
		dep	golang.org/x/tools	v0.1.0	h1:po9/4sTYwZU9lPhi1tOrb4hCv3qrhiQ77LZfGa2OjwY=
		dep	golang.org/x/xerrors	v0.0.0-20200804184101-5ec99f83aff1	h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
	
	gopls:	/home/skaldesh/go/bin/gopls: go1.17.5
		path	golang.org/x/tools/gopls
		mod	golang.org/x/tools/gopls	v0.7.4	h1:hw8cpqjio1iMwIKbbDkG3MeW4l8R9dY/yqOHqv7HImA=
		dep	github.com/BurntSushi/toml	v0.4.1	h1:GaI7EiDXDRfa8VshkTj7Fym7ha+y8/XxIgD2okUIjLw=
		dep	github.com/google/go-cmp	v0.5.6	h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ=
		dep	github.com/sergi/go-diff	v1.1.0	h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
		dep	golang.org/x/mod	v0.5.1	h1:OJxoQ/rynoF0dcCdI7cLPktw/hR2cueqYfjm43oqK38=
		dep	golang.org/x/sync	v0.0.0-20210220032951-036812b2e83c	h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ=
		dep	golang.org/x/sys	v0.0.0-20211019181941-9d821ace8654	h1:id054HUawV2/6IGm2IV8KZQjqtwAOo2CYlOToYqa0d0=
		dep	golang.org/x/text	v0.3.7	h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
		dep	golang.org/x/tools	v0.1.9-0.20211209172050-90a85b2969be	h1:JRBiPXZpZ1FsceyPRRme0vX394zXC3xlhqu705k9nzM=
		dep	golang.org/x/xerrors	v0.0.0-20200804184101-5ec99f83aff1	h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
		dep	honnef.co/go/tools	v0.2.1	h1:/EPr//+UMMXwMTkXvCCoaJDq8cpjMO80Ou+L4PDo2mY=
		dep	mvdan.cc/gofumpt	v0.1.1	h1:bi/1aS/5W00E2ny5q65w9SnKpWEF/UIOqDYBILpo9rA=
		dep	mvdan.cc/xurls/v2	v2.3.0	h1:59Olnbt67UKpxF1EwVBopJvkSUBmgtb468E4GVWIZ1I=

Share the Go related settings you have added/edited

Run Preferences: Open Settings (JSON) command to open your settings.json file.
Share all the settings with the go. or ["go"] or gopls prefixes.

"go.toolsGopath": "/home/skaldesh/go",
    "go.useLanguageServer": true,
    "go.addTags": {
        "tags": "json,yaml",
        "options": "json=omitempty,yaml=inline",
        "promptForTags": true,
        "transform": "snakecase"
    },
    "[go]": {
        "editor.formatOnSave": true,
        "editor.codeActionsOnSave": {
            "source.organizeImports": true,
            "source.fixAll": true,
        },
        // Optional: Disable snippets, as they conflict with completion ranking.
        "editor.snippetSuggestions": "none",
    },
    "[go.mod]": {
        "editor.formatOnSave": true,
        "editor.codeActionsOnSave": {
            "source.organizeImports": true,
        },
    },
    "gopls": {
         // Add parameter placeholders when completing a function.
        "usePlaceholders": true,
    
        // If true, enable additional analyses with staticcheck.
        // Warning: This will significantly increase memory usage.
        "staticcheck": false,

        "analyses": {
            "fillreturns": true,        
            "nonewvars": true,
        }
    },

Describe the bug

A clear and concise description of what the bug.

When letting the go extension auto complete a struct field that is of type func and from an external package, parameters with a type defined by said external package do not receive the import identifier.

A clear and concise description of what you expected to happen.

I expected them to be added

Steps to reproduce the behavior:

Sample test file:

package main

import (
	"github.com/desertbit/grumble"
)

func main() {
	App :=grumble.New(&grumble.Config{
		Name: "test",
		Description: "test description",
		Flags: func(f *Flags) { // <--- ERROR here, should be func(f *grumble.Flags) { ... }

		},
	})
}

Reproduce:

  1. Create file with the above content
  2. go get github.com/desertbit/grumble
  3. Delete Flags keyword from config and use VSCode autocomplete to fill it again' So type Fl and then chose suggestion from autocomplete
  4. You see, that the generated code misses the grumble. import identifier for the *Flags type of the argument

Screenshots or recordings

If applicable, add screenshots or recordings to help explain your problem
Here is a video

@suzmue
Copy link
Contributor

suzmue commented Jan 10, 2022

I was able to reproduce this by setting "gopls.usePlaceholders": true.

This is an issue with the place holder that is provided for the completion and does not seem to affect the fill struct, or a completion triggered at the value.

@suzmue suzmue changed the title Jan 10, 2022
@suzmue suzmue transferred this issue from golang/vscode-go Jan 10, 2022
@suzmue suzmue added the gopls Issues related to the Go language server, gopls. label Jan 10, 2022
@suzmue suzmue added this to the gopls/unplanned milestone Jan 10, 2022
@gopherbot gopherbot added the Tools This label describes issues relating to any tools in the x/tools repository. label Jan 10, 2022
@suzmue suzmue modified the milestones: gopls/on-deck, gopls/v0.8.0 Jan 14, 2022
@findleyr findleyr modified the milestones: gopls/v0.8.0, gopls/v0.8.1 Feb 21, 2022
@findleyr findleyr modified the milestones: gopls/v0.8.1, gopls/v0.8.2 Mar 7, 2022
@gopherbot
Copy link

Change https://go.dev/cl/395678 mentions this issue: internal/lsp/source: descend into fields and field lists in qualifyExpr

@findleyr
Copy link
Contributor

Thanks for the detailed bug report. This was a particularly gnarly bug to track down, and it wouldn't have been possible without the details here.

@skaldesh
Copy link
Author

Happy it got solved, thank you :)

@findleyr findleyr self-assigned this Mar 31, 2022
@golang golang locked and limited conversation to collaborators Jun 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

4 participants