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: fully qualify symbol names for Symbol #38273

Open
myitcv opened this issue Apr 6, 2020 · 1 comment
Open

x/tools/gopls: fully qualify symbol names for Symbol #38273

myitcv opened this issue Apr 6, 2020 · 1 comment

Comments

@myitcv
Copy link
Member

@myitcv myitcv commented Apr 6, 2020

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

$ go version
go version devel +801cd7c84d Thu Apr 2 09:00:44 2020 +0000 linux/amd64
$ go list -m golang.org/x/tools
golang.org/x/tools v0.0.0-20200402175326-9fc00b0a7ff6
$ go list -m golang.org/x/tools/gopls
golang.org/x/tools/gopls v0.1.8-0.20200402175326-9fc00b0a7ff6

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=""
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/.vim/plugged/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-build616148717=/tmp/go-build -gno-record-gcc-switches"

What did you do?

This request complements/is complemented by #37237.

Currently the workspace symbol method performs a case-insensitive search on a symbol by its name only, rather than the fully qualified path. Furthermore it returns only this name in the Name field of a SymbolInformation struct.

Consider the following cut-down example:

-- go.mod --
module github.com/myitcv/playground

go 1.12
-- main.go --
package main

import (
	"fmt"

	"github.com/myitcv/playground/p"
)

const name = "main"

func main() {
	fmt.Println(name, p.Name)
}
-- p/p.go --
package p

const Name = "p"

A symbol search for "na" returns:

[]protocol.SymbolInformation{
    {
        Name:       "name",
        Kind:       14,
        Tags:       nil,
        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:6},
                End:   protocol.Position{Line:8, Character:10},
            },
        },
        ContainerName: "",
    },
    {
        Name:       "Name",
        Kind:       14,
        Tags:       nil,
        Deprecated: false,
        Location:   protocol.Location{
            URI:   "file:///home/myitcv/gostuff/src/github.com/myitcv/playground/p/p.go",
            Range: protocol.Range{
                Start: protocol.Position{Line:2, Character:6},
                End:   protocol.Position{Line:2, Character:10},
            },
        },
        ContainerName: "",
    },
    ....

What did you expect to see?

  • matches to be performed against the fully qualified symbols, e.g. github.com/myitcv/playground.name and github.com/myitcv/playground/p.Name
  • matches to be fuzzy matches that understand the nature of / and ., e.g. "p.na" would only return results in a package which fuzzy matches "p" and where the symbol within those packages fuzzy matches "na"
  • the fully qualified symbol to be returned in the SymbolInformation.Name field

A further question is how the type of a symbol can be returned as part of a match; whilst this should likely not play a part in the match, it is relevant in the presentation of results.

What did you see instead?

Per above


cc @stamblerre @findleyr

FYI @leitzler

@gopherbot
Copy link

@gopherbot gopherbot commented Apr 8, 2020

Change https://golang.org/cl/227677 mentions this issue: internal/lsp: first cut of advanced query syntax for WorkspaceSymbol

myitcv added a commit to myitcvforks/tools that referenced this issue Apr 8, 2020
DO NOT REVIEW
DO NOT SUBMIT

* Add config option for SymbolMatcher
* Fully qualify symbols and match against fully-qualified symbol
* Define and implement workspaceOnly and nonWorkspaceExportedOnly search
  options

Fixes golang/go#38273
Updates golang/go#37237

Change-Id: Ie58ae992bf2d22673c3daa2c495c15279a1fa54b
myitcv added a commit to myitcvforks/tools that referenced this issue Apr 8, 2020
DO NOT REVIEW
DO NOT SUBMIT

* Add config option for SymbolMatcher
* Fully qualify symbols and match against fully-qualified symbol
* Define and implement workspaceOnly and nonWorkspaceExportedOnly search
  options

Fixes golang/go#38273
Updates golang/go#37237

Change-Id: Ie58ae992bf2d22673c3daa2c495c15279a1fa54b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.