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 ¶
- func Serve(ctx context.Context, rwc io.ReadWriteCloser, opts ...sema.Option) error
- type Server
- func (Server) CodeAction(ctx context.Context, params *protocol.CodeActionParams) (result []protocol.CodeAction, err error)
- func (Server) CodeLens(ctx context.Context, params *protocol.CodeLensParams) (result []protocol.CodeLens, err error)
- func (Server) CodeLensRefresh(ctx context.Context) (err error)
- func (Server) CodeLensResolve(ctx context.Context, params *protocol.CodeLens) (result *protocol.CodeLens, err error)
- func (Server) ColorPresentation(ctx context.Context, params *protocol.ColorPresentationParams) (result []protocol.ColorPresentation, err error)
- func (Server) Completion(ctx context.Context, params *protocol.CompletionParams) (result *protocol.CompletionList, err error)
- func (Server) CompletionResolve(ctx context.Context, params *protocol.CompletionItem) (result *protocol.CompletionItem, err error)
- func (Server) Declaration(ctx context.Context, params *protocol.DeclarationParams) (result []protocol.Location, err error)
- func (s *Server) Definition(_ context.Context, params *protocol.DefinitionParams) ([]protocol.Location, error)
- func (s *Server) DidChange(ctx context.Context, params *protocol.DidChangeTextDocumentParams) error
- func (Server) DidChangeConfiguration(ctx context.Context, params *protocol.DidChangeConfigurationParams) (err error)
- func (Server) DidChangeWatchedFiles(ctx context.Context, params *protocol.DidChangeWatchedFilesParams) (err error)
- func (Server) DidChangeWorkspaceFolders(ctx context.Context, params *protocol.DidChangeWorkspaceFoldersParams) (err error)
- func (s *Server) DidClose(ctx context.Context, params *protocol.DidCloseTextDocumentParams) error
- func (Server) DidCreateFiles(ctx context.Context, params *protocol.CreateFilesParams) (err error)
- func (Server) DidDeleteFiles(ctx context.Context, params *protocol.DeleteFilesParams) (err error)
- func (s *Server) DidOpen(ctx context.Context, params *protocol.DidOpenTextDocumentParams) error
- func (Server) DidRenameFiles(ctx context.Context, params *protocol.RenameFilesParams) (err error)
- func (s *Server) DidSave(ctx context.Context, params *protocol.DidSaveTextDocumentParams) error
- func (Server) DocumentColor(ctx context.Context, params *protocol.DocumentColorParams) (result []protocol.ColorInformation, err error)
- 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(ctx context.Context, params *protocol.DocumentLink) (result *protocol.DocumentLink, err error)
- func (Server) DocumentSymbol(ctx context.Context, params *protocol.DocumentSymbolParams) (result []interface{}, err error)
- func (Server) ExecuteCommand(ctx context.Context, params *protocol.ExecuteCommandParams) (result interface{}, err error)
- func (s *Server) Exit(context.Context) error
- func (Server) FoldingRanges(ctx context.Context, params *protocol.FoldingRangeParams) (result []protocol.FoldingRange, err error)
- func (Server) Formatting(ctx context.Context, params *protocol.DocumentFormattingParams) (result []protocol.TextEdit, err error)
- func (Server) Hover(ctx context.Context, params *protocol.HoverParams) (result *protocol.Hover, err error)
- func (Server) Implementation(ctx context.Context, params *protocol.ImplementationParams) (result []protocol.Location, err error)
- func (Server) IncomingCalls(ctx context.Context, params *protocol.CallHierarchyIncomingCallsParams) (result []protocol.CallHierarchyIncomingCall, err error)
- func (s *Server) Initialize(context.Context, *protocol.InitializeParams) (*protocol.InitializeResult, error)
- func (s *Server) Initialized(context.Context, *protocol.InitializedParams) error
- func (Server) LinkedEditingRange(ctx context.Context, params *protocol.LinkedEditingRangeParams) (result *protocol.LinkedEditingRanges, err error)
- func (Server) LogTrace(ctx context.Context, params *protocol.LogTraceParams) (err error)
- func (Server) Moniker(ctx context.Context, params *protocol.MonikerParams) (result []protocol.Moniker, err error)
- func (Server) OnTypeFormatting(ctx context.Context, params *protocol.DocumentOnTypeFormattingParams) (result []protocol.TextEdit, err error)
- func (Server) OutgoingCalls(ctx context.Context, params *protocol.CallHierarchyOutgoingCallsParams) (result []protocol.CallHierarchyOutgoingCall, err error)
- func (Server) PrepareCallHierarchy(ctx context.Context, params *protocol.CallHierarchyPrepareParams) (result []protocol.CallHierarchyItem, err error)
- func (Server) PrepareRename(ctx context.Context, params *protocol.PrepareRenameParams) (result *protocol.Range, err error)
- func (Server) RangeFormatting(ctx context.Context, params *protocol.DocumentRangeFormattingParams) (result []protocol.TextEdit, err error)
- func (Server) References(ctx context.Context, params *protocol.ReferenceParams) (result []protocol.Location, err error)
- func (Server) Rename(ctx context.Context, params *protocol.RenameParams) (result *protocol.WorkspaceEdit, err error)
- func (Server) Request(ctx context.Context, method string, params interface{}) (result interface{}, err error)
- func (Server) SemanticTokensFull(ctx context.Context, params *protocol.SemanticTokensParams) (result *protocol.SemanticTokens, err error)
- func (Server) SemanticTokensFullDelta(ctx context.Context, params *protocol.SemanticTokensDeltaParams) (result interface{}, err error)
- func (Server) SemanticTokensRange(ctx context.Context, params *protocol.SemanticTokensRangeParams) (result *protocol.SemanticTokens, err error)
- func (Server) SemanticTokensRefresh(ctx context.Context) (err error)
- func (s *Server) SetTrace(context.Context, *protocol.SetTraceParams) error
- func (Server) ShowDocument(ctx context.Context, params *protocol.ShowDocumentParams) (result *protocol.ShowDocumentResult, err error)
- func (s *Server) Shutdown(context.Context) error
- func (Server) SignatureHelp(ctx context.Context, params *protocol.SignatureHelpParams) (result *protocol.SignatureHelp, err error)
- func (Server) Symbols(ctx context.Context, params *protocol.WorkspaceSymbolParams) (result []protocol.SymbolInformation, err error)
- func (Server) TypeDefinition(ctx context.Context, params *protocol.TypeDefinitionParams) (result []protocol.Location, err error)
- func (Server) WillCreateFiles(ctx context.Context, params *protocol.CreateFilesParams) (result *protocol.WorkspaceEdit, err error)
- func (Server) WillDeleteFiles(ctx context.Context, params *protocol.DeleteFilesParams) (result *protocol.WorkspaceEdit, err error)
- func (Server) WillRenameFiles(ctx context.Context, params *protocol.RenameFilesParams) (result *protocol.WorkspaceEdit, err error)
- func (Server) WillSave(ctx context.Context, params *protocol.WillSaveTextDocumentParams) (err error)
- func (Server) WillSaveWaitUntil(ctx context.Context, params *protocol.WillSaveTextDocumentParams) (result []protocol.TextEdit, err error)
- func (Server) WorkDoneProgressCancel(ctx context.Context, params *protocol.WorkDoneProgressCancelParams) (err error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Serve ¶
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 ¶
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) CodeLensRefresh ¶
func (Server) CodeLensResolve ¶
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) 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 ¶
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 ¶
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) DidRenameFiles ¶
func (Server) DidRenameFiles(ctx context.Context, params *protocol.RenameFilesParams) (err error)
func (*Server) DidSave ¶
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 ¶
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) FoldingRanges ¶
func (Server) FoldingRanges(ctx context.Context, params *protocol.FoldingRangeParams) (result []protocol.FoldingRange, err error)
func (Server) Formatting ¶
func (Server) Implementation ¶
func (Server) IncomingCalls ¶
func (Server) IncomingCalls(ctx context.Context, params *protocol.CallHierarchyIncomingCallsParams) (result []protocol.CallHierarchyIncomingCall, err error)
func (*Server) Initialize ¶
func (s *Server) Initialize(context.Context, *protocol.InitializeParams) (*protocol.InitializeResult, error)
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) OnTypeFormatting ¶
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) RangeFormatting ¶
func (Server) References ¶
func (Server) Rename ¶
func (Server) Rename(ctx context.Context, params *protocol.RenameParams) (result *protocol.WorkspaceEdit, 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) ShowDocument ¶
func (Server) ShowDocument(ctx context.Context, params *protocol.ShowDocumentParams) (result *protocol.ShowDocumentResult, err 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) 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) WorkDoneProgressCancel ¶
func (Server) WorkDoneProgressCancel(ctx context.Context, params *protocol.WorkDoneProgressCancelParams) (err error)