lsp

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2026 License: GPL-3.0 Imports: 17 Imported by: 0

Documentation

Overview

Package lsp serves the Language Server Protocol over a TDL model being edited: what is wrong with a file, and where a name under the cursor was declared.

It is private for the reason internal/sema is. `ir` and `proto` are the compatibility surface, and an editor integration is not.

See docs/design/lsp.md for the reasoning and docs/design/lsp-plan.md for what each phase adds.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Serve

func Serve(ctx context.Context, rwc io.ReadWriteCloser, opts ...sema.Option) error

Serve runs a server over one connection and returns when it ends.

The connection is built here rather than with protocol.NewServer, because that constructor wants the server before it has made the client, and this server publishes diagnostics, so it needs the client to exist first.

The logger is silent. Anything written to stdout on a stdio server corrupts the stream, and a library that logs by default is a library that will.

Types

type Server

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

Server answers protocol requests about the documents an editor has open.

It embeds unimplemented, so a request it does not serve is answered with ErrMethodNotFound rather than with a panic, and adding a feature is writing the method for it.

func NewServer

func NewServer(client protocol.Client, opts ...sema.Option) *Server

NewServer returns a server publishing to client.

opts are the lowering options every document is analyzed with, which is how a caller replaces the prelude. The loader is not among them: the server supplies its own, so an open document's unsaved text is what an import of it resolves to.

func (Server) CodeAction

func (Server) CodeAction(ctx context.Context, params *protocol.CodeActionParams) (result []protocol.CodeAction, err error)

func (Server) CodeLens

func (Server) CodeLens(ctx context.Context, params *protocol.CodeLensParams) (result []protocol.CodeLens, err error)

func (Server) CodeLensRefresh

func (Server) CodeLensRefresh(ctx context.Context) (err error)

func (Server) CodeLensResolve

func (Server) CodeLensResolve(ctx context.Context, params *protocol.CodeLens) (result *protocol.CodeLens, err error)

func (Server) ColorPresentation

func (Server) ColorPresentation(ctx context.Context, params *protocol.ColorPresentationParams) (result []protocol.ColorPresentation, err error)

func (Server) Completion

func (Server) Completion(ctx context.Context, params *protocol.CompletionParams) (result *protocol.CompletionList, err error)

func (Server) CompletionResolve

func (Server) CompletionResolve(ctx context.Context, params *protocol.CompletionItem) (result *protocol.CompletionItem, err error)

func (Server) Declaration

func (Server) Declaration(ctx context.Context, params *protocol.DeclarationParams) (result []protocol.Location, err error)

func (*Server) Definition

func (s *Server) Definition(_ context.Context, params *protocol.DefinitionParams) ([]protocol.Location, error)

Definition answers where the name under the cursor was declared.

The answer comes from the index internal/sema records while it resolves, so shadowing, the prelude, and `_` imports are decided by the code that already decides them and are not restated here.

Three cases return nothing, and all three are an answer rather than a failure: the cursor is not on a name, the name did not resolve, or it resolved into the prelude, which is embedded and has no file an editor can open. docs/design/lsp.md argues the last one.

func (*Server) DidChange

func (s *Server) DidChange(ctx context.Context, params *protocol.DidChangeTextDocumentParams) error

DidChange replaces a document's text and re-analyzes it.

Synchronization is full, so the last change carries the whole document. A change for a file that was never opened is dropped: the editor and the server disagree about what is open, and guessing at the text is worse than reporting nothing until the next didOpen.

func (Server) DidChangeConfiguration

func (Server) DidChangeConfiguration(ctx context.Context, params *protocol.DidChangeConfigurationParams) (err error)

func (Server) DidChangeWatchedFiles

func (Server) DidChangeWatchedFiles(ctx context.Context, params *protocol.DidChangeWatchedFilesParams) (err error)

func (Server) DidChangeWorkspaceFolders

func (Server) DidChangeWorkspaceFolders(ctx context.Context, params *protocol.DidChangeWorkspaceFoldersParams) (err error)

func (*Server) DidClose

func (s *Server) DidClose(ctx context.Context, params *protocol.DidCloseTextDocumentParams) error

DidClose forgets a document and clears what it published.

An import of it reads the disk from here, so every other open document is re-analyzed: one of them may import this file and have been resolving it against text that is no longer the server's to know.

func (Server) DidCreateFiles

func (Server) DidCreateFiles(ctx context.Context, params *protocol.CreateFilesParams) (err error)

func (Server) DidDeleteFiles

func (Server) DidDeleteFiles(ctx context.Context, params *protocol.DeleteFilesParams) (err error)

func (*Server) DidOpen

func (s *Server) DidOpen(ctx context.Context, params *protocol.DidOpenTextDocumentParams) error

DidOpen analyzes a document the editor has opened.

func (Server) DidRenameFiles

func (Server) DidRenameFiles(ctx context.Context, params *protocol.RenameFilesParams) (err error)

func (*Server) DidSave

func (s *Server) DidSave(ctx context.Context, params *protocol.DidSaveTextDocumentParams) error

DidSave re-analyzes, because a file this document imports may have been written by something other than the editor.

func (Server) DocumentColor

func (Server) DocumentColor(ctx context.Context, params *protocol.DocumentColorParams) (result []protocol.ColorInformation, err error)

func (Server) DocumentHighlight

func (Server) DocumentHighlight(ctx context.Context, params *protocol.DocumentHighlightParams) (result []protocol.DocumentHighlight, err error)
func (Server) DocumentLink(ctx context.Context, params *protocol.DocumentLinkParams) (result []protocol.DocumentLink, err error)

func (Server) DocumentLinkResolve

func (Server) DocumentLinkResolve(ctx context.Context, params *protocol.DocumentLink) (result *protocol.DocumentLink, err error)

func (Server) DocumentSymbol

func (Server) DocumentSymbol(ctx context.Context, params *protocol.DocumentSymbolParams) (result []interface{}, err error)

func (Server) ExecuteCommand

func (Server) ExecuteCommand(ctx context.Context, params *protocol.ExecuteCommandParams) (result interface{}, err error)

func (*Server) Exit

func (s *Server) Exit(context.Context) error

func (Server) FoldingRanges

func (Server) FoldingRanges(ctx context.Context, params *protocol.FoldingRangeParams) (result []protocol.FoldingRange, err error)

func (Server) Formatting

func (Server) Formatting(ctx context.Context, params *protocol.DocumentFormattingParams) (result []protocol.TextEdit, err error)

func (Server) Hover

func (Server) Hover(ctx context.Context, params *protocol.HoverParams) (result *protocol.Hover, err error)

func (Server) Implementation

func (Server) Implementation(ctx context.Context, params *protocol.ImplementationParams) (result []protocol.Location, err error)

func (Server) IncomingCalls

func (Server) IncomingCalls(ctx context.Context, params *protocol.CallHierarchyIncomingCallsParams) (result []protocol.CallHierarchyIncomingCall, err error)

func (*Server) Initialize

Initialize reports what this server serves.

Text synchronization is full rather than incremental. A .tdl file is a description of a domain model, the parser is one pass over it, and incremental sync would save nothing worth measuring while adding a second way for the server's copy of the text to drift from the editor's.

func (*Server) Initialized

func (Server) LinkedEditingRange

func (Server) LinkedEditingRange(ctx context.Context, params *protocol.LinkedEditingRangeParams) (result *protocol.LinkedEditingRanges, err error)

func (Server) LogTrace

func (Server) LogTrace(ctx context.Context, params *protocol.LogTraceParams) (err error)

func (Server) Moniker

func (Server) Moniker(ctx context.Context, params *protocol.MonikerParams) (result []protocol.Moniker, err error)

func (Server) OnTypeFormatting

func (Server) OnTypeFormatting(ctx context.Context, params *protocol.DocumentOnTypeFormattingParams) (result []protocol.TextEdit, err error)

func (Server) OutgoingCalls

func (Server) OutgoingCalls(ctx context.Context, params *protocol.CallHierarchyOutgoingCallsParams) (result []protocol.CallHierarchyOutgoingCall, err error)

func (Server) PrepareCallHierarchy

func (Server) PrepareCallHierarchy(ctx context.Context, params *protocol.CallHierarchyPrepareParams) (result []protocol.CallHierarchyItem, err error)

func (Server) PrepareRename

func (Server) PrepareRename(ctx context.Context, params *protocol.PrepareRenameParams) (result *protocol.Range, err error)

func (Server) RangeFormatting

func (Server) RangeFormatting(ctx context.Context, params *protocol.DocumentRangeFormattingParams) (result []protocol.TextEdit, err error)

func (Server) References

func (Server) References(ctx context.Context, params *protocol.ReferenceParams) (result []protocol.Location, err error)

func (Server) Rename

func (Server) Rename(ctx context.Context, params *protocol.RenameParams) (result *protocol.WorkspaceEdit, err error)

func (Server) Request

func (Server) Request(ctx context.Context, method string, params interface{}) (result interface{}, err error)

func (Server) SemanticTokensFull

func (Server) SemanticTokensFull(ctx context.Context, params *protocol.SemanticTokensParams) (result *protocol.SemanticTokens, err error)

func (Server) SemanticTokensFullDelta

func (Server) SemanticTokensFullDelta(ctx context.Context, params *protocol.SemanticTokensDeltaParams) (result interface{}, err error)

func (Server) SemanticTokensRange

func (Server) SemanticTokensRange(ctx context.Context, params *protocol.SemanticTokensRangeParams) (result *protocol.SemanticTokens, err error)

func (Server) SemanticTokensRefresh

func (Server) SemanticTokensRefresh(ctx context.Context) (err error)

func (*Server) SetTrace

func (Server) ShowDocument

func (Server) ShowDocument(ctx context.Context, params *protocol.ShowDocumentParams) (result *protocol.ShowDocumentResult, err error)

func (*Server) Shutdown

func (s *Server) Shutdown(context.Context) error

func (Server) SignatureHelp

func (Server) SignatureHelp(ctx context.Context, params *protocol.SignatureHelpParams) (result *protocol.SignatureHelp, err error)

func (Server) Symbols

func (Server) Symbols(ctx context.Context, params *protocol.WorkspaceSymbolParams) (result []protocol.SymbolInformation, err error)

func (Server) TypeDefinition

func (Server) TypeDefinition(ctx context.Context, params *protocol.TypeDefinitionParams) (result []protocol.Location, err error)

func (Server) WillCreateFiles

func (Server) WillCreateFiles(ctx context.Context, params *protocol.CreateFilesParams) (result *protocol.WorkspaceEdit, err error)

func (Server) WillDeleteFiles

func (Server) WillDeleteFiles(ctx context.Context, params *protocol.DeleteFilesParams) (result *protocol.WorkspaceEdit, err error)

func (Server) WillRenameFiles

func (Server) WillRenameFiles(ctx context.Context, params *protocol.RenameFilesParams) (result *protocol.WorkspaceEdit, err error)

func (Server) WillSave

func (Server) WillSave(ctx context.Context, params *protocol.WillSaveTextDocumentParams) (err error)

func (Server) WillSaveWaitUntil

func (Server) WillSaveWaitUntil(ctx context.Context, params *protocol.WillSaveTextDocumentParams) (result []protocol.TextEdit, err error)

func (Server) WorkDoneProgressCancel

func (Server) WorkDoneProgressCancel(ctx context.Context, params *protocol.WorkDoneProgressCancelParams) (err error)

Jump to

Keyboard shortcuts

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