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: strange preselected completion for unimported package #62560

Closed
icholy opened this issue Sep 10, 2023 · 2 comments
Closed

x/tools/gopls: strange preselected completion for unimported package #62560

icholy opened this issue Sep 10, 2023 · 2 comments
Assignees
Labels
gopls/completion Issues related to auto-completion in gopls. gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@icholy
Copy link

icholy commented Sep 10, 2023

gopls version

golang.org/x/tools/gopls v0.13.2
    golang.org/x/tools/gopls@v0.13.2 h1:Pyvx6MKvatbX3zzZmdGiFRfQZl0ohPlt2sFxO/5j6Ro=

go env

GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/home/icholy/.cache/go-build'
GOENV='/home/icholy/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/home/icholy/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/icholy/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/local/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/local/go/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.21.0'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/tmp/scratch/go.mod'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build4199407928=/tmp/go-build -gno-record-gcc-switches'

What did you do?

package main

import _ "github.com/aws/aws-sdk-go-v2/service/codebuild"

func main() {
	json.U // <- trigger completion here
}

What did you expect to see?

Suggest json.Unmarshal as pre-selected completion.

What did you see instead?

json.InvalidUTF8Error as pre-selected completion.

image

Editor and settings

I'm using neovim's built-in lsp client. However, I was able to reproduce this in a vanilla VSCode install with only the Go plugin installed.

Here's the completion response neovim is getting:

{
    id = 10,
    jsonrpc = "2.0",
    result = {
        isIncomplete = true,
        items = {
            {
                additionalTextEdits = {
                    {
                        newText = '"\n\t"encoding/json',
                        range = {["end"] = {character = 9, line = 3}, start = {character = 9, line = 3}}
                    }
                },
                detail = 'type (from "encoding/json")',
                documentation = {kind = "markdown", value = ""},
                filterText = "InvalidUTF8Error",
                insertTextFormat = 2,
                kind = 7,
                label = "InvalidUTF8Error",
                preselect = true,
                sortText = "00000",
                textEdit = {
                    newText = "InvalidUTF8Error",
                    range = {["end"] = {character = 7, line = 20}, start = {character = 6, line = 20}}
                }
            },
            {
                additionalTextEdits = {
                    {
                        newText = '"\n\t"encoding/json',
                        range = {["end"] = {character = 9, line = 3}, start = {character = 9, line = 3}}
                    }
                },
                detail = 'type (from "encoding/json")',
                documentation = {kind = "markdown", value = ""},
                filterText = "InvalidUnmarshalError",
                insertTextFormat = 2,
                kind = 7,
                label = "InvalidUnmarshalError",
                sortText = "00001",
                textEdit = {
                    newText = "InvalidUnmarshalError",
                    range = {["end"] = {character = 7, line = 20}, start = {character = 6, line = 20}}
                }
            },
            {
                additionalTextEdits = {
                    {
                        newText = '"\n\t"encoding/json',
                        range = {["end"] = {character = 9, line = 3}, start = {character = 9, line = 3}}
                    }
                },
                detail = 'func (from "encoding/json")',
                documentation = {kind = "markdown", value = ""},
                filterText = "Unmarshal",
                insertTextFormat = 2,
                kind = 3,
                label = "Unmarshal",
                sortText = "00002",
                textEdit = {
                    newText = "Unmarshal(data, v)",
                    range = {["end"] = {character = 7, line = 20}, start = {character = 6, line = 20}}
                }
            },
            {
                additionalTextEdits = {
                    {
                        newText = '"\n\t"encoding/json',
                        range = {["end"] = {character = 9, line = 3}, start = {character = 9, line = 3}}
                    }
                },
                detail = 'type (from "encoding/json")',
                documentation = {kind = "markdown", value = ""},
                filterText = "UnmarshalFieldError",
                insertTextFormat = 2,
                kind = 7,
                label = "UnmarshalFieldError",
                sortText = "00003",
                textEdit = {
                    newText = "UnmarshalFieldError",
                    range = {["end"] = {character = 7, line = 20}, start = {character = 6, line = 20}}
                }
            },
            {
                additionalTextEdits = {
                    {
                        newText = '"\n\t"encoding/json',
                        range = {["end"] = {character = 9, line = 3}, start = {character = 9, line = 3}}
                    }
                },
                detail = 'type (from "encoding/json")',
                documentation = {kind = "markdown", value = ""},
                filterText = "UnmarshalTypeError",
                insertTextFormat = 2,
                kind = 7,
                label = "UnmarshalTypeError",
                sortText = "00004",
                textEdit = {
                    newText = "UnmarshalTypeError",
                    range = {["end"] = {character = 7, line = 20}, start = {character = 6, line = 20}}
                }
            },
            {
                additionalTextEdits = {
                    {
                        newText = '"\n\t"encoding/json',
                        range = {["end"] = {character = 9, line = 3}, start = {character = 9, line = 3}}
                    }
                },
                detail = 'type (from "encoding/json")',
                documentation = {kind = "markdown", value = ""},
                filterText = "Unmarshaler",
                insertTextFormat = 2,
                kind = 7,
                label = "Unmarshaler",
                sortText = "00005",
                textEdit = {
                    newText = "Unmarshaler",
                    range = {["end"] = {character = 7, line = 20}, start = {character = 6, line = 20}}
                }
            },
            {
                additionalTextEdits = {
                    {
                        newText = '"\n\t"encoding/json',
                        range = {["end"] = {character = 9, line = 3}, start = {character = 9, line = 3}}
                    }
                },
                detail = 'type (from "encoding/json")',
                documentation = {kind = "markdown", value = ""},
                filterText = "UnsupportedTypeError",
                insertTextFormat = 2,
                kind = 7,
                label = "UnsupportedTypeError",
                sortText = "00006",
                textEdit = {
                    newText = "UnsupportedTypeError",
                    range = {["end"] = {character = 7, line = 20}, start = {character = 6, line = 20}}
                }
            },
            {
                additionalTextEdits = {
                    {
                        newText = '"\n\t"encoding/json',
                        range = {["end"] = {character = 9, line = 3}, start = {character = 9, line = 3}}
                    }
                },
                detail = 'type (from "encoding/json")',
                documentation = {kind = "markdown", value = ""},
                filterText = "UnsupportedValueError",
                insertTextFormat = 2,
                kind = 7,
                label = "UnsupportedValueError",
                sortText = "00007",
                textEdit = {
                    newText = "UnsupportedValueError",
                    range = {["end"] = {character = 7, line = 20}, start = {character = 6, line = 20}}
                }
            },
            {
                additionalTextEdits = {
                    {
                        newText = '"\n\t"github.com/aws/smithy-go/encoding/json',
                        range = {["end"] = {character = 51, line = 9}, start = {character = 51, line = 9}}
                    }
                },
                detail = 'func (from "github.com/aws/smithy-go/encoding/json")',
                documentation = {kind = "markdown", value = ""},
                filterText = "CollectUnknownField",
                insertTextFormat = 2,
                kind = 3,
                label = "CollectUnknownField",
                sortText = "00008",
                textEdit = {
                    newText = "CollectUnknownField(decoder)",
                    range = {["end"] = {character = 7, line = 20}, start = {character = 6, line = 20}}
                }
            },
            {
                additionalTextEdits = {
                    {
                        newText = '"\n\t"github.com/aws/smithy-go/encoding/json',
                        range = {["end"] = {character = 51, line = 9}, start = {character = 51, line = 9}}
                    }
                },
                detail = 'func (from "github.com/aws/smithy-go/encoding/json")',
                documentation = {kind = "markdown", value = ""},
                filterText = "DiscardUnknownField",
                insertTextFormat = 2,
                kind = 3,
                label = "DiscardUnknownField",
                sortText = "00009",
                textEdit = {
                    newText = "DiscardUnknownField(decoder)",
                    range = {["end"] = {character = 7, line = 20}, start = {character = 6, line = 20}}
                }
            },
            {
                additionalTextEdits = {
                    {
                        newText = '"\n\t"github.com/segmentio/encoding/json',
                        range = {["end"] = {character = 51, line = 9}, start = {character = 51, line = 9}}
                    }
                },
                detail = '(from "github.com/segmentio/encoding/json")',
                documentation = {kind = "markdown", value = ""},
                filterText = "Uint",
                insertTextFormat = 2,
                kind = 6,
                label = "Uint",
                sortText = "00010",
                textEdit = {
                    newText = "Uint",
                    range = {["end"] = {character = 7, line = 20}, start = {character = 6, line = 20}}
                }
            },
            {
                additionalTextEdits = {
                    {
                        newText = '"\n\t"github.com/segmentio/encoding/json',
                        range = {["end"] = {character = 51, line = 9}, start = {character = 51, line = 9}}
                    }
                },
                detail = '(from "github.com/segmentio/encoding/json")',
                documentation = {kind = "markdown", value = ""},
                filterText = "Undefined",
                insertTextFormat = 2,
                kind = 6,
                label = "Undefined",
                sortText = "00011",
                textEdit = {
                    newText = "Undefined",
                    range = {["end"] = {character = 7, line = 20}, start = {character = 6, line = 20}}
                }
            },
            {
                additionalTextEdits = {
                    {
                        newText = '"\n\t"github.com/segmentio/encoding/json',
                        range = {["end"] = {character = 51, line = 9}, start = {character = 51, line = 9}}
                    }
                },
                detail = '(from "github.com/segmentio/encoding/json")',
                documentation = {kind = "markdown", value = ""},
                filterText = "Unescape",
                insertTextFormat = 2,
                kind = 6,
                label = "Unescape",
                sortText = "00012",
                textEdit = {
                    newText = "Unescape",
                    range = {["end"] = {character = 7, line = 20}, start = {character = 6, line = 20}}
                }
            },
            {
                additionalTextEdits = {
                    {
                        newText = '"\n\t"github.com/segmentio/encoding/json',
                        range = {["end"] = {character = 51, line = 9}, start = {character = 51, line = 9}}
                    }
                },
                detail = '(from "github.com/segmentio/encoding/json")',
                documentation = {kind = "markdown", value = ""},
                filterText = "Unescaped",
                insertTextFormat = 2,
                kind = 6,
                label = "Unescaped",
                sortText = "00013",
                textEdit = {
                    newText = "Unescaped",
                    range = {["end"] = {character = 7, line = 20}, start = {character = 6, line = 20}}
                }
            },
            {
                additionalTextEdits = {
                    {
                        newText = '"\n\t"github.com/segmentio/encoding/json',
                        range = {["end"] = {character = 51, line = 9}, start = {character = 51, line = 9}}
                    }
                },
                detail = '(from "github.com/segmentio/encoding/json")',
                documentation = {kind = "markdown", value = ""},
                filterText = "Unmarshal",
                insertTextFormat = 2,
                kind = 6,
                label = "Unmarshal",
                sortText = "00014",
                textEdit = {
                    newText = "Unmarshal",
                    range = {["end"] = {character = 7, line = 20}, start = {character = 6, line = 20}}
                }
            },
            {
                additionalTextEdits = {
                    {
                        newText = '"\n\t"github.com/segmentio/encoding/json',
                        range = {["end"] = {character = 51, line = 9}, start = {character = 51, line = 9}}
                    }
                },
                detail = '(from "github.com/segmentio/encoding/json")',
                documentation = {kind = "markdown", value = ""},
                filterText = "UnmarshalFieldError",
                insertTextFormat = 2,
                kind = 6,
                label = "UnmarshalFieldError",
                sortText = "00015",
                textEdit = {
                    newText = "UnmarshalFieldError",
                    range = {["end"] = {character = 7, line = 20}, start = {character = 6, line = 20}}
                }
            },
            {
                additionalTextEdits = {
                    {
                        newText = '"\n\t"github.com/segmentio/encoding/json',
                        range = {["end"] = {character = 51, line = 9}, start = {character = 51, line = 9}}
                    }
                },
                detail = '(from "github.com/segmentio/encoding/json")',
                documentation = {kind = "markdown", value = ""},
                filterText = "UnmarshalTypeError",
                insertTextFormat = 2,
                kind = 6,
                label = "UnmarshalTypeError",
                sortText = "00016",
                textEdit = {
                    newText = "UnmarshalTypeError",
                    range = {["end"] = {character = 7, line = 20}, start = {character = 6, line = 20}}
                }
            },
            {
                additionalTextEdits = {
                    {
                        newText = '"\n\t"github.com/segmentio/encoding/json',
                        range = {["end"] = {character = 51, line = 9}, start = {character = 51, line = 9}}
                    }
                },
                detail = '(from "github.com/segmentio/encoding/json")',
                documentation = {kind = "markdown", value = ""},
                filterText = "Unmarshaler",
                insertTextFormat = 2,
                kind = 6,
                label = "Unmarshaler",
                sortText = "00017",
                textEdit = {
                    newText = "Unmarshaler",
                    range = {["end"] = {character = 7, line = 20}, start = {character = 6, line = 20}}
                }
            },
            {
                additionalTextEdits = {
                    {
                        newText = '"\n\t"github.com/segmentio/encoding/json',
                        range = {["end"] = {character = 51, line = 9}, start = {character = 51, line = 9}}
                    }
                },
                detail = '(from "github.com/segmentio/encoding/json")',
                documentation = {kind = "markdown", value = ""},
                filterText = "UnsupportedTypeError",
                insertTextFormat = 2,
                kind = 6,
                label = "UnsupportedTypeError",
                sortText = "00018",
                textEdit = {
                    newText = "UnsupportedTypeError",
                    range = {["end"] = {character = 7, line = 20}, start = {character = 6, line = 20}}
                }
            },
            {
                additionalTextEdits = {
                    {
                        newText = '"\n\t"github.com/segmentio/encoding/json',
                        range = {["end"] = {character = 51, line = 9}, start = {character = 51, line = 9}}
                    }
                },
                detail = '(from "github.com/segmentio/encoding/json")',
                documentation = {kind = "markdown", value = ""},
                filterText = "UnsupportedValueError",
                insertTextFormat = 2,
                kind = 6,
                label = "UnsupportedValueError",
                sortText = "00019",
                textEdit = {
                    newText = "UnsupportedValueError",
                    range = {["end"] = {character = 7, line = 20}, start = {character = 6, line = 20}}
                }
            },
            {
                additionalTextEdits = {
                    {
                        newText = '"\n\t"github.com/segmentio/encoding/json',
                        range = {["end"] = {character = 51, line = 9}, start = {character = 51, line = 9}}
                    }
                },
                detail = '(from "github.com/segmentio/encoding/json")',
                documentation = {kind = "markdown", value = ""},
                filterText = "UseNumber",
                insertTextFormat = 2,
                kind = 6,
                label = "UseNumber",
                sortText = "00020",
                textEdit = {
                    newText = "UseNumber",
                    range = {["end"] = {character = 7, line = 20}, start = {character = 6, line = 20}}
                }
            },
            {
                additionalTextEdits = {
                    {
                        newText = '"\n\t"github.com/segmentio/encoding/json',
                        range = {["end"] = {character = 51, line = 9}, start = {character = 51, line = 9}}
                    }
                },
                detail = '(from "github.com/segmentio/encoding/json")',
                documentation = {kind = "markdown", value = ""},
                filterText = "AppendUnescape",
                insertTextFormat = 2,
                kind = 6,
                label = "AppendUnescape",
                sortText = "00021",
                textEdit = {
                    newText = "AppendUnescape",
                    range = {["end"] = {character = 7, line = 20}, start = {character = 6, line = 20}}
                }
            },
            {
                additionalTextEdits = {
                    {
                        newText = '"\n\t"github.com/segmentio/encoding/json',
                        range = {["end"] = {character = 51, line = 9}, start = {character = 51, line = 9}}
                    }
                },
                detail = '(from "github.com/segmentio/encoding/json")',
                documentation = {kind = "markdown", value = ""},
                filterText = "DisallowUnknownFields",
                insertTextFormat = 2,
                kind = 6,
                label = "DisallowUnknownFields",
                sortText = "00022",
                textEdit = {
                    newText = "DisallowUnknownFields",
                    range = {["end"] = {character = 7, line = 20}, start = {character = 6, line = 20}}
                }
            },
            {
                additionalTextEdits = {
                    {
                        newText = '"\n\t"github.com/segmentio/encoding/json',
                        range = {["end"] = {character = 51, line = 9}, start = {character = 51, line = 9}}
                    }
                },
                detail = '(from "github.com/segmentio/encoding/json")',
                documentation = {kind = "markdown", value = ""},
                filterText = "InvalidUTF8Error",
                insertTextFormat = 2,
                kind = 6,
                label = "InvalidUTF8Error",
                sortText = "00023",
                textEdit = {
                    newText = "InvalidUTF8Error",
                    range = {["end"] = {character = 7, line = 20}, start = {character = 6, line = 20}}
                }
            },
            {
                additionalTextEdits = {
                    {
                        newText = '"\n\t"github.com/segmentio/encoding/json',
                        range = {["end"] = {character = 51, line = 9}, start = {character = 51, line = 9}}
                    }
                },
                detail = '(from "github.com/segmentio/encoding/json")',
                documentation = {kind = "markdown", value = ""},
                filterText = "InvalidUnmarshalError",
                insertTextFormat = 2,
                kind = 6,
                label = "InvalidUnmarshalError",
                sortText = "00024",
                textEdit = {
                    newText = "InvalidUnmarshalError",
                    range = {["end"] = {character = 7, line = 20}, start = {character = 6, line = 20}}
                }
            }
        }
    }
}
@icholy icholy added gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository. labels Sep 10, 2023
@gopherbot gopherbot added this to the Unreleased milestone Sep 10, 2023
@findleyr findleyr added the gopls/completion Issues related to auto-completion in gopls. label Sep 18, 2023
@findleyr
Copy link
Contributor

Thanks for the report. I agree this is not correct, and will fix it. Coincidentally, I plan to work on unimported completion this week for #62665 (comment). I expect that there is also missing scoring logic, causing this bug, and I'll fix that if I can.

@findleyr findleyr modified the milestones: Unreleased, gopls/v0.14.0 Sep 18, 2023
@gopherbot
Copy link

Change https://go.dev/cl/531418 mentions this issue: gopls/internal/lsp: use matcher score in ranking unimported candidates

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
gopls/completion Issues related to auto-completion in gopls. gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

3 participants