lsp

package
v0.2.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 23, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package lsp implements a minimal, synchronous Language Server Protocol client that speaks JSON-RPC 2.0 over a server process's stdio. It is stdlib-only and intended for read-only symbol resolution: enclosing definition ranges, go-to-definition and find-references.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PathToURI

func PathToURI(path string) string

PathToURI converts a filesystem path to a file:// URI. The path is made absolute when possible; each segment is percent-escaped.

func URIToPath

func URIToPath(uri string) string

URIToPath converts a file:// URI back to a filesystem path. Non-file or unparseable URIs are returned unchanged.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is a synchronous JSON-RPC 2.0 LSP client bound to a server process. A single background goroutine reads framed responses and demultiplexes them to per-request waiters keyed by id.

func Start

func Start(ctx context.Context, argv []string, rootDir string) (*Client, error)

Start launches the language server (argv[0] with argv[1:] args), performs the LSP initialize handshake rooted at rootDir, and returns a ready client. It returns an error rather than hanging if the binary is missing or the initialize request fails. The ctx bounds the whole client lifetime; every request also honours it and a per-request timeout.

func (*Client) Close

func (c *Client) Close() error

Close performs a best-effort shutdown/exit handshake, then kills the process and closes the pipes. It is safe to call more than once.

func (*Client) Definition

func (c *Client) Definition(uri string, line, char int) ([]Location, error)

Definition resolves the definition(s) of the symbol at (line, char), handling Location, Location[] and LocationLink[] result shapes.

func (*Client) DidOpen

func (c *Client) DidOpen(uri, languageID, text string) error

DidOpen notifies the server that a document is open with the given contents.

func (*Client) DocumentSymbol

func (c *Client) DocumentSymbol(uri string) ([]DocumentSymbol, error)

DocumentSymbol returns the document's symbols, supporting both the hierarchical DocumentSymbol[] shape and the flat SymbolInformation[] fallback.

func (*Client) References

func (c *Client) References(uri string, line, char int, includeDecl bool) ([]Location, error)

References finds the references to the symbol at (line, char). When includeDecl is true the declaration itself is included.

type DocumentSymbol

type DocumentSymbol struct {
	Name           string           `json:"name"`
	Kind           int              `json:"kind"`
	Range          Range            `json:"range"`
	SelectionRange Range            `json:"selectionRange"`
	Children       []DocumentSymbol `json:"children,omitempty"`
}

DocumentSymbol is a hierarchical symbol with an enclosing Range and a narrower SelectionRange (typically the name).

type Location

type Location struct {
	URI   string `json:"uri"`
	Range Range  `json:"range"`
}

Location identifies a range within a document URI.

type Position

type Position struct {
	Line      int `json:"line"`
	Character int `json:"character"`
}

Position is a zero-based location within a text document.

type Range

type Range struct {
	Start Position `json:"start"`
	End   Position `json:"end"`
}

Range is a span between two positions (end exclusive).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL