lsp

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: May 11, 2026 License: MIT Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SymbolKindClass    = 5
	SymbolKindFunction = 12
	SymbolKindProperty = 7
)

SymbolKind constants per LSP specification.

View Source
const (
	MessageTypeError   = 1
	MessageTypeWarning = 2
	MessageTypeInfo    = 3
	MessageTypeLog     = 4
)

MessageType constants per LSP specification.

View Source
const (
	CompletionKindText    = 1
	CompletionKindKeyword = 14
	CompletionKindClass   = 7
)

CompletionItemKind constants per LSP specification.

View Source
const JARScheme = "krit-jar"

JARScheme is the URI scheme for synthetic JAR-source documents that the LSP server can produce for goto-def / find-references results pointing into compiled dependencies.

The shape is:

krit-jar:///{artifact}/{version}/{path-with-slashes}.kt

The artifact and version are recovered from the JAR filename when possible (e.g. kotlinx-coroutines-core-1.7.3.jar → artifact=kotlinx-coroutines-core, version=1.7.3) and the path-with-slashes is the FQN of the requested symbol. The original on-disk JAR path and FQN are encoded as query parameters so the server can locate them again without re-deriving anything from the URI hierarchy.

Variables

This section is empty.

Functions

func BuildJARURI

func BuildJARURI(ref JARRef) string

BuildJARURI returns a synthetic LSP URI for a JAR-resolved declaration. The visible path embeds the artifact, version, and FQN-as-path so editors render a recognisable label, while the JAR path and FQN ride along as query parameters for round-trip parsing.

func IsJARURI

func IsJARURI(uri string) bool

IsJARURI reports whether uri uses the krit-jar scheme. It is cheaper than ParseJARURI and tolerates malformed query strings.

func PositionToByteOffset

func PositionToByteOffset(content []byte, pos Position) int

PositionToByteOffset converts an LSP position to a byte offset in content. LSP character offsets are UTF-16 code units, not UTF-8 bytes.

Types

type ClientCapabilities

type ClientCapabilities struct {
	TextDocument *TextDocumentClientCapabilities `json:"textDocument,omitempty"`
	Window       *WindowClientCapabilities       `json:"window,omitempty"`
}

ClientCapabilities describes the client's capabilities (minimal subset).

type CodeAction

type CodeAction struct {
	Title       string          `json:"title"`
	Kind        string          `json:"kind"` // "quickfix"
	Description string          `json:"description,omitempty"`
	Diagnostics []Diagnostic    `json:"diagnostics,omitempty"`
	Edit        *WorkspaceEdit  `json:"edit,omitempty"`
	Command     *Command        `json:"command,omitempty"`
	Data        *CodeActionData `json:"data,omitempty"`
}

CodeAction represents a code action (quick fix, refactor, etc.).

type CodeActionContext

type CodeActionContext struct {
	Diagnostics []Diagnostic `json:"diagnostics"`
}

CodeActionContext contains the diagnostics the code action was invoked for.

type CodeActionData

type CodeActionData struct {
	Preview *CodeActionPreview `json:"preview,omitempty"`
}

CodeActionData carries extra client-facing metadata for a code action.

type CodeActionParams

type CodeActionParams struct {
	TextDocument TextDocumentIdentifier `json:"textDocument"`
	Range        Range                  `json:"range"`
	Context      CodeActionContext      `json:"context"`
}

CodeActionParams contains the parameters for the textDocument/codeAction request.

type CodeActionPreview

type CodeActionPreview struct {
	FixLevel string `json:"fixLevel"`
	Diff     string `json:"diff"`
}

CodeActionPreview describes a proposed fix preview payload.

type CodeLens

type CodeLens struct {
	Range   Range    `json:"range"`
	Command *Command `json:"command,omitempty"`
	Data    any      `json:"data,omitempty"`
}

CodeLens represents inline metadata shown above source ranges.

type CodeLensOptions

type CodeLensOptions struct {
	ResolveProvider bool `json:"resolveProvider,omitempty"`
}

CodeLensOptions describes code lens provider capabilities.

type CodeLensParams

type CodeLensParams struct {
	TextDocument TextDocumentIdentifier `json:"textDocument"`
}

CodeLensParams contains the parameters for the textDocument/codeLens request.

type Command

type Command struct {
	Title     string        `json:"title"`
	Command   string        `json:"command"`
	Arguments []interface{} `json:"arguments,omitempty"`
}

Command represents an executable editor command attached to a code lens.

type CompletionItem

type CompletionItem struct {
	Label         string `json:"label"`
	Kind          int    `json:"kind"` // 1=Text, 6=Variable, 14=Keyword
	Detail        string `json:"detail,omitempty"`
	Documentation string `json:"documentation,omitempty"`
	InsertText    string `json:"insertText,omitempty"`
}

CompletionItem represents a completion suggestion.

type CompletionList

type CompletionList struct {
	IsIncomplete bool             `json:"isIncomplete"`
	Items        []CompletionItem `json:"items"`
}

CompletionList represents a collection of completion items.

type CompletionOptions

type CompletionOptions struct {
	TriggerCharacters []string `json:"triggerCharacters,omitempty"`
}

CompletionOptions describes completion provider capabilities.

type CompletionParams

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

CompletionParams contains the parameters for textDocument/completion.

type DefinitionParams

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

DefinitionParams contains the parameters for textDocument/definition.

type Diagnostic

type Diagnostic struct {
	Range    Range  `json:"range"`
	Severity int    `json:"severity,omitempty"` // 1=Error, 2=Warning, 3=Info, 4=Hint
	Code     string `json:"code,omitempty"`
	Source   string `json:"source,omitempty"`
	Message  string `json:"message"`
}

Diagnostic represents a diagnostic, such as a compiler error or warning.

func FindingColumnsToDiagnostics

func FindingColumnsToDiagnostics(columns *scanner.FindingColumns) []Diagnostic

FindingColumnsToDiagnostics converts columnar findings to LSP diagnostics.

type DiagnosticOptions

type DiagnosticOptions struct {
	InterFileDependencies bool   `json:"interFileDependencies"`
	WorkspaceDiagnostics  bool   `json:"workspaceDiagnostics"`
	Identifier            string `json:"identifier,omitempty"`
}

DiagnosticOptions describes diagnostic provider capabilities.

type DidChangeConfigurationParams

type DidChangeConfigurationParams struct {
	Settings json.RawMessage `json:"settings"`
}

DidChangeConfigurationParams contains the parameters for workspace/didChangeConfiguration.

type DidChangeTextDocumentParams

type DidChangeTextDocumentParams struct {
	TextDocument   VersionedTextDocumentIdentifier  `json:"textDocument"`
	ContentChanges []TextDocumentContentChangeEvent `json:"contentChanges"`
}

DidChangeTextDocumentParams contains the parameters for didChange.

type DidCloseTextDocumentParams

type DidCloseTextDocumentParams struct {
	TextDocument TextDocumentIdentifier `json:"textDocument"`
}

DidCloseTextDocumentParams contains the parameters for didClose.

type DidOpenTextDocumentParams

type DidOpenTextDocumentParams struct {
	TextDocument TextDocumentItem `json:"textDocument"`
}

DidOpenTextDocumentParams contains the parameters for didOpen.

type Document

type Document struct {
	URI      string
	Content  []byte
	Version  int32
	Findings scanner.FindingColumns
	File     *scanner.File
	// contains filtered or unexported fields
}

Document tracks an open text document.

type DocumentFormattingParams

type DocumentFormattingParams struct {
	TextDocument TextDocumentIdentifier `json:"textDocument"`
	Options      FormattingOptions      `json:"options"`
}

DocumentFormattingParams contains the parameters for textDocument/formatting.

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 represents a symbol in a document (class, function, property, etc.).

type DocumentSymbolParams

type DocumentSymbolParams struct {
	TextDocument TextDocumentIdentifier `json:"textDocument"`
}

DocumentSymbolParams contains the parameters for textDocument/documentSymbol.

type ExecuteCommandParams

type ExecuteCommandParams struct {
	Command   string            `json:"command"`
	Arguments []json.RawMessage `json:"arguments,omitempty"`
}

ExecuteCommandParams contains workspace/executeCommand request parameters.

type FormattingOptions

type FormattingOptions struct {
	TabSize      int  `json:"tabSize"`
	InsertSpaces bool `json:"insertSpaces"`
}

FormattingOptions describes formatting options.

type Hover

type Hover struct {
	Contents MarkupContent `json:"contents"`
	Range    *Range        `json:"range,omitempty"`
}

Hover is the result of a hover request.

type HoverParams

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

HoverParams contains the parameters for textDocument/hover.

type InitOptions

type InitOptions struct {
	ConfigPath        string   `json:"configPath,omitempty"`
	IndexOnInitialize *bool    `json:"indexOnInitialize,omitempty"`
	Classpath         []string `json:"classpath,omitempty"`
	UseOracleDaemon   *bool    `json:"useOracleDaemon,omitempty"`
}

InitOptions contains options passed from the client during initialization.

type InitializeParams

type InitializeParams struct {
	ProcessID             *int               `json:"processId"`
	RootURI               string             `json:"rootUri,omitempty"`
	RootPath              string             `json:"rootPath,omitempty"`
	Capabilities          ClientCapabilities `json:"capabilities"`
	InitializationOptions json.RawMessage    `json:"initializationOptions,omitempty"`
}

InitializeParams contains the parameters for the initialize request.

type InitializeResult

type InitializeResult struct {
	Capabilities ServerCapabilities `json:"capabilities"`
	ServerInfo   *ServerInfo        `json:"serverInfo,omitempty"`
}

InitializeResult is the response to the initialize request.

type JARContentParams

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

JARContentParams is the request payload for the krit/jarContent custom LSP method. Clients call this when a navigation result returns a krit-jar:// URI and the client needs the document body to render.

type JARContentResult

type JARContentResult struct {
	URI      string `json:"uri"`
	Language string `json:"languageId"`
	Text     string `json:"text"`
}

JARContentResult is the response for krit/jarContent. Languages other than Kotlin are unsupported; the field is included so future expansions (Java decompile, e.g.) don't require a protocol bump.

type JARLookup

type JARLookup func(fqn string) *oracle.Class

JARLookup is the optional bridge from the LSP server into oracle declaration data. When unset, krit/jarContent falls back to an unresolved-classpath placeholder. Wiring this up is part of the navigation-handler oracle integration milestone — providing the seam here lets that work proceed without changing the protocol.

type JARRef

type JARRef struct {
	JARPath string // absolute filesystem path to the .jar
	FQN     string // fully qualified name of the requested declaration
}

JARRef identifies a single symbol inside a JAR for the purposes of decompilation. Both fields are required.

func ParseJARURI

func ParseJARURI(uri string) (JARRef, error)

ParseJARURI is the inverse of BuildJARURI. It returns an error for any URI that does not use the krit-jar scheme or that is missing the required jar/fqn query parameters.

type Location

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

Location represents a location inside a resource.

type MarkupContent

type MarkupContent struct {
	Kind  string `json:"kind"` // "markdown" or "plaintext"
	Value string `json:"value"`
}

MarkupContent represents a string value with a kind (markdown or plaintext).

type Notification

type Notification = jsonrpc.Notification

JSON-RPC 2.0 types — aliases to the shared jsonrpc package.

type OracleWorkspaceIndexer

type OracleWorkspaceIndexer struct {
	JARPath   string
	Root      string
	Classpath []string
	Verbose   bool
	Fallback  WorkspaceIndexer
	Ready     func(*oracle.Daemon)
}

func (OracleWorkspaceIndexer) BuildWorkspaceIndex

func (o OracleWorkspaceIndexer) BuildWorkspaceIndex(ctx context.Context, root string, progress WorkspaceIndexProgress) (*oracle.Index, error)

type Position

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

Position represents a position in a text document (0-based line and character).

type PublishDiagnosticsCapability

type PublishDiagnosticsCapability struct {
	RelatedInformation bool `json:"relatedInformation,omitempty"`
}

PublishDiagnosticsCapability describes publishDiagnostics capabilities.

type PublishDiagnosticsParams

type PublishDiagnosticsParams struct {
	URI         string       `json:"uri"`
	Diagnostics []Diagnostic `json:"diagnostics"`
}

PublishDiagnosticsParams contains the parameters for publishDiagnostics.

type RPCError

type RPCError = jsonrpc.Error

JSON-RPC 2.0 types — aliases to the shared jsonrpc package.

type Range

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

Range represents a range in a text document.

type ReferenceContext

type ReferenceContext struct {
	IncludeDeclaration bool `json:"includeDeclaration"`
}

ReferenceContext contains additional information about the context of a reference request.

type ReferenceParams

type ReferenceParams struct {
	TextDocument TextDocumentIdentifier `json:"textDocument"`
	Position     Position               `json:"position"`
	Context      ReferenceContext       `json:"context"`
}

ReferenceParams contains the parameters for textDocument/references.

type RenameParams

type RenameParams struct {
	TextDocument TextDocumentIdentifier `json:"textDocument"`
	Position     Position               `json:"position"`
	NewName      string                 `json:"newName"`
}

RenameParams contains the parameters for textDocument/rename.

type Request

type Request = jsonrpc.Request

JSON-RPC 2.0 types — aliases to the shared jsonrpc package.

type Response

type Response = jsonrpc.Response

JSON-RPC 2.0 types — aliases to the shared jsonrpc package.

type Server

type Server struct {

	// Verbose gates informational log output.
	Verbose bool

	// OracleRefresh, when set, is invoked on a separate longer-debounced
	// timer after each didChange. Implementations send a per-file re-analyze
	// request to the krit-types daemon and apply the result to the FQN
	// reverse index. Must be set before Run() — there is no synchronization
	// against concurrent reassignment.
	OracleRefresh func(uri string, content []byte)
	// contains filtered or unexported fields
}

Server implements a minimal LSP server over stdio using JSON-RPC 2.0.

func NewServer

func NewServer(reader *bufio.Reader, writer io.Writer) *Server

NewServer creates a new LSP server reading from reader and writing to writer.

func (*Server) Run

func (s *Server) Run()

Run reads and dispatches LSP messages until EOF or exit.

func (*Server) SetJARLookup

func (s *Server) SetJARLookup(fn JARLookup)

SetJARLookup installs (or replaces) the lookup. Safe to call before or after the first krit/jarContent request.

func (*Server) SetLogger

func (s *Server) SetLogger(l logger.Logger)

SetLogger overrides the default Logger. Intended for tests to inject logger.NewCapture so emitted records are observable.

func (*Server) SetOracleIndex

func (s *Server) SetOracleIndex(idx *oracle.Index)

SetOracleIndex installs a new index. Tests use this directly; production callers will route through the workspace-init path in a later milestone.

func (*Server) SetWorkspaceIndexer

func (s *Server) SetWorkspaceIndexer(indexer WorkspaceIndexer)

type ServerCapabilities

