golang snippets/auto completion not working with vs code
Asked Answered
P

2

5

I use VS Code with wsl terminal. I have installed many extensions for theme and snippet. For C/C++, Python, JS,HTML/CSS, etc snippets work but with GO it's not working. When I type imp and I expect to get auto-completion like import, but it does not show up. It works with sublime though. For GO, I have installed

  1. Go (from Microsoft)
  2. Golang postfix code completion
  3. gotemplate-syntax
  4. GO snippets

Especially GO snippets is designed to give snippet for func main but it won't do so. Anything I am missing on?

Psychasthenia answered 1/6, 2020 at 9:22 Comment(3)
If I were you I'll first disable all other plugins except the recommended go plugin, then restart your vscode and see if it helpsJulejulee
still won't workPsychasthenia
Maybe this helps, if autocomplete for go in vscode does not work: https://mcmap.net/q/2036071/-vscode-no-autocomplete-for-f-close-on-fileLehr
D
5

One thing you can do is enable the use of Go's Language Server - gopls. Go to the Settings and search for "Use Language Server". You will need to reload (or restart) your VSCode. On reload it should warn you that you need to install/update gopls and other tools - do it and you should be fine.

Note:
gopls is beta at best. It will sometimes crash, use excessive CPU and so on. It's not ideal but people are working on it and it's getting better every day. Just keep in mind that it might be less that ideal, OK? :)

Distinguishing answered 1/6, 2020 at 13:11 Comment(0)
L
1

This could be a problem with the settings for the Extension you are using.

You can uninstall and reinstall the GO Extension and see if it solves the problem.

Else another option is to edit the settings.json file under the settings icon for the GO Extension.

it will be usfull to variefy the GoRoot from terminal using,

$ go evnv 

and make sure its mentioned in the settings.json file, if not you need to copy the value under the tag GOROOT="/"

Then go back to the VS code Go Extension settings editor and add it to the following lines, *the settings.json editor can be found under the Edit in settings.json link, Under extension settings. *

{
    "window.zoomLevel": -3,
    "editor.tabCompletion": "on",
    "go.autocompleteUnimportedPackages": true,
    "go.installDependenciesWhenBuilding": true,
    "go.useCodeSnippetsOnFunctionSuggest": true,
    "go.useCodeSnippetsOnFunctionSuggestWithoutType": true,
    "go.formatTool": "gofmt",
    "go.gocodeAutoBuild": true,
    "go.useLanguageServer": true,
    "go.goroot": "/Your GoRoot Path",
    "go.delveConfig": {
    
    }
    
}

by setting up the following tags the issues will disappear,

    "go.autocompleteUnimportedPackages": true,
    "go.goroot": "/Your GoRoot Path",
    "editor.tabCompletion": "on",
    "go.useLanguageServer": true,

Hope this info helps.

Lecythus answered 8/7, 2022 at 12:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.