Documentation
¶
Index ¶
- type ArrayBuffer
- type Buffer
- type BufferType
- type ClientCapabilities
- type CompletionItem
- type CompletionItemKind
- type CompletionList
- type CompletionOptions
- type CompletionParams
- type DidChangeTextDocumentParams
- type DidCloseTextDocumentParams
- type DidOpenTextDocumentParams
- type Document
- func (d *Document) ApplyChange(change TextDocumentContentChangeEvent) error
- func (d *Document) Bytes() []byte
- func (d *Document) Len() int
- func (d *Document) PositionToOffset(pos Position) (int, error)
- func (d *Document) ReadAt(p []byte, off int64) (n int, err error)
- func (d *Document) Reset(text []byte)
- type DocumentSyncHandler
- type ErrorCode
- type Filesystem
- func (f *Filesystem) DidChangeTextDocument(_ context.Context, params DidChangeTextDocumentParams) error
- func (f *Filesystem) DidCloseTextDocument(_ context.Context, params DidCloseTextDocumentParams) error
- func (f *Filesystem) DidOpenTextDocument(_ context.Context, params DidOpenTextDocumentParams) error
- type GapBuffer
- type Handler
- type Location
- type MarkupContent
- type MarkupKind
- type Position
- type Range
- type ResponseError
- type RopeBuffer
- type Server
- type ServerCapabilities
- type ServerInfo
- type TextDocumentContentChangeEvent
- type TextDocumentIdentifier
- type TextDocumentItem
- type TextDocumentPositionParams
- type TextDocumentSyncKind
- type TextDocumentSyncOptions
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ArrayBuffer ¶
type ArrayBuffer struct {
// contains filtered or unexported fields
}
ArrayBuffer is the simplest implementation of Buffer, using a byte slice for storage. It is optimized for reads. Insertions and deletions are O(n) due to slice copying.
This implementation is not recommended and is mainly used as a testing benchmark baseline for smarter buffer implementations.
type Buffer ¶
type Buffer interface {
io.ReaderAt
io.WriterAt
// Reset reinitializes the buffer with the given text.
Reset(b []byte)
// Bytes returns the full content of the buffer as a byte slice.
Bytes() []byte
// Delete deletes a range of bytes from the buffer.
Delete(start, end int)
// Len returns the number of bytes in the buffer.
Len() int
}
Buffer implements large text storage with methods for random access.
type BufferType ¶
type BufferType int
BufferType represents a buffer implementation.
const ( // BufferTypeDefault chooses a buffer for you. BufferTypeDefault BufferType = iota // BufferTypeGap uses a gap buffer for amortized O(1) insertions and // deletions and fast reads, at the cost of poorer random access. BufferTypeGap // BufferTypeRope uses a rope data structure for efficient random // access and insertions/deletions in large documents. BufferTypeRope )
type ClientCapabilities ¶
type ClientCapabilities struct{}
type CompletionItem ¶
type CompletionItem struct {
Label string `json:"label"`
Kind CompletionItemKind `json:"kind,omitempty"`
Detail string `json:"detail,omitempty"`
Documentation *MarkupContent `json:"documentation,omitempty"`
}
type CompletionItemKind ¶
type CompletionItemKind int
const ( CompletionText CompletionItemKind = 1 CompletionMethod CompletionItemKind = 2 CompletionFunction CompletionItemKind = 3 CompletionConstructor CompletionItemKind = 4 CompletionField CompletionItemKind = 5 CompletionVariable CompletionItemKind = 6 CompletionClass CompletionItemKind = 7 CompletionInterface CompletionItemKind = 8 CompletionModule CompletionItemKind = 9 CompletionProperty CompletionItemKind = 10 CompletionUnit CompletionItemKind = 11 CompletionValue CompletionItemKind = 12 CompletionEnum CompletionItemKind = 13 CompletionKeyword CompletionItemKind = 14 CompletionSnippet CompletionItemKind = 15 CompletionColor CompletionItemKind = 16 CompletionFile CompletionItemKind = 17 CompletionReference CompletionItemKind = 18 CompletionFolder CompletionItemKind = 19 CompletionEnumMember CompletionItemKind = 20 CompletionConstant CompletionItemKind = 21 CompletionStruct CompletionItemKind = 22 CompletionEvent CompletionItemKind = 23 CompletionOperator CompletionItemKind = 24 CompletionTypeParameter CompletionItemKind = 25 )
type CompletionList ¶
type CompletionList struct {
IsIncomplete bool `json:"isIncomplete"`
Items []CompletionItem `json:"items"`
}
type CompletionOptions ¶
type CompletionOptions struct{}
type CompletionParams ¶
type CompletionParams struct {
TextDocumentPositionParams
}
type DidChangeTextDocumentParams ¶
type DidChangeTextDocumentParams struct {
TextDocument TextDocumentIdentifier `json:"textDocument"`
ContentChanges []TextDocumentContentChangeEvent `json:"contentChanges"`
}
type DidCloseTextDocumentParams ¶
type DidCloseTextDocumentParams struct {
TextDocument TextDocumentIdentifier `json:"textDocument"`
}
type DidOpenTextDocumentParams ¶
type DidOpenTextDocumentParams struct {
TextDocument TextDocumentItem `json:"textDocument"`
}
type Document ¶
type Document struct {
// contains filtered or unexported fields
}
Document represents a text document with methods to manipulate its content.
func NewDocument ¶
NewDocument creates a new Document with the given initial text and buffer. If buf is nil, a GapBuffer is used.
func (*Document) ApplyChange ¶
func (d *Document) ApplyChange(change TextDocumentContentChangeEvent) error
ApplyChange applies a content change to the document.
func (*Document) PositionToOffset ¶
PositionToOffset converts a Position (line and character) to a byte offset in the document. It correctly handles UTF-16 character widths.
type DocumentSyncHandler ¶
type DocumentSyncHandler interface {
DidOpenTextDocument(ctx context.Context, params DidOpenTextDocumentParams) error
DidCloseTextDocument(ctx context.Context, params DidCloseTextDocumentParams) error
DidChangeTextDocument(ctx context.Context, params DidChangeTextDocumentParams) error
}
DocumentSyncHandler defines methods for handling document synchronization.
type Filesystem ¶
type Filesystem struct {
Documents map[string]*Document
BufferType BufferType
}
Filesystem can be embedded into handlers in order to implement the basic document sync methods of the LSP.
func (*Filesystem) DidChangeTextDocument ¶
func (f *Filesystem) DidChangeTextDocument(_ context.Context, params DidChangeTextDocumentParams) error
DidChangeTextDocument implements lsp.Handler.
func (*Filesystem) DidCloseTextDocument ¶
func (f *Filesystem) DidCloseTextDocument(_ context.Context, params DidCloseTextDocumentParams) error
DidCloseTextDocument implements lsp.Handler.
func (*Filesystem) DidOpenTextDocument ¶
func (f *Filesystem) DidOpenTextDocument(_ context.Context, params DidOpenTextDocumentParams) error
DidOpenTextDocument implements DocumentSyncHandler.
type GapBuffer ¶
type GapBuffer struct {
// contains filtered or unexported fields
}
GapBuffer implements a gap buffer for amortized O(1) insertions and deletions at the cursor position and O(n) for random access. Its reads are fast compared to RopeBuffer.
type Handler ¶
type Handler interface {
DocumentSyncHandler
Initialize(ctx context.Context, clientCapabilities ClientCapabilities) (*ServerCapabilities, error)
Completion(ctx context.Context, params CompletionParams) (*CompletionList, error)
}
Handler provides the logic for handling LSP requests and notifications.
type Location ¶
https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#location
type MarkupContent ¶
type MarkupContent struct {
Kind MarkupKind `json:"kind"`
Value string `json:"value"`
}
type MarkupKind ¶
type MarkupKind string
const ( MarkupPlainText MarkupKind = "plaintext" MarkupMarkdown MarkupKind = "markdown" )
type Position ¶
https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#position
type Range ¶
https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#range
type ResponseError ¶
type ResponseError struct {
Code ErrorCode `json:"code"`
Message string `json:"message"`
InternalError error `json:"-"`
}
func (*ResponseError) Error ¶
func (e *ResponseError) Error() string
func (*ResponseError) Unwrap ¶
func (e *ResponseError) Unwrap() error
type RopeBuffer ¶
type RopeBuffer struct {
// contains filtered or unexported fields
}
RopeBuffer implements Buffer using a rope data structure. This is best at scale, for large documents with frequent random insertions and deletions.
type Server ¶
Server manages the LSP server lifecycle and dispatching requests and notifications to a handler.
type ServerCapabilities ¶
type ServerCapabilities struct {
TextDocumentSync *TextDocumentSyncOptions `json:"textDocumentSync,omitempty"`
CompletionProvider *CompletionOptions `json:"completionProvider,omitempty"`
HoverProvider bool `json:"hoverProvider,omitempty"`
DefinitionProvider bool `json:"definitionProvider,omitempty"`
ReferencesProvider bool `json:"referencesProvider,omitempty"`
SignatureHelpProvider bool `json:"signatureHelpProvider,omitempty"`
}
type ServerInfo ¶
type TextDocumentContentChangeEvent ¶
type TextDocumentContentChangeEvent struct {
Text string `json:"text"`
Range *Range `json:"range,omitempty"`
}
func (TextDocumentContentChangeEvent) String ¶
func (e TextDocumentContentChangeEvent) String() string
type TextDocumentIdentifier ¶
type TextDocumentIdentifier struct {
URI string `json:"uri"`
}
type TextDocumentItem ¶
type TextDocumentPositionParams ¶
type TextDocumentPositionParams struct {
TextDocument TextDocumentIdentifier `json:"textDocument"`
Position Position `json:"position"`
}
type TextDocumentSyncKind ¶
type TextDocumentSyncKind int
const ( SyncNone TextDocumentSyncKind = 0 SyncFull TextDocumentSyncKind = 1 SyncIncremental TextDocumentSyncKind = 2 )
type TextDocumentSyncOptions ¶
type TextDocumentSyncOptions struct {
OpenClose bool `json:"openClose,omitempty"`
Change TextDocumentSyncKind `json:"change"`
}