server

package
v0.0.0-...-cdf053b Latest Latest
Warning

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

Go to latest
Published: May 27, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewDefaultBinder

func NewDefaultBinder(sc *service.Container) jsonrpc2.Binder

NewDefaultBinder creates a new default binder.

func NewDefaultLanguageServer

func NewDefaultLanguageServer(sc *service.Container) lsp.Server

NewDefaultLanguageServer creates a new default language server.

func NewSlogHandler

func NewSlogHandler(sc *service.Container) slog.Handler

NewSlogHandler creates a new slog handler that writes to the LSP connection.

func SetupDefaultServices

func SetupDefaultServices(sc *service.Container)

SetupDefaultServices sets up the default services for the language server. If any service is already set, it's not overwritten.

func StartLanguageServer

func StartLanguageServer(ctx context.Context, sc *service.Container) error

StartLanguageServer starts a language server using the service container. It sets up JSON-RPC communication over stdio and handles the essential LSP messages.

func SymbolKind

func SymbolKind(node core.AstNode) lsp.SymbolKind

SymbolKind returns the LSP symbol kind for a node. If the node implements SymbolKindNode, uses that. Otherwise returns lsp.Field as default.

Language-specific implementations can be provided by implementing the SymbolKindNode interface.

Types

type Connection

type Connection struct {
	Value *jsonrpc2.Connection
}

Connection is assigned by ConnectionBinder when the language server is started.

type DefaultBinder

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

DefaultBinder implements the jsonrpc2.Binder interface

func (*DefaultBinder) Bind

type DefaultDefinitionProvider

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

DefaultDefinitionProvider is the default implementation of DefinitionProvider.

func (*DefaultDefinitionProvider) HandleDefinitionRequest

func (s *DefaultDefinitionProvider) HandleDefinitionRequest(ctx context.Context, params *lsp.DefinitionParams) ([]lsp.DefinitionLink, error)

type DefaultDocumentSymbolFilter

type DefaultDocumentSymbolFilter struct{}

DefaultDocumentSymbolFilter provides standard symbol filtering behavior.

func (*DefaultDocumentSymbolFilter) ShouldInclude

func (f *DefaultDocumentSymbolFilter) ShouldInclude(node core.AstNode) bool

type DefaultDocumentSymbolProvider

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

DefaultDocumentSymbolProvider implements the DocumentSymbolProvider interface.

func (*DefaultDocumentSymbolProvider) HandleDocumentSymbolRequest

func (p *DefaultDocumentSymbolProvider) HandleDocumentSymbolRequest(ctx context.Context, params *lsp.DocumentSymbolParams) ([]lsp.DocumentSymbol, error)

type DefaultDocumentSyncher

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

DefaultDocumentSyncher is the default implementation of DocumentSyncher.

func (*DefaultDocumentSyncher) DidChange

func (*DefaultDocumentSyncher) DidClose

func (*DefaultDocumentSyncher) DidOpen

func (*DefaultDocumentSyncher) DidSave

DidSave does nothing by default.

func (*DefaultDocumentSyncher) WillSave

WillSave does nothing by default.

func (*DefaultDocumentSyncher) WillSaveWaitUntil

func (s *DefaultDocumentSyncher) WillSaveWaitUntil(ctx context.Context, params *lsp.WillSaveTextDocumentParams) ([]lsp.TextEdit, error)

WillSaveWaitUntil does nothing by default.

type DefaultFoldingRangeFilter

type DefaultFoldingRangeFilter struct{}

DefaultFoldingRangeFilter provides the standard folding behavior: Processes all nodes, excludes last line for nodes ending with closing brackets, and includes last line for comments.

func (*DefaultFoldingRangeFilter) IncludeLastFoldingLine

func (f *DefaultFoldingRangeFilter) IncludeLastFoldingLine(node core.AstNode) bool

func (*DefaultFoldingRangeFilter) IncludeLastFoldingLineForComment

func (f *DefaultFoldingRangeFilter) IncludeLastFoldingLineForComment() bool

func (*DefaultFoldingRangeFilter) ShouldProcess

func (f *DefaultFoldingRangeFilter) ShouldProcess(node core.AstNode) bool

type DefaultFoldingRangeProvider

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

func (*DefaultFoldingRangeProvider) HandleFoldingRangeRequest

func (p *DefaultFoldingRangeProvider) HandleFoldingRangeRequest(ctx context.Context, params *lsp.FoldingRangeParams) ([]lsp.FoldingRange, error)

type DefaultLanguageServer

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

DefaultLanguageServer implements the lsp.Server interface

func (*DefaultLanguageServer) CodeAction

func (s *DefaultLanguageServer) CodeAction(ctx context.Context, params *lsp.CodeActionParams) ([]lsp.CodeAction, error)

func (*DefaultLanguageServer) CodeLens

func (s *DefaultLanguageServer) CodeLens(ctx context.Context, params *lsp.CodeLensParams) ([]lsp.CodeLens, error)

func (*DefaultLanguageServer) ColorPresentation

func (*DefaultLanguageServer) Completion

func (*DefaultLanguageServer) Declaration

func (*DefaultLanguageServer) Definition

func (*DefaultLanguageServer) Diagnostic

func (*DefaultLanguageServer) DiagnosticWorkspace

func (*DefaultLanguageServer) DidChange

func (*DefaultLanguageServer) DidChangeConfiguration

func (s *DefaultLanguageServer) DidChangeConfiguration(ctx context.Context, params *lsp.DidChangeConfigurationParams) error

func (*DefaultLanguageServer) DidChangeNotebookDocument

func (s *DefaultLanguageServer) DidChangeNotebookDocument(ctx context.Context, params *lsp.DidChangeNotebookDocumentParams) error

func (*DefaultLanguageServer) DidChangeWatchedFiles

func (s *DefaultLanguageServer) DidChangeWatchedFiles(ctx context.Context, params *lsp.DidChangeWatchedFilesParams) error

func (*DefaultLanguageServer) DidChangeWorkspaceFolders

func (s *DefaultLanguageServer) DidChangeWorkspaceFolders(ctx context.Context, params *lsp.DidChangeWorkspaceFoldersParams) error

func (*DefaultLanguageServer) DidClose

func (*DefaultLanguageServer) DidCloseNotebookDocument

func (s *DefaultLanguageServer) DidCloseNotebookDocument(ctx context.Context, params *lsp.DidCloseNotebookDocumentParams) error

func (*DefaultLanguageServer) DidCreateFiles

func (s *DefaultLanguageServer) DidCreateFiles(ctx context.Context, params *lsp.CreateFilesParams) error

func (*DefaultLanguageServer) DidDeleteFiles

func (s *DefaultLanguageServer) DidDeleteFiles(ctx context.Context, params *lsp.DeleteFilesParams) error

func (*DefaultLanguageServer) DidOpen

func (*DefaultLanguageServer) DidOpenNotebookDocument

func (s *DefaultLanguageServer) DidOpenNotebookDocument(ctx context.Context, params *lsp.DidOpenNotebookDocumentParams) error

func (*DefaultLanguageServer) DidRenameFiles

func (s *DefaultLanguageServer) DidRenameFiles(ctx context.Context, params *lsp.RenameFilesParams) error

func (*DefaultLanguageServer) DidSave

func (*DefaultLanguageServer) DidSaveNotebookDocument

func (s *DefaultLanguageServer) DidSaveNotebookDocument(ctx context.Context, params *lsp.DidSaveNotebookDocumentParams) error

func (*DefaultLanguageServer) DocumentColor

func (*DefaultLanguageServer) DocumentHighlight

func (s *DefaultLanguageServer) DocumentLink(ctx context.Context, params *lsp.DocumentLinkParams) ([]lsp.DocumentLink, error)

func (*DefaultLanguageServer) DocumentSymbol

func (s *DefaultLanguageServer) DocumentSymbol(ctx context.Context, params *lsp.DocumentSymbolParams) ([]any, error)

func (*DefaultLanguageServer) ExecuteCommand

func (s *DefaultLanguageServer) ExecuteCommand(ctx context.Context, params *lsp.ExecuteCommandParams) (any, error)

func (*DefaultLanguageServer) Exit

func (*DefaultLanguageServer) FoldingRange

func (s *DefaultLanguageServer) FoldingRange(ctx context.Context, params *lsp.FoldingRangeParams) ([]lsp.FoldingRange, error)

func (*DefaultLanguageServer) Formatting

func (*DefaultLanguageServer) Hover

func (s *DefaultLanguageServer) Hover(ctx context.Context, params *lsp.HoverParams) (*lsp.Hover, error)

func (*DefaultLanguageServer) Implementation

func (*DefaultLanguageServer) IncomingCalls

func (*DefaultLanguageServer) Initialize

func (*DefaultLanguageServer) Initialized

func (s *DefaultLanguageServer) Initialized(ctx context.Context, params *lsp.InitializedParams) error

func (*DefaultLanguageServer) InlayHint

func (s *DefaultLanguageServer) InlayHint(ctx context.Context, params *lsp.InlayHintParams) ([]lsp.InlayHint, error)

func (*DefaultLanguageServer) InlineCompletion

func (*DefaultLanguageServer) InlineValue

func (s *DefaultLanguageServer) InlineValue(ctx context.Context, params *lsp.InlineValueParams) ([]lsp.InlineValue, error)

func (*DefaultLanguageServer) LinkedEditingRange

func (*DefaultLanguageServer) Moniker

func (s *DefaultLanguageServer) Moniker(ctx context.Context, params *lsp.MonikerParams) ([]lsp.Moniker, error)

func (*DefaultLanguageServer) OnTypeFormatting

func (*DefaultLanguageServer) OutgoingCalls

func (*DefaultLanguageServer) PrepareCallHierarchy

func (*DefaultLanguageServer) PrepareRename

func (*DefaultLanguageServer) PrepareTypeHierarchy

func (*DefaultLanguageServer) Progress

func (s *DefaultLanguageServer) Progress(ctx context.Context, params *lsp.ProgressParams) error

func (*DefaultLanguageServer) RangeFormatting

func (*DefaultLanguageServer) RangesFormatting

func (*DefaultLanguageServer) References

func (s *DefaultLanguageServer) References(ctx context.Context, params *lsp.ReferenceParams) ([]lsp.Location, error)

func (*DefaultLanguageServer) Rename

func (*DefaultLanguageServer) Resolve

func (s *DefaultLanguageServer) Resolve(ctx context.Context, params *lsp.InlayHint) (*lsp.InlayHint, error)

func (*DefaultLanguageServer) ResolveCodeAction

func (s *DefaultLanguageServer) ResolveCodeAction(ctx context.Context, params *lsp.CodeAction) (*lsp.CodeAction, error)

func (*DefaultLanguageServer) ResolveCodeLens

func (s *DefaultLanguageServer) ResolveCodeLens(ctx context.Context, params *lsp.CodeLens) (*lsp.CodeLens, error)

func (*DefaultLanguageServer) ResolveCompletionItem

func (s *DefaultLanguageServer) ResolveCompletionItem(ctx context.Context, params *lsp.CompletionItem) (*lsp.CompletionItem, error)
func (s *DefaultLanguageServer) ResolveDocumentLink(ctx context.Context, params *lsp.DocumentLink) (*lsp.DocumentLink, error)

func (*DefaultLanguageServer) ResolveWorkspaceSymbol

func (s *DefaultLanguageServer) ResolveWorkspaceSymbol(ctx context.Context, params *lsp.WorkspaceSymbol) (*lsp.WorkspaceSymbol, error)

func (*DefaultLanguageServer) SelectionRange

func (*DefaultLanguageServer) SemanticTokensFull

func (s *DefaultLanguageServer) SemanticTokensFull(ctx context.Context, params *lsp.SemanticTokensParams) (*lsp.SemanticTokens, error)

func (*DefaultLanguageServer) SemanticTokensFullDelta

func (s *DefaultLanguageServer) SemanticTokensFullDelta(ctx context.Context, params *lsp.SemanticTokensDeltaParams) (any, error)

func (*DefaultLanguageServer) SemanticTokensRange

func (s *DefaultLanguageServer) SemanticTokensRange(ctx context.Context, params *lsp.SemanticTokensRangeParams) (*lsp.SemanticTokens, error)

func (*DefaultLanguageServer) SetTrace

func (s *DefaultLanguageServer) SetTrace(ctx context.Context, params *lsp.SetTraceParams) error

func (*DefaultLanguageServer) Shutdown

func (s *DefaultLanguageServer) Shutdown(ctx context.Context) error

func (*DefaultLanguageServer) SignatureHelp

func (*DefaultLanguageServer) Subtypes

func (*DefaultLanguageServer) Supertypes

func (*DefaultLanguageServer) Symbol

func (*DefaultLanguageServer) TextDocumentContent

func (*DefaultLanguageServer) TypeDefinition

func (*DefaultLanguageServer) WillCreateFiles

func (s *DefaultLanguageServer) WillCreateFiles(ctx context.Context, params *lsp.CreateFilesParams) (*lsp.WorkspaceEdit, error)

func (*DefaultLanguageServer) WillDeleteFiles

func (s *DefaultLanguageServer) WillDeleteFiles(ctx context.Context, params *lsp.DeleteFilesParams) (*lsp.WorkspaceEdit, error)

func (*DefaultLanguageServer) WillRenameFiles

func (s *DefaultLanguageServer) WillRenameFiles(ctx context.Context, params *lsp.RenameFilesParams) (*lsp.WorkspaceEdit, error)

func (*DefaultLanguageServer) WillSave

func (*DefaultLanguageServer) WillSaveWaitUntil

func (s *DefaultLanguageServer) WillSaveWaitUntil(ctx context.Context, params *lsp.WillSaveTextDocumentParams) ([]lsp.TextEdit, error)

func (*DefaultLanguageServer) WorkDoneProgressCancel

func (s *DefaultLanguageServer) WorkDoneProgressCancel(ctx context.Context, params *lsp.WorkDoneProgressCancelParams) error

type DefaultNameFinder

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

func (*DefaultNameFinder) Find

func (nf *DefaultNameFinder) Find(ctx context.Context, token *core.Token) FoundName

type DefaultReferencesFinder

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

func (*DefaultReferencesFinder) Find

type DefaultReferencesProvider

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

DefaultReferencesProvider is the default implementation of ReferencesProvider.

func (*DefaultReferencesProvider) HandleReferencesRequest

func (s *DefaultReferencesProvider) HandleReferencesRequest(ctx context.Context, params *lsp.ReferenceParams) ([]lsp.Location, error)

type DefaultRenameProvider

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

func (*DefaultRenameProvider) HandleRenameRequest

func (rp *DefaultRenameProvider) HandleRenameRequest(ctx context.Context, params *lsp.RenameParams) (*lsp.WorkspaceEdit, error)

func (*DefaultRenameProvider) PrepareRenameRequest

func (rp *DefaultRenameProvider) PrepareRenameRequest(ctx context.Context, params *lsp.PrepareRenameParams) (*lsp.PrepareRenameResult, error)

type DefinitionProvider

type DefinitionProvider interface {
	// TODO: Maybe add the document directly to the params to avoid looking it up in the workspace?
	// Also, maybe add a separate params struct that doesn't directly depend on the lsp lib
	HandleDefinitionRequest(ctx context.Context, params *lsp.DefinitionParams) ([]lsp.DefinitionLink, error)
}

DefinitionProvider is a service for handling LSP definition requests.

func NewDefaultDefinitionProvider

func NewDefaultDefinitionProvider(sc *service.Container) DefinitionProvider

type DocumentSymbolFilter

type DocumentSymbolFilter interface {
	// ShouldInclude determines whether the specified AstNode should appear as a symbol.
	// By default, nodes with names are included.
	ShouldInclude(node core.AstNode) bool
}

DocumentSymbolFilter defines document-symbol-specific customization points.

type DocumentSymbolProvider

type DocumentSymbolProvider interface {
	HandleDocumentSymbolRequest(ctx context.Context, params *lsp.DocumentSymbolParams) ([]lsp.DocumentSymbol, error)
}

DocumentSymbolProvider is a service for handling LSP document symbol requests.

func NewDefaultDocumentSymbolProvider

func NewDefaultDocumentSymbolProvider(sc *service.Container) DocumentSymbolProvider

NewDefaultDocumentSymbolProvider creates a provider using services from the container.

func NewDocumentSymbolProviderWithFilter

func NewDocumentSymbolProviderWithFilter(sc *service.Container, filter DocumentSymbolFilter) DocumentSymbolProvider

NewDocumentSymbolProviderWithFilter creates a provider with a custom filter.

type DocumentSyncher

type DocumentSyncher interface {
	DidOpen(ctx context.Context, params *lsp.DidOpenTextDocumentParams)
	DidChange(ctx context.Context, params *lsp.DidChangeTextDocumentParams)
	DidClose(ctx context.Context, params *lsp.DidCloseTextDocumentParams)
	WillSave(ctx context.Context, params *lsp.WillSaveTextDocumentParams)
	WillSaveWaitUntil(ctx context.Context, params *lsp.WillSaveTextDocumentParams) ([]lsp.TextEdit, error)
	DidSave(ctx context.Context, params *lsp.DidSaveTextDocumentParams)
}

DocumentSyncher is a service for handling LSP text document synchronization notifications.

Thread Safety: All methods are safe for concurrent use.

func NewDefaultDocumentSyncher

func NewDefaultDocumentSyncher(sc *service.Container) DocumentSyncher

type FindReferencesOptions

type FindReferencesOptions struct {
	// Whether to include the declaration of the symbol as a dedicated [core.ReferenceDescription] in the results.
	// If true, will contain the declaration as a reference with the same source and target node, and the range of the name as the first element.
	IncludeDeclaration bool
}

type FoldingRangeFilter

type FoldingRangeFilter interface {
	// ShouldProcess determines whether the specified AstNode should be folded.
	ShouldProcess(node core.AstNode) bool

	// IncludeLastFoldingLine determines whether the folding range should include its last line for AST nodes.
	// Return false to exclude the last line (e.g., for nodes ending in closing braces).
	IncludeLastFoldingLine(node core.AstNode) bool

	// IncludeLastFoldingLineForComment determines whether comment folding ranges should include the last line.
	// Return false to exclude the last line (typically desired for multi-line comments).
	IncludeLastFoldingLineForComment() bool
}

FoldingRangeFilter defines the customization points for folding behavior.

type FoldingRangeProvider

type FoldingRangeProvider interface {
	HandleFoldingRangeRequest(ctx context.Context, params *lsp.FoldingRangeParams) ([]lsp.FoldingRange, error)
}

FoldingRangeProvider is a service for handling LSP folding range requests.

func NewDefaultFoldingRangeProvider

func NewDefaultFoldingRangeProvider(sc *service.Container) FoldingRangeProvider

func NewFoldingRangeProviderWithFilter

func NewFoldingRangeProviderWithFilter(sc *service.Container, filter FoldingRangeFilter) FoldingRangeProvider

type FoundName

type FoundName struct {
	// The unit that contains the token that was used to start the search.
	Source core.StringUnit
	// The unit that contains the name of the symbol that was found.
	Target core.StringUnit
}

type NameFinder

type NameFinder interface {
	Find(ctx context.Context, token *core.Token) FoundName
}

NameFinder is responsible for finding the source and target core.StringUnit for a given token. It is used by various LSP services to find the name of a referenced/given symbol. Adopters should customize this service if they want to change how names are found in LSP services. Downstream LSP services will automatically use the new implementation.

func NewDefaultNameFinder

func NewDefaultNameFinder(sc *service.Container) NameFinder

type ReferencesFinder

type ReferencesFinder interface {
	Find(ctx context.Context, target core.AstNode, options FindReferencesOptions) iter.Seq[*core.ReferenceDescription]
}

func NewDefaultReferencesFinder

func NewDefaultReferencesFinder(sc *service.Container) ReferencesFinder

type ReferencesProvider

type ReferencesProvider interface {
	HandleReferencesRequest(ctx context.Context, params *lsp.ReferenceParams) ([]lsp.Location, error)
}

ReferencesProvider is a service for handling LSP reference requests.

func NewDefaultReferencesProvider

func NewDefaultReferencesProvider(sc *service.Container) ReferencesProvider

type RenameProvider

type RenameProvider interface {
	HandleRenameRequest(ctx context.Context, params *lsp.RenameParams) (*lsp.WorkspaceEdit, error)
	PrepareRenameRequest(ctx context.Context, params *lsp.PrepareRenameParams) (*lsp.PrepareRenameResult, error)
}

func NewDefaultRenameProvider

func NewDefaultRenameProvider(sc *service.Container) RenameProvider

type StdioDialer

type StdioDialer struct{}

StdioDialer implements jsonrpc2.Dialer for stdio communication

func (StdioDialer) Dial

type SymbolKindNode

type SymbolKindNode interface {
	// SymbolKind returns the LSP symbol kind for this node.
	SymbolKind() lsp.SymbolKind
}

SymbolKindNode can be implemented by AST node Impl structs to provide custom LSP symbol kinds for the document symbol outline.

type TextDocumentChangeEvent

type TextDocumentChangeEvent struct {
	Document *textdoc.Overlay
}

TextDocumentChangeEvent signals changes to a text document.

type TextDocumentChangeHandler

type TextDocumentChangeHandler func(ctx context.Context, event *TextDocumentChangeEvent)

TextDocumentChangeHandler is called when a document changes. Handlers are invoked synchronously in the order they were registered. If a handler blocks, it will delay subsequent handlers and the notification response.

type TextDocumentWillSaveEvent

type TextDocumentWillSaveEvent struct {
	Document *textdoc.Overlay
	Reason   lsp.TextDocumentSaveReason
}

TextDocumentWillSaveEvent signals that a document will be saved.

type TextDocumentWillSaveHandler

type TextDocumentWillSaveHandler func(ctx context.Context, event *TextDocumentWillSaveEvent)

TextDocumentWillSaveHandler is called when a document will be saved. Handlers are invoked synchronously in the order they were registered.

type TextDocumentWillSaveWaitUntilHandler

type TextDocumentWillSaveWaitUntilHandler func(ctx context.Context, event *TextDocumentWillSaveEvent) ([]lsp.TextEdit, error)

TextDocumentWillSaveWaitUntilHandler is called when a document will be saved and can return edits. Only one handler can be registered for this event to ensure deterministic edit behavior.

type WorkspaceFolders

type WorkspaceFolders struct {
	Value []lsp.WorkspaceFolder
}

WorkspaceFolders is populated during the LSP initialize request.

Jump to

Keyboard shortcuts

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