Skip to content
This repository was archived by the owner on Jul 15, 2023. It is now read-only.

Auto-complete didn't work before saving file with at least one time usage #2575

Closed
zulhfreelancer opened this issue Jun 14, 2019 · 11 comments
Closed
Labels
upstream-gopls Issue for gopls

Comments

@zulhfreelancer
Copy link

Hi,

I'm on OSX and currently using go1.11.4 darwin/amd64 with GO111MODULE is set to on. My VS Code editor version is 1.35.1 (c7d83e57cd18f18026a8162d042843bda1bcf21f) and here is my .zshrc content:

export GOPATH=/Users/zulh/go
export PATH=$GOPATH/bin:$PATH
export GO111MODULE=on

From what I noticed, the auto-complete is not working if I haven't use the package:

Screen Shot 2019-06-14 at 5 01 39 PM

After using a package and save the file, the auto-complete works:

Screen Shot 2019-06-14 at 5 02 20 PM

Note:

This main.go file is located in /Users/zulh/go/src/github.com/zulhfreelancer/go_parity_next_nonce

Here is the result for Go: Browse Packages:

Screen Shot 2019-06-14 at 5 02 39 PM

When I try to close the gocode, here is what I got:

$ gocode-gomod close
2019/06/14 17:13:18 dial unix /var/folders/qb/j82t6fhn56gd5qjmr6xwlxyc0000gn/T/gocode-gomod-daemon.zulh: connect: no such file or directory

$ gocode close
2019/06/14 17:13:26 dial unix /var/folders/qb/j82t6fhn56gd5qjmr6xwlxyc0000gn/T/gocode-daemon.zulh: connect: no such file or directory

When I run gocode-gomod -s -debug, nothing appears in my Terminal when I'm typing code in VS Code editor.

Here are my settings:

{

    "workbench.startupEditor": "newUntitledFile",
    "window.zoomLevel": 0,
    "workbench.statusBar.visible": true,
    "editor.minimap.enabled": true,
    "editor.renderWhitespace": "none",
    "editor.renderControlCharacters": false,
    "editor.fontSize": 14,
    "workbench.colorTheme": "One Dark Pro Vivid",
    "terminal.integrated.rendererType": "dom",
    "workbench.iconTheme": "vscode-icons",
    "sync.gist": "b098aaded0ef7d5274b0f1e482b97f4e",
    "sync.host": "",
    "sync.pathPrefix": "",
    "sync.quietSync": false,
    "sync.askGistName": false,
    "sync.removeExtensions": true,
    "sync.syncExtensions": true,
    "sync.autoDownload": false,
    "sync.autoUpload": false,
    "sync.lastUpload": "2018-08-23T10:56:18.264Z",
    "sync.lastDownload": "2018-08-13T17:46:45.531Z",
    "sync.forceDownload": false,
    "todohighlight.isEnable": true,
    "todohighlight.keywords": [
        {
            "text": "TODO",
            "color": "#000",
            "backgroundColor": "#f1c40f"
        }
    ],
    "explorer.confirmDragAndDrop": false,
    "extensions.ignoreRecommendations": true,
    "editor.wordWrap": "on",
    "files.insertFinalNewline": true,
    "emmet.includeLanguages": {
        "javascript": "javascriptreact",
        "vue-html": "html"
    },
    "go.useLanguageServer": true,
    "ruby.useLanguageServer": true,
    "go.enableCodeLens": {
        "references": false,
        "runtest": false
    },
    "go.autocompleteUnimportedPackages": true,
    "solidity.linter": "",
    "solidity.compileUsingRemoteVersion": "v0.4.25+commit.59dbf8f1",
    "ruby.intellisense": "rubyLocate",
    "git.path": "/usr/local/bin/git",
    "[go]": {
        "editor.formatOnSave": true,
        "editor.codeActionsOnSave": {
            "source.organizeImports": true
        }
    }
}

What should I do to make the auto-complete work before I import and save the package?

Thank you.

@ysantalla
Copy link

I have the same problem.

@ramya-rao-a
Copy link
Contributor

@zulhfreelancer It looks like you are using the language server, in this case gocode or gocode-mod are not used for the auto-completion feature. Instead, the language server is used.

The language server at the moment does not support the auto-completion feature for packages that haven't been imported yet.

@stamblerre Is there an issue tracking this for gopls?

@ramya-rao-a ramya-rao-a added the upstream-gopls Issue for gopls label Jun 15, 2019
@zulhfreelancer
Copy link
Author

Thank you for the respond @ramya-rao-a. How do I switch from language server to gocode or gocode-mod?

@ramya-rao-a
Copy link
Contributor

@zulhfreelancer Set go.useLanguageServer to false to stop using language server altogether or keep that to true and add the below to turn off just the completion feature from the language server

  "go.languageServerExperimentalFeatures": {
    "autoComplete": false
  }

Though, if you are using modules, we strongly suggest to use the language server as the back up tools are no longer under active development in favor of the language server

@stamblerre
Copy link
Contributor

The upstream issue is golang/go#31906.

@ramya-rao-a
Copy link
Contributor

ramya-rao-a commented Jun 18, 2019

@stamblerre golang/go#31906 is about getting the unimported packages themselves in the completion list, and then on completion, the import statement gets added automatically

This issue is that typing . after an unimported package, does not give completions for symbols from that package

@stamblerre
Copy link
Contributor

I think the two are effectively the same issue though. In the case that you type fmt. without importing "fmt", we will add the import statement if you select a completion.

@zulhfreelancer
Copy link
Author

zulhfreelancer commented Jun 18, 2019

@ramya-rao-a thank you. I can confirm it's working now after adding the snippet above. Since I'm using Go Modules, I'm keeping go.useLanguageServer to true.

Screen Shot 2019-06-18 at 12 39 07 PM

This is my full settings file content:

{

    "workbench.startupEditor": "newUntitledFile",
    "window.zoomLevel": 0,
    "workbench.statusBar.visible": true,
    "editor.minimap.enabled": false,
    "editor.renderWhitespace": "none",
    "editor.renderControlCharacters": false,
    "editor.fontSize": 14,
    "workbench.colorTheme": "One Dark Pro Vivid",
    "terminal.integrated.rendererType": "dom",
    "workbench.iconTheme": "vscode-icons",
    "sync.gist": "b098aaded0ef7d5274b0f1e482b97f4e",
    "sync.host": "",
    "sync.pathPrefix": "",
    "sync.quietSync": false,
    "sync.askGistName": false,
    "sync.removeExtensions": true,
    "sync.syncExtensions": true,
    "sync.autoDownload": false,
    "sync.autoUpload": false,
    "sync.lastUpload": "2018-08-23T10:56:18.264Z",
    "sync.lastDownload": "2018-08-13T17:46:45.531Z",
    "sync.forceDownload": false,
    "todohighlight.isEnable": true,
    "todohighlight.keywords": [
        {
            "text": "TODO",
            "color": "#000",
            "backgroundColor": "#f1c40f"
        }
    ],
    "explorer.confirmDragAndDrop": false,
    "extensions.ignoreRecommendations": true,
    "editor.wordWrap": "on",
    "files.insertFinalNewline": true,
    "emmet.includeLanguages": {
        "javascript": "javascriptreact",
        "vue-html": "html"
    },
    "go.useLanguageServer": true,
    "go.languageServerExperimentalFeatures": {
        "autoComplete": false
    },
    "ruby.useLanguageServer": true,
    "go.enableCodeLens": {
        "references": false,
        "runtest": false
    },
    "go.autocompleteUnimportedPackages": true,
    "solidity.linter": "",
    "solidity.compileUsingRemoteVersion": "v0.4.25+commit.59dbf8f1",
    "ruby.intellisense": "rubyLocate",
    "git.path": "/usr/local/bin/git",
    "[go]": {
        "editor.formatOnSave": true,
        "editor.codeActionsOnSave": {
            "source.organizeImports": true
        }
    },
    "breadcrumbs.enabled": false
}

@ramya-rao-a
Copy link
Contributor

I think the two are effectively the same issue though. In the case that you type fmt. without importing "fmt", we will add the import statement if you select a completion.

@stamblerre They are not the same

golang/go#31906 or at least the vscode-go issue it is referring to #2484 is about typing ti and getting time as a completion item.

This issue is about typing time. and getting all the symbols from the time package in the completion item list.

@stamblerre
Copy link
Contributor

Added a note to the issue. I think they will still be implemented effectively the same way, so that issue can cover both cases.

@stamblerre
Copy link
Contributor

@ramya-rao-a: golang/go#31906 is now closed, and unimported completions will be on by default for gopls/v0.3.0, so I think that this issue can be closed.

@vscodebot vscodebot bot locked and limited conversation to collaborators Mar 12, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
upstream-gopls Issue for gopls
Projects
None yet
Development

No branches or pull requests

4 participants