-
Notifications
You must be signed in to change notification settings - Fork 18k
x/tools/gopls: undeclared name when accessing symbols from other files #33107
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
Comments
Does the problem persist after you re-load the VSCode window? |
The problem disappears in the list, but as soon as I open that file back up
the issue comes back.
|
Removing since it only works temporarily and in some situations. |
I tried what you listed @peterfraedrich, but that didn't seem to work for me. |
This shouldn't be necessary - are either of you able to share your |
Here's some recent logs for gopls in VSCode (there's a lot, can provide more if you need it)
And the trace
|
having the same issue here too. |
@chodyo: Looks like the @ckim0419: Please provide logs so that I can help you debug. |
Thanks @stamblerre, that sounds consistent with what I've observed while using gopls. I think I've found the root of the problem. I have a folder/workspace open in VSCode that isn't the root of my project. My workspace is something like |
The workaround in #32394 fixed it for me.
Thank you! |
That worked for me too. Thank you @stamblerre |
I'm working with VSCode on Linux mint 19.2 with similar versions of go and gopls as in the first message in the thread. Whatever I do gopls give me the "undeclared name" error on a symbol that is defined in a different file, but in the same package. I don't get the error for symbols exported in other packages. Any ideas of how I can workaround it? |
@adir-ch: What is the output of |
My local problem solved! This is the gopls debug output:
No matter how I tried using VSCode (as single folder or as the root folder of a workspace) with the repo, I got the "undeclared name" error. Finally I've noticed in gopls logs shows the following errer: What I did to resolve it, was to install libc-dev (apt-get install libc-dev), and gopls was able to work properly! |
Glad to hear it! Thanks for sharing. @lumi-sch: Are you still seeing this issue? |
No, I've recently reset my PC and the issue didn't occur on the fresh install. |
Ok, glad to hear it. I’m going to close this issue- if anyone is still experiencing this, please open a new issue. |
same issue on mac , |
@fastfading: Please open a new issue, and please attach the information requested in the troubleshooting guide. |
thanks for the solution, same situation with you 😂 |
Yeap, same solution for me, thanks for sharing it... Could any of you tell me why that happens when we open the folder in the way the breaks gopls? |
|
I have a monorepo directory added to VSCode, with various sub-directories containing golang code and code in other languages. VSCode was not finding symbols in the same Golang package which are not in the same file. I ran this command in the root of the git repo, restarted VSCode, and the problem went away:
|
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
This is the latest release.
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
What did you expect to see?
Nothing. This code compiles without issues.
What did you see instead?
undeclared name: someFunc
Additional info
The issue occurs with variables, constants, functions and types. So basically everything.
The text was updated successfully, but these errors were encountered: