Skip to content

x/tools/gopls: Completion: "unexpected surrounding: %q != %q" bug in collectCompletions #75192

@adonovan

Description

@adonovan
#!stacks
"bug.Reportf" && "completion.(*completer).selector:+57"

Issue created by stacks.

	// -- completion of symbols in unimported packages --

	// use new code for unimported completions, if flag allows it
	if c.snapshot.Options().ImportsSource == settings.ImportsSourceGopls {
		// The user might have typed strings.TLower, so id.Name==strings, sel.Sel.Name == TLower,
		// but the cursor might be inside TLower, so adjust the prefix
		prefix := sel.Sel.Name
		if c.surrounding != nil {
			if c.surrounding.content != sel.Sel.Name {
				bug.Reportf("unexpected surrounding: %q != %q", c.surrounding.content, sel.Sel.Name)
			} else {
				prefix = sel.Sel.Name[:c.surrounding.cursor-c.surrounding.start]
			}
		}
		c.unimported(ctx, metadata.PackageName(id.Name), prefix)
		return nil

	}

Possible regression in https://go.dev/cl/667576?

This stack _bvZaw was reported by telemetry:

golang.org/x/tools/[email protected] go1.25.0 darwin/arm64 vscode (1)

Dups: BjtwIw 8lB0bg aoE2jw

Metadata

Metadata

Assignees

Labels

BugReportIssues describing a possible bug in the Go implementation.NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.ToolsThis label describes issues relating to any tools in the x/tools repository.goplsIssues related to the Go language server, gopls.gopls/telemetry-wins

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions