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: symbol returns matches from outside the workspace #37236

Open
myitcv opened this issue Feb 15, 2020 · 3 comments
Open

x/tools/gopls: symbol returns matches from outside the workspace #37236

myitcv opened this issue Feb 15, 2020 · 3 comments
Labels
gopls Issues related to the Go language server, gopls. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@myitcv
Copy link
Member

myitcv commented Feb 15, 2020

What version of Go are you using (go version)?

$ go version
go version devel +b7689f5aa3 Fri Jan 31 06:02:00 2020 +0000 linux/amd64
$ go list -m golang.org/x/tools
golang.org/x/tools v0.0.0-20200214144324-88be01311a71
$ go list -m golang.org/x/tools/gopls
golang.org/x/tools/gopls v0.1.8-0.20200214144324-88be01311a71

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/myitcv/.cache/go-build"
GOENV="/home/myitcv/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/myitcv/gostuff"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/home/myitcv/gos"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/home/myitcv/gos/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/myitcv/gostuff/src/github.com/myitcv/govim/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build235629906=/tmp/go-build -gno-record-gcc-switches"

What did you do?

With the following setup:

-- main.go --
package main

import (
	"fmt"

	"golang.org/x/tools/imports"
)

func main() {
	fmt.Println(imports.LocalPrefix)
}
-- go.mod --
module github.com/myitcv/playground

go 1.12

require golang.org/x/tools v0.0.0-20200214191634-99763790079f

Called 'Symbol' with a query of "main"

What did you expect to see?

A single result: the main function defined in main; because the workspace scope is defined (I think) as the main module.

What did you see instead?

Lots of results from outside the workspace (main module) within dependencies:

gopls.Symbol() return; err: <nil>; res:
[]protocol.SymbolInformation{
    {
        Name:       "main",
        Kind:       12,
        Deprecated: false,
        Location:   protocol.Location{
            URI:   "file:///home/myitcv/gostuff/src/github.com/myitcv/playground/main.go",
            Range: protocol.Range{
                Start: protocol.Position{Line:8, Character:5},
                End:   protocol.Position{Line:8, Character:9},
            },
        },
        ContainerName: "",
    },
    {
        Name:       "Remainder",
        Kind:       12,
        Deprecated: false,
        Location:   protocol.Location{
            URI:   "file:///home/myitcv/gos/src/math/remainder.go",
            Range: protocol.Range{
                Start: protocol.Position{Line:36, Character:5},
                End:   protocol.Position{Line:36, Character:14},
            },
        },
        ContainerName: "",
    },
    {
        Name:       "remainder",
        Kind:       12,
        Deprecated: false,
        Location:   protocol.Location{
            URI:   "file:///home/myitcv/gos/src/math/remainder.go",
            Range: protocol.Range{
                Start: protocol.Position{Line:38, Character:5},
                End:   protocol.Position{Line:38, Character:14},
            },
        },
        ContainerName: "",
    },
    {
        Name:       "main",
        Kind:       8,
        Deprecated: false,
        Location:   protocol.Location{
            URI:   "file:///home/myitcv/gostuff/pkg/mod/golang.org/x/tools@v0.0.0-20200214191634-99763790079f/internal/imports/mod.go",
            Range: protocol.Range{
                Start: protocol.Position{Line:32, Character:1},
                End:   protocol.Position{Line:32, Character:5},
            },
        },
        ContainerName: "",
    },
    {
        Name:       "domainname",
        Kind:       8,
        Deprecated: false,
        Location:   protocol.Location{
            URI:   "file:///home/myitcv/gos/src/runtime/defs_linux_amd64.go",
            Range: protocol.Range{
                Start: protocol.Position{Line:274, Character:1},
                End:   protocol.Position{Line:274, Character:11},
            },
        },
        ContainerName: "",
    },
    {
        Name:       "main_inittask",
        Kind:       13,
        Deprecated: false,
        Location:   protocol.Location{
            URI:   "file:///home/myitcv/gos/src/runtime/proc.go",
            Range: protocol.Range{
                Start: protocol.Position{Line:91, Character:4},
                End:   protocol.Position{Line:91, Character:17},
            },
        },
        ContainerName: "",
    },
    {
        Name:       "main_init_done",
        Kind:       13,
        Deprecated: false,
        Location:   protocol.Location{
            URI:   "file:///home/myitcv/gos/src/runtime/proc.go",
            Range: protocol.Range{
                Start: protocol.Position{Line:97, Character:4},
                End:   protocol.Position{Line:97, Character:18},
            },
        },
        ContainerName: "",
    },
    {
        Name:       "main_main",
        Kind:       12,
        Deprecated: false,
        Location:   protocol.Location{
            URI:   "file:///home/myitcv/gos/src/runtime/proc.go",
            Range: protocol.Range{
                Start: protocol.Position{Line:100, Character:5},
                End:   protocol.Position{Line:100, Character:14},
            },
        },
        ContainerName: "",
    },
    {
        Name:       "mainStarted",
        Kind:       13,
        Deprecated: false,
        Location:   protocol.Location{
            URI:   "file:///home/myitcv/gos/src/runtime/proc.go",
            Range: protocol.Range{
                Start: protocol.Position{Line:103, Character:4},
                End:   protocol.Position{Line:103, Character:15},
            },
        },
        ContainerName: "",
    },
    {
        Name:       "main",
        Kind:       12,
        Deprecated: false,
        Location:   protocol.Location{
            URI:   "file:///home/myitcv/gos/src/runtime/proc.go",
            Range: protocol.Range{
                Start: protocol.Position{Line:112, Character:5},
                End:   protocol.Position{Line:112, Character:9},
            },
        },
        ContainerName: "",
    },
    {
        Name:       "funcID_runtime_main",
        Kind:       14,
        Deprecated: false,
        Location:   protocol.Location{
            URI:   "file:///home/myitcv/gos/src/runtime/symtab.go",
            Range: protocol.Range{
                Start: protocol.Position{Line:237, Character:1},
                End:   protocol.Position{Line:237, Character:20},
            },
        },
        ContainerName: "",
    },
    {
        Name:       "hasmain",
        Kind:       8,
        Deprecated: false,
        Location:   protocol.Location{
            URI:   "file:///home/myitcv/gos/src/runtime/symtab.go",
            Range: protocol.Range{
                Start: protocol.Position{Line:293, Character:1},
                End:   protocol.Position{Line:293, Character:8},
            },
        },
        ContainerName: "",
    },
    {
        Name:       "Setdomainname",
        Kind:       12,
        Deprecated: false,
        Location:   protocol.Location{
            URI:   "file:///home/myitcv/gos/src/syscall/zsyscall_linux_amd64.go",
            Range: protocol.Range{
                Start: protocol.Position{Line:715, Character:5},
                End:   protocol.Position{Line:715, Character:18},
            },
        },
        ContainerName: "",
    },
    {
        Name:       "Domainname",
        Kind:       8,
        Deprecated: false,
        Location:   protocol.Location{
            URI:   "file:///home/myitcv/gos/src/syscall/ztypes_linux_amd64.go",
            Range: protocol.Range{
                Start: protocol.Position{Line:574, Character:1},
                End:   protocol.Position{Line:574, Character:11},
            },
        },
        ContainerName: "",
    },
}

cc @stamblerre

FYI @leitzler

@myitcv myitcv added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. gopls Issues related to the Go language server, gopls. labels Feb 15, 2020
@gopherbot gopherbot added this to the Unreleased milestone Feb 15, 2020
@gopherbot gopherbot added the Tools This label describes issues relating to any tools in the x/tools repository. label Feb 15, 2020
@stamblerre
Copy link
Contributor

This is intentional - I think it's useful to be able to go to the a symbol in a dependency of your workspace packages. Is there a particular reason you would want to remove this behavior?

@stamblerre stamblerre modified the milestones: Unreleased, gopls/v1.0.0 Feb 18, 2020
@myitcv
Copy link
Member Author

myitcv commented Feb 19, 2020

Is there a particular reason you would want to remove this behavior

The only reason I questioned whether this was the intended behaviour or not is the discrepancy, under a very strict reading at least, between the fact the method is defined as returning workspace symbols but in fact returns symbols from outside the workspace.

If this is working as intended that's absolutely fine (and in many respects better). I'll add another comment to #37237 to also request a module scope.

@myitcv myitcv closed this as completed Feb 19, 2020
@stamblerre stamblerre modified the milestones: gopls/v1.0.0, gopls/v0.4.0 Jul 22, 2020
@golang golang locked and limited conversation to collaborators Jul 22, 2021
@findleyr
Copy link
Contributor

This has come up a few times. Several users do not like seeing results outside their workspace.

Given that this is a superficial change, I would not be opposed to adding e.g. a "symbolScope" setting that alters this behavior.

@findleyr findleyr reopened this Jan 26, 2023
@findleyr findleyr modified the milestones: gopls/v0.4.0, gopls/later Jan 26, 2023
@golang golang unlocked this conversation Jan 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
gopls Issues related to the Go language server, gopls. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

4 participants