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: could not import local package #46584

Closed
2435043xia opened this issue Jun 5, 2021 · 3 comments
Closed

x/tools/gopls: could not import local package #46584

2435043xia opened this issue Jun 5, 2021 · 3 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. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.

Comments

@2435043xia
Copy link

2435043xia commented Jun 5, 2021

1.project can be built successfully,it's work.
2.vscode(or gopls) show errors 'could not import **** package'
3.Goland will not have this problem, But I want to use vscode remote

The project structure is as follows:

Assume modName is MyProject

  • GoPath
  • src
    • MyProject ----- open project
      • go.mod
      • cmd
        • package1
          • main.go // import "MyProject/internal/package1"
      • internal
        • package1
          • goFiles ---- import "MyProject/internal/package2" //show errors
        • package2
          • goFiles

What should I change to let the error go away?

@gopherbot gopherbot added the gopls Issues related to the Go language server, gopls. label Jun 5, 2021
@seankhliao seankhliao changed the title vscode(or gopls) open golang project,Could not import local package x/tools/gopls: could not import local package Jun 5, 2021
@gopherbot gopherbot added the Tools This label describes issues relating to any tools in the x/tools repository. label Jun 5, 2021
@gopherbot gopherbot added this to the Unreleased milestone Jun 5, 2021
@findleyr
Copy link
Contributor

findleyr commented Jun 5, 2021

Hi, I am assuming that the GoPath directory is part of your GOPATH. In that case, it looks like the code is not in GoPath/src. Per go help gopath:

The src directory holds source code. The path below src
determines the import path or executable name.
...
If DIR is a directory listed in the GOPATH, a package with
source in DIR/src/foo/bar can be imported as "foo/bar" and

However, you report that your build succeeds from the command line. Could you share:

  • what specific command succeeds, when run from which directory?
  • do you have a go.mod file in your project?

Thanks

@findleyr findleyr added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Jun 5, 2021
@findleyr findleyr modified the milestones: Unreleased, gopls/unplanned Jun 5, 2021
@2435043xia
Copy link
Author

Hi, I am assuming that the GoPath directory is part of your GOPATH. In that case, it looks like the code is not in GoPath/src. Per go help gopath:

The src directory holds source code. The path below src
determines the import path or executable name.
...
If DIR is a directory listed in the GOPATH, a package with
source in DIR/src/foo/bar can be imported as "foo/bar" and

However, you report that your build succeeds from the command line. Could you share:

  • what specific command succeeds, when run from which directory?
  • do you have a go.mod file in your project?

Thanks

My issue description is wrong,i have updated it.

1.I run "go build cmd/package1/main.go" in "MyProject" directory. The project is indeed under GOPATH/src
2.yes,i have go.mod.

@2435043xia
Copy link
Author

Hi, I am assuming that the GoPath directory is part of your GOPATH. In that case, it looks like the code is not in GoPath/src. Per go help gopath:

The src directory holds source code. The path below src
determines the import path or executable name.
...
If DIR is a directory listed in the GOPATH, a package with
source in DIR/src/foo/bar can be imported as "foo/bar" and

However, you report that your build succeeds from the command line. Could you share:

  • what specific command succeeds, when run from which directory?
  • do you have a go.mod file in your project?

Thanks

I just tried to reproduce it with a new project, I failed.
I guess that there is a problem with my environment.This makes me very confused.
Thank you for your help. I will try to fix my environment

@stamblerre stamblerre removed this from the gopls/unplanned milestone Jun 7, 2021
@golang golang locked and limited conversation to collaborators Jun 7, 2022
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. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

4 participants