type ServerCapabilities struct {
	TextDocumentSync           *TextDocumentSyncOptions `json:"textDocumentSync,omitempty"`
	DiagnosticProvider         *DiagnosticOptions       `json:"diagnosticProvider,omitempty"`
	CodeActionProvider         bool                     `json:"codeActionProvider,omitempty"`
	CodeLensProvider           *CodeLensOptions         `json:"codeLensProvider,omitempty"`
	DocumentFormattingProvider bool                     `json:"documentFormattingProvider,omitempty"`
	HoverProvider              bool                     `json:"hoverProvider,omitempty"`
	DocumentSymbolProvider     bool                     `json:"documentSymbolProvider,omitempty"`
	DefinitionProvider         bool                     `json:"definitionProvider,omitempty"`
	ReferencesProvider         bool                     `json:"referencesProvider,omitempty"`
	RenameProvider             bool                     `json:"renameProvider,omitempty"`
	CompletionProvider         *CompletionOptions       `json:"completionProvider,omitempty"`
}

ServerCapabilities describes the server's capabilities.

type ServerInfo

type ServerInfo struct {
	Name    string `json:"name"`
	Version string `json:"version,omitempty"`
}

ServerInfo contains information about the server.

type ShowMessageParams

type ShowMessageParams struct {
	Type    int    `json:"type"`
	Message string `json:"message"`
}

ShowMessageParams contains the parameters for window/showMessage.

type SourceWorkspaceIndexer

type SourceWorkspaceIndexer struct{}

func (SourceWorkspaceIndexer) BuildWorkspaceIndex

func (SourceWorkspaceIndexer) BuildWorkspaceIndex(ctx context.Context, root string, progress WorkspaceIndexProgress) (*oracle.Index, error)

type TextDocumentClientCapabilities

type TextDocumentClientCapabilities struct {
	PublishDiagnostics *PublishDiagnosticsCapability `json:"publishDiagnostics,omitempty"`
}

TextDocumentClientCapabilities describes textDocument capabilities.

type TextDocumentContentChangeEvent

type TextDocumentContentChangeEvent struct {
	Text string `json:"text"`
}

TextDocumentContentChangeEvent describes a change to a text document. With full sync, RangeLength and Range are nil and Text contains the full content.

type TextDocumentIdentifier

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

TextDocumentIdentifier identifies a text document.

type TextDocumentItem

type TextDocumentItem struct {
	URI        string `json:"uri"`
	LanguageID string `json:"languageId"`
	Version    int32  `json:"version"`
	Text       string `json:"text"`
}

TextDocumentItem is an item to transfer a text document from client to server.

type TextDocumentSyncOptions

type TextDocumentSyncOptions struct {
	OpenClose bool `json:"openClose"`
	// Change is the sync kind: 0=None, 1=Full, 2=Incremental.
	Change int `json:"change"`
}

TextDocumentSyncOptions describes how text documents are synced.

type TextEdit

type TextEdit struct {
	Range   Range  `json:"range"`
	NewText string `json:"newText"`
}

TextEdit represents a text edit applicable to a document.

type VersionedTextDocumentIdentifier

type VersionedTextDocumentIdentifier struct {
	URI     string `json:"uri"`
	Version int32  `json:"version"`
}

VersionedTextDocumentIdentifier identifies a specific version of a text document.

type WindowClientCapabilities

type WindowClientCapabilities struct {
	WorkDoneProgress bool `json:"workDoneProgress,omitempty"`
}

type WorkDoneProgressParams

type WorkDoneProgressParams struct {
	Token string                `json:"token"`
	Value WorkDoneProgressValue `json:"value"`
}

type WorkDoneProgressValue

type WorkDoneProgressValue struct {
	Kind       string `json:"kind"`
	Title      string `json:"title,omitempty"`
	Message    string `json:"message,omitempty"`
	Percentage int    `json:"percentage,omitempty"`
}

type WorkspaceEdit

type WorkspaceEdit struct {
	Changes map[string][]TextEdit `json:"changes"`
}

WorkspaceEdit represents changes to multiple resources.

type WorkspaceIndexProgress

type WorkspaceIndexProgress func(done, total int)

type WorkspaceIndexer

type WorkspaceIndexer interface {
	BuildWorkspaceIndex(ctx context.Context, root string, progress WorkspaceIndexProgress) (*oracle.Index, error)
}

Jump to

Keyboard shortcuts

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