Skip to content

x/tools/gopls: Add a gopls command for resolving targets to locations. #80874

Description

@aputman

This can be read more about in go.dev/cl/768861 (I'll update this to doc once that cl is submitted).

The basic protocol will look like this:

Parameter types

type ResolveTargetParams struct {
    // TextDocument identifies the document context (e.g. CWD file or -pos file).
    TextDocument protocol.TextDocumentIdentifier `json:"textDocument"`

    // Target is the literal name or regex pattern (enclosed in slashes).
    Target string `json:"target"`

    // PkgScope optionally overrides the package search scope (from -pkg).
    PkgScope string `json:"pkgScope,omitempty"`

    // Range optionally restricts the search to a specific span within the file.
    Range *protocol.Range `json:"range,omitempty"`
}

Result types

type ResolveTargetResult struct {
    Matches []TargetMatch `json:"matches"`
}

type TargetMatch struct {
    Package  string            `json:"package,omitempty"` // Go package path
    Name     string            `json:"name"`              // Symbol name
    // Location is LSP protocol location because gopls.resolve_target
    // is an internal utility command to map the target symbol position to
    // LSP protocol locations.
    Location protocol.Location `json:"location"`
}

The rules for resolution are a bit trickier and still being ironed out, so will leave the source of truth to be the md file linked above.

Activity

  1. added this to the gopls/v0.24.0 milestone on Aug 13, 2026
  2. self-assigned this
    on Aug 13, 2026
  3. added
    goplsIssues related to the Go language server, gopls.
    ToolsThis label describes issues relating to any tools in the x/tools repository.
    on Aug 13, 2026
  4. added theissue type on Aug 13, 2026
  5. gopherbot commented on Aug 13, 2026

    @gopherbot
    Contributor

    Change https://go.dev/cl/815160 mentions this issue: gopls/internal/protocol: Add basic resolve_target gopls command

  6. gopherbot commented on Sep 15, 2026

    @gopherbot
    Contributor

    Change https://go.dev/cl/817120 mentions this issue: gopls/internal/resolvetarget: Add relative package paths.

  7. gopherbot commented on Oct 6, 2026

    @gopherbot
    Contributor

    Change https://go.dev/cl/846025 mentions this issue: gopls/internal/cmd: Add inspect subcommand

  8. gopherbot commented on Oct 14, 2026

    @gopherbot
    Contributor

    Change https://go.dev/cl/821440 mentions this issue: gopls/internal/test: allow marker tests at CWD directory

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

ToolsThis label describes issues relating to any tools in the x/tools repository.goplsIssues related to the Go language server, gopls.

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions