Documentation
¶
Overview ¶
Package lsp serves the Language Server Protocol for TDL: diagnostics, go to definition, hover, document symbols, and formatting.
See docs/design/lsp.md and docs/design/lsp-plan.md.
Index ¶
- func Serve(ctx context.Context, rwc io.ReadWriteCloser, opts ...sema.Option) error
- type Server
- func (s *Server) Definition(_ context.Context, params *protocol.DefinitionParams) (protocol.DefinitionResult, error)
- func (s *Server) DidChange(ctx context.Context, params *protocol.DidChangeTextDocumentParams) error
- func (s *Server) DidClose(ctx context.Context, params *protocol.DidCloseTextDocumentParams) error
- func (s *Server) DidOpen(ctx context.Context, params *protocol.DidOpenTextDocumentParams) error
- func (s *Server) DidSave(ctx context.Context, params *protocol.DidSaveTextDocumentParams) error
- func (s *Server) DocumentSymbol(_ context.Context, params *protocol.DocumentSymbolParams) (protocol.DocumentSymbolResult, error)
- func (s *Server) Exit(context.Context) error
- func (s *Server) Formatting(_ context.Context, params *protocol.DocumentFormattingParams) ([]protocol.TextEdit, error)
- func (s *Server) Hover(_ context.Context, params *protocol.HoverParams) (*protocol.Hover, error)
- func (s *Server) Initialize(context.Context, *protocol.InitializeParams) (*protocol.InitializeResult, error)
- func (s *Server) Initialized(context.Context, *protocol.InitializedParams) error
- func (s *Server) SetTrace(context.Context, *protocol.SetTraceParams) error
- func (s *Server) Shutdown(context.Context) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Server ¶
type Server struct {
protocol.UnimplementedServer
// contains filtered or unexported fields
}
Server answers protocol requests about the documents an editor has open. A request it does not implement gets "method not found" from the embedded protocol.UnimplementedServer.
func NewServer ¶
NewServer returns a server analyzing every document with opts. The server appends its own loader, so an import of an open document resolves to its unsaved text. The client comes from each request's context.
func (*Server) Definition ¶
func (s *Server) Definition(_ context.Context, params *protocol.DefinitionParams) (protocol.DefinitionResult, error)
Definition answers where the name under the cursor was declared, read from the index sema records while it resolves. It returns nothing when the cursor is not on a name, the name did not resolve, or it resolved into the embedded prelude.
func (*Server) DidChange ¶
DidChange replaces a document's text and re-analyzes it. With full sync the last change carries the whole document; a range change was never advertised and is ignored. A change for a file never opened is dropped.
func (*Server) DidClose ¶
DidClose forgets a document and clears what it published. Every other open document is re-analyzed, since an import of this one reads the disk from here on.
func (*Server) DidSave ¶
DidSave re-analyzes, because a file this document imports may have been written by something other than the editor.
func (*Server) DocumentSymbol ¶
func (s *Server) DocumentSymbol(_ context.Context, params *protocol.DocumentSymbolParams) (protocol.DocumentSymbolResult, error)
DocumentSymbol is the outline of a document: each declaration, with its fields and variants as children. It reads the tree, so a file that does not parse still outlines what the parser recovered.
func (*Server) Formatting ¶
func (s *Server) Formatting(_ context.Context, params *protocol.DocumentFormattingParams) ([]protocol.TextEdit, error)
Formatting is `tdl fmt` over the editor's text, returned as one edit replacing the whole document. The client's formatting options are ignored. A file that does not parse is left alone, since printing its tree would delete what the parser could not read.
func (*Server) Hover ¶
Hover describes the name under the cursor: the declaration it refers to in canonical form, its deprecation, and its doc comment. A reference is answered from the index Definition reads, including one into the prelude; a declaration's own name is found in the tree.
func (*Server) Initialize ¶
func (s *Server) Initialize(context.Context, *protocol.InitializeParams) (*protocol.InitializeResult, error)
Initialize reports what this server serves. Text synchronization is full: a .tdl file is small, and incremental sync would add a way for the server's copy to drift from the editor's.