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

Compilation and intellisense for elsewhere declared variables and functions no longer works after a recent update. #2905

Closed
StephanVerbeeck opened this issue Nov 14, 2019 · 13 comments

Comments

@StephanVerbeeck
Copy link

StephanVerbeeck commented Nov 14, 2019

After [open folder] to edit a golang project directory: Variables and functions declare in another *.go source (with the same package in the same directory) are shown as compilation error "undeclared name: ___".

Resulting in +600 "so called" compilation errors while the same unchanged project compiled perfectly before the recent update.

[F12] (goto definition) is also not working because of this

Compilation is only possible by running "go build" in the terminal window or external command shell.

Version: 1.40.1 (user setup)
Commit: 8795a9889db74563ddd43eb0a897a2384129a619
Date: 2019-11-13T16:49:35.976Z
Electron: 6.1.2
Chrome: 76.0.3809.146
Node.js: 12.4.0
V8: 7.6.303.31-electron.0
OS: Windows_NT x64 10.0.18362

expected behavior: variables and functions defined in other *.go sources that are in the same directory and are also "package main" should be visible to the compiler and to intellisense.
Declarations in these other sources should have the same effect as a declaration in the currently being edited *.go source that is also "package main"

@ramya-rao-a
Copy link
Contributor

Please share any Go related settings you might have added/edited. You can get these by running the command Preferences: Open Settings(JSON)

@ramya-rao-a
Copy link
Contributor

ramya-rao-a commented Nov 15, 2019

You mentioned that the problem appears only after the recent update. Did you mean recent update of the extension or any of the Go tools?
If you meant the extension, then do you mind trying out the older version and confirming that it is indeed the latest version that has the problem?

You can get the older versions of the extensions from https://github.com/microsoft/vscode-go/releases

  • Download the corresponding vsix file
  • Run code --install-extension path-to-the-vsix-file
  • Reload VS Code

@StephanVerbeeck
Copy link
Author

I do not understand your reaction.
This error can be reproduced by anybody in a few seconds.
Why do you not simply try it????
The error is humongous and makes the product unusable (meaning total loss, meaning total broken).
Please take this serious and take prompt action accordingly.

@StephanVerbeeck
Copy link
Author

here below the requested content of settings.json

{
"window.zoomLevel": 1,
"workbench.sideBar.location": "right",
"workbench.statusBar.feedback.visible": false,
"editor.renderWhitespace": "none",
"breadcrumbs.enabled": true,
"files.autoSave": "afterDelay",
"C_Cpp.updateChannel": "Insiders",
"editor.renderControlCharacters": false,
"go.formatTool": "goimports",
"go.useLanguageServer": true,
"go.autocompleteUnimportedPackages": true,
"go.gocodeAutoBuild": true
}

@stamblerre
Copy link
Contributor

@StephanVerbeeck: It looks like you are using gopls, the Go language server. I recommend that you take a look at the recommended settings here, and see if adding any of these help.

Are you using Go modules or GOPATH mode? If you are using modules, make sure to open VS Code at the root of the module (the file containing the go.mod file) or in a subdirectory of the module. If you need to open multiple modules simultaneously, you should add them as workspace folders (File -> Add Folder to Workspace).

If none of this fixes the issue, please attach your gopls logs to this issue. You can find instructions on how to capture them here.

@StephanVerbeeck
Copy link
Author

I have temporarily bypassed the problem by not using gopls anymore.
The intellisense and goto-definition now works again.
It is probably something that can be fixed in gopls via settings but I have no time to investigate deeper at this moment in time.

-> https://github.com/golang/tools/blob/master/gopls/doc/user.md
(solved by changing "go.useLanguageServer": true, to "go.useLanguageServer": false, in settings.json)
-> https://github.com/golang/tools/blob/master/gopls/doc/troubleshooting.md

@KBassford
Copy link

KBassford commented Nov 20, 2019

Did not work for me. Intellisense still says "loading ...", go-lint not being picked up on saves, and I have this message:
"go: github.com/mjl-/[email protected] requires
9fans.net/[email protected]: invalid version: unknown revision 000000000000"
despite the fact that I don't use this library anywhere, anymore; and it's not in my vendor or Gopkg files.
(Note: this is under Linux (Debian))

@KBassford
Copy link

This might help ...
I had a similar problem, found that gopls check the "go.mod" file in the project. If the dependencies are out of sync, gopls fails. Try renaming your go.mod to something else, if you get your functionality back, problem solved.

@StephanVerbeeck
Copy link
Author

This might help ...
I had a similar problem, found that gopls check the "go.mod" file in the project. If the dependencies are out of sync, gopls fails. Try renaming your go.mod to something else, if you get your functionality back, problem solved.

I do not use .mod files. The sources are in the same project because they are in the same directory. That is exactly the beauty of GO (not having to deal with make files and such)

@stamblerre
Copy link
Contributor

I can help investigate gopls issues for those that are interested to do so.

@KBassford: You mentioned Gopkg files above, but you are also using modules? I would imagine that this might be related to the difficulties you encountered above.

@KBassford
Copy link

KBassford commented Nov 22, 2019

I generated both for backwards compatibility. I also have vendor folder as well.

@stamblerre
Copy link
Contributor

@KBassford: Replied on #2913. I think golang/go#31999 covers handling the types of issues that you encountered.

@vscodebot vscodebot bot closed this as completed Feb 14, 2020
@vscodebot
Copy link

vscodebot bot commented Feb 14, 2020

This issue has been closed automatically because it needs more information and has not had recent activity. Thank you for your contributions.

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

No branches or pull requests

4 participants