lsp

package
v0.20.3 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package lsp implements a stateful, persistent JSON-RPC Language Server Protocol (LSP) client for multiplexing language analysis queries directly to a single, persistent gopls daemon.

Package lsp implements a stateful, persistent JSON-RPC Language Server Protocol (LSP) client.

Index

Constants

This section is empty.

Variables

View Source
var GlobalManager = &Manager{}

GlobalManager is the shared, package-level LSP lifecycle controller.

Functions

func PathToURI added in v0.20.2

func PathToURI(path string) string

PathToURI converts an absolute path to a file:// URI, supporting Windows drive letters.

Types

type Client

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

Client represents the persistent gopls LSP JSON-RPC client.

func NewClientWithConn

func NewClientWithConn(conn net.Conn) *Client

NewClientWithConn creates an LSP client using a pre-established net.Conn connection (ideal for testing).

func (*Client) Close

func (c *Client) Close(ctx context.Context) error

Close gracefully stops the LSP session by sending shutdown/exit sequence.

func (*Client) GetDefinition

func (c *Client) GetDefinition(ctx context.Context, filename string, line, col int) ([]Location, error)

GetDefinition retrieves definition coordinates (converting 1-indexed input to 0-indexed LSP queries).

func (*Client) Initialize

func (c *Client) Initialize(ctx context.Context, initialRoots []string) error

Initialize performs the standard initialize and initialized LSP handshake.

func (*Client) SyncRoots added in v0.20.2

func (c *Client) SyncRoots(_ context.Context, allRoots []string) error

SyncRoots synchronizes the active workspace roots with the provided list of roots.

type DefinitionParams

type DefinitionParams struct {
	TextDocument TextDocumentIdentifier `json:"textDocument"`
	Position     Position               `json:"position"`
}

DefinitionParams contains parameters for the textDocument/definition request.

type Location

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

Location represents a coordinates range inside a target URI.

type Manager

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

Manager coordinates the lifecycle of the single, persistent gopls language server process.

func (*Manager) Client

func (m *Manager) Client(ctx context.Context) (*Client, error)

Client retrieves the active, initialized LSP client.

func (*Manager) Close

func (m *Manager) Close(ctx context.Context) error

Close terminates the gopls process and cleans up connection resources.

func (*Manager) Reset added in v0.20.2

func (m *Manager) Reset(ctx context.Context) error

Reset terminates the active connection and process (if any) and clears the client so that a fresh, healthy language server is spawned on the next query.

type Position

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

Position represents a 0-indexed position within a text document.

type Range

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

Range represents a span inside a document.

type TextDocumentIdentifier

type TextDocumentIdentifier struct {
	URI string `json:"uri"`
}

TextDocumentIdentifier targets a specific file URI.

type WorkspaceFolder added in v0.20.2

type WorkspaceFolder struct {
	URI  string `json:"uri"`
	Name string `json:"name"`
}

WorkspaceFolder represents a workspace folder in LSP.

Jump to

Keyboard shortcuts

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