Documentation
¶
Overview ¶
Package folding computes document folding ranges: braced bodies (structs, enums, services), const list and map values, annotations, and comment blocks. Pure over the snapshot: parsing and file I/O happen in the caller.
Package links computes document links: include paths resolving to their target files. Pure over the snapshot: parsing and file I/O happen in the caller.
Package semantic computes LSP semantic tokens for a thrift document: keywords, types, definition names, comments, strings, and numbers. Pure over the snapshot: parsing and file I/O happen in the caller.
Index ¶
- func Definition(ctx context.Context, ss *cache.Snapshot, file uri.URI, pos protocol.Position) (res []protocol.Location, err error)
- func DocumentSymbols(ctx context.Context, ss *cache.Snapshot, file uri.URI) []*protocol.DocumentSymbol
- func FindConstValueDefinition(ctx context.Context, ss *cache.Snapshot, file uri.URI, ast *syntax.Document, ...) (uri.URI, *syntax.Identifier, error)
- func FindServiceDefinition(ctx context.Context, ss *cache.Snapshot, file uri.URI, ast *syntax.Document, ...) (uri.URI, *syntax.Identifier, error)
- func Format(ctx context.Context, ss *cache.Snapshot, fh cache.FileHandle, ...) (string, error)
- func FormatDocument(ctx context.Context, ss *cache.Snapshot, fh cache.FileHandle, ...) (*protocol.TextEdit, error)
- func FormatDocumentAction(ctx context.Context, ss *cache.Snapshot, fh cache.FileHandle, ...) (*protocol.CodeAction, error)
- func FormatRange(ctx context.Context, ss *cache.Snapshot, fh cache.FileHandle, ...) ([]protocol.TextEdit, error)
- func Highlight(ctx context.Context, ss *cache.Snapshot, file uri.URI, pos protocol.Position) ([]protocol.DocumentHighlight, error)
- func Hover(ctx context.Context, ss *cache.Snapshot, file uri.URI, pos protocol.Position) (res string, err error)
- func IsBasicType(t string) bool
- func Legend() []string
- func Links(ctx context.Context, ss *cache.Snapshot, file uri.URI) []protocol.DocumentLink
- func PrepareRename(ctx context.Context, ss *cache.Snapshot, file uri.URI, pos protocol.Position) (res *protocol.Range, err error)
- func Ranges(ctx context.Context, ss *cache.Snapshot, file uri.URI) []protocol.FoldingRange
- func Reference(ctx context.Context, ss *cache.Snapshot, file uri.URI, pos protocol.Position) (res []protocol.Location, err error)
- func Rename(ctx context.Context, ss *cache.Snapshot, file uri.URI, pos protocol.Position, ...) (res *protocol.WorkspaceEdit, err error)
- func Tokens(ctx context.Context, ss *cache.Snapshot, file uri.URI) ([]uint32, error)
- func TypeDefinition(ctx context.Context, ss *cache.Snapshot, file uri.URI, pos protocol.Position) (res []protocol.Location, err error)
- func WorkspaceSymbols(ctx context.Context, ss *cache.Snapshot, files []uri.URI, query string, ...) []protocol.SymbolInformation
- type Candidate
- type Checker
- type CompletionItem
- type CompletionRequest
- type Context
- type ContextKind
- type CycleCheck
- type CyclePair
- type DefinitionKind
- type Diagnostic
- type DiagnosticResult
- type FieldIDCheck
- type Include
- type Interface
- type Parse
- type Provider
- type SemanticAnalysis
- type TargetKind
- type TokenCompletion
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Definition ¶
func Definition(ctx context.Context, ss *cache.Snapshot, file uri.URI, pos protocol.Position) (res []protocol.Location, err error)
Definition returns the locations of the definition under the cursor: a type reference, a constant value identifier, or a service reference.
func DocumentSymbols ¶
func DocumentSymbols(ctx context.Context, ss *cache.Snapshot, file uri.URI) []*protocol.DocumentSymbol
DocumentSymbols returns the document symbols of a file, in source order.
func FindConstValueDefinition ¶
func FindConstValueDefinition(ctx context.Context, ss *cache.Snapshot, file uri.URI, ast *syntax.Document, value *syntax.ConstValue) (uri.URI, *syntax.Identifier, error)
FindConstValueDefinition resolves a constant value identifier to its definition: an enum value or a const, possibly in an included file.
func FindServiceDefinition ¶
func FindServiceDefinition(ctx context.Context, ss *cache.Snapshot, file uri.URI, ast *syntax.Document, ident *syntax.Identifier) (uri.URI, *syntax.Identifier, error)
FindServiceDefinition resolves a service name or extends reference to the service definition.
func Format ¶
func Format(ctx context.Context, ss *cache.Snapshot, fh cache.FileHandle, opts formatter.Options) (string, error)
Format returns the whole-document formatting of fh's content.
func FormatDocument ¶
func FormatDocument(ctx context.Context, ss *cache.Snapshot, fh cache.FileHandle, opts formatter.Options) (*protocol.TextEdit, error)
FormatDocument returns the single text edit replacing the whole document with its formatted content. It returns nil when the document is already formatted.
func FormatDocumentAction ¶
func FormatDocumentAction(ctx context.Context, ss *cache.Snapshot, fh cache.FileHandle, opts formatter.Options) (*protocol.CodeAction, error)
FormatDocumentAction returns the source.fixAll code action that formats the document, mirroring the formatting request. It returns nil when the document is already formatted.
func FormatRange ¶
func FormatRange(ctx context.Context, ss *cache.Snapshot, fh cache.FileHandle, opts formatter.Options, rng protocol.Range) ([]protocol.TextEdit, error)
FormatRange implements textDocument/rangeFormatting.
The formatter only knows how to print whole documents, so a range is formatted by formatting the whole document and diffing it against the original at the granularity of blank-line-separated blocks. Blank lines are preserved exactly by the formatter, so the blocks align one-to-one; every edit is bounded by blank lines or file edges, and any subset splices safely. Only the edits overlapping the selection are returned.
func Highlight ¶
func Highlight(ctx context.Context, ss *cache.Snapshot, file uri.URI, pos protocol.Position) ([]protocol.DocumentHighlight, error)
Highlight returns the references of the identifier at pos within the same file, for document highlighting. The identifier itself is always included, so the cursor word stays highlighted.
func Hover ¶
func Hover(ctx context.Context, ss *cache.Snapshot, file uri.URI, pos protocol.Position) (res string, err error)
Hover returns the formatted definition under the cursor: a type reference, a constant value identifier, or a service reference.
func IsBasicType ¶
IsBasicType reports whether t is a built-in base type.
func Links ¶
Links returns the document links of a file, one per include and cpp_include, targeting the resolved file.
func PrepareRename ¶
func PrepareRename(ctx context.Context, ss *cache.Snapshot, file uri.URI, pos protocol.Position) (res *protocol.Range, err error)
PrepareRename returns the range of the identifier under the cursor when renaming is supported: definition names, const values, and services.
func Ranges ¶
Ranges returns the folding ranges of a file, in source order. Degenerate single-line ranges are omitted.
func Reference ¶
func Reference(ctx context.Context, ss *cache.Snapshot, file uri.URI, pos protocol.Position) (res []protocol.Location, err error)
Reference returns the locations of all references to the definition under the cursor: type definitions, constant values, enum values, and services.
func Rename ¶
func Rename(ctx context.Context, ss *cache.Snapshot, file uri.URI, pos protocol.Position, newName string) (res *protocol.WorkspaceEdit, err error)
Rename renames the definition under the cursor and all its references, preserving include qualifiers on qualified references (user.Test becomes user.newtext, not newtext).
func TypeDefinition ¶
func TypeDefinition(ctx context.Context, ss *cache.Snapshot, file uri.URI, pos protocol.Position) (res []protocol.Location, err error)
TypeDefinition returns the definition of the type of the declaration under the cursor: for a type reference, the type's definition; for a field, function, typedef, or const name, the definition of its declared type.
func WorkspaceSymbols ¶
func WorkspaceSymbols(ctx context.Context, ss *cache.Snapshot, files []uri.URI, query string, maxResults int) []protocol.SymbolInformation
WorkspaceSymbols returns the workspace symbols matching query among the given files: every top-level definition and its members, files ordered by URI, symbols in source order. An empty query matches everything; the result is capped at maxResults (0 means unlimited). Matching is case-insensitive substring on the symbol name.
Types ¶
type Candidate ¶
type Candidate struct {
// contains filtered or unexported fields
}
Candidate is a single completion entry before LSP conversion.
func ListDirAndFiles ¶
ListDirAndFiles lists the entries matching the typed include path prefix, one level deep, under the current file's directory and every configured include path root. Directories are returned with a trailing slash; only .thrift files are returned. Results are deduplicated across roots.
type Checker ¶
type Checker interface {
Diagnostic(ctx context.Context, ss *cache.Snapshot, changeFiles []uri.URI) (DiagnosticResult, error)
Name() string
}
func NewDiagnostic ¶
func NewDiagnostic() Checker
type CompletionItem ¶
type CompletionItem struct {
// Label holds the primary text user sees
Label string
// Detail a human-readable string with additional information
// about this item, like type or symbol information.
Detail string
// InsertText holds the text to insert when user selects this completion.
// It may be same with Label
InsertText string
InsertTextFormat protocol.InsertTextFormat
Kind protocol.CompletionItemKind
Deprecated bool
Score int
// Documentation holds document text for this completion
Documentation string
}
func BuildCompletionItem ¶
func BuildCompletionItem(candidate Candidate) *CompletionItem
type CompletionRequest ¶
type CompletionRequest struct {
TriggerKind int
Pos types.Position
Fh cache.FileHandle
}
type Context ¶
type Context struct {
Kind ContextKind
Path []syntax.Node // SearchNodePathByPosition result; annotations stay opaque
Offset int // byte offset of the cursor in the document
// Prefix is the text to filter candidates against (the typed path
// inside quotes for include/annotation slots), and EditStart the byte
// offset where the completion edit range starts.
Prefix string
EditStart int
Doc *syntax.Document
}
Context is the resolved grammar slot at the cursor.
type ContextKind ¶
type ContextKind uint8
ContextKind classifies the grammar slot the cursor sits in. Providers are selected by slot, so a cursor on a field name never suggests value candidates and a cursor in an include literal never suggests keywords.
const ( CtxNone ContextKind = iota CtxIncludePath // inside an include/cpp_include string literal CtxType // any type reference slot: field/return/arg/throws/typedef/const/map<k,v> CtxFieldName // struct/union/exception field, argument, or throws member name CtxFieldID // field id slot (before ':') CtxFieldValue // after '=' in a field or const CtxEnumValueName // enum member name slot CtxDefinitionName // top-level definition name (struct/enum/service/typedef/const) CtxFunctionName // service function name slot CtxServiceExtends // after 'extends' CtxAnnotationKey // inside ( ... ) — annotation name position CtxAnnotationValue // inside an annotation value string literal CtxKeyword // no structural slot: keywords + identifiers )
type CycleCheck ¶
type CycleCheck struct{}
func (*CycleCheck) Diagnostic ¶
func (c *CycleCheck) Diagnostic(ctx context.Context, ss *cache.Snapshot, changeFiles []uri.URI) (DiagnosticResult, error)
func (*CycleCheck) Name ¶
func (c *CycleCheck) Name() string
type DefinitionKind ¶
type DefinitionKind uint8
DefinitionKind identifies the kind of a resolved definition.
const ( DefinitionNone DefinitionKind = iota DefinitionStruct DefinitionUnion DefinitionException DefinitionEnum DefinitionTypedef DefinitionConst DefinitionEnumValue DefinitionService )
func FindTypeDefinition ¶
func FindTypeDefinition(ctx context.Context, ss *cache.Snapshot, file uri.URI, ast *syntax.Document, ft *syntax.FieldType) (uri.URI, *syntax.Identifier, DefinitionKind, error)
FindTypeDefinition resolves a type reference to its definition: an exception, struct, enum, union, or typedef, possibly in an included file.
type Diagnostic ¶
type Diagnostic struct{}
func (*Diagnostic) Diagnostic ¶
func (d *Diagnostic) Diagnostic(ctx context.Context, ss *cache.Snapshot, changeFiles []uri.URI) (DiagnosticResult, error)
func (*Diagnostic) Name ¶
func (d *Diagnostic) Name() string
type DiagnosticResult ¶
type DiagnosticResult map[uri.URI][]protocol.Diagnostic
type FieldIDCheck ¶
type FieldIDCheck struct{}
func (*FieldIDCheck) Diagnostic ¶
func (c *FieldIDCheck) Diagnostic(ctx context.Context, ss *cache.Snapshot, changeFiles []uri.URI) (DiagnosticResult, error)
FieldIDCheck checks struct, union, exception, function parameter, and throws field ids: they must be unique positive integers in [1, 32767].
func (*FieldIDCheck) Name ¶
func (c *FieldIDCheck) Name() string
type Interface ¶
type Interface interface {
// Completion returns the completion items for the request, the edit
// range, and whether the list was truncated by the item cap (the LSP
// isIncomplete flag).
Completion(ctx context.Context, ss *cache.Snapshot, cmp *CompletionRequest) ([]*CompletionItem, protocol.Range, bool, error)
}
var DefaultTokenCompletion Interface = &TokenCompletion{}
type Provider ¶
type Provider interface {
Kind() ContextKind
// Candidates returns unfiltered candidates for the slot. The current
// context carries the prefix and the document.
Candidates(ctx context.Context, ss *cache.Snapshot, file uri.URI, c Context) []Candidate
}
Provider supplies completion candidates for one grammar slot. Prefix filtering, sorting, the edit range, and the item cap stay in the shared pipeline (TokenCompletion.Completion).
type SemanticAnalysis ¶
type SemanticAnalysis struct{}
func (*SemanticAnalysis) Diagnostic ¶
func (s *SemanticAnalysis) Diagnostic(ctx context.Context, ss *cache.Snapshot, changeFiles []uri.URI) (DiagnosticResult, error)
func (*SemanticAnalysis) Name ¶
func (s *SemanticAnalysis) Name() string
type TargetKind ¶
type TargetKind uint8
TargetKind classifies what the cursor is on.
const ( // TargetNone is a position with no relevant target. TargetNone TargetKind = iota // TargetTypeName is a type reference (a field/return/typedef type). TargetTypeName // TargetConstValue is an identifier in a constant value position. TargetConstValue // TargetService is a service name or an extends reference. TargetService // TargetDefinition is a definition name: struct, enum, const, typedef, // field, function, enum value, and so on. TargetDefinition )
type TokenCompletion ¶
type TokenCompletion struct{}
TokenCompletion is the slot-based completion entry point. It resolves the grammar slot at the cursor, asks the providers for that slot, then filters, sorts, and caps the candidates.
func (*TokenCompletion) Completion ¶
func (c *TokenCompletion) Completion(ctx context.Context, ss *cache.Snapshot, cmp *CompletionRequest) ([]*CompletionItem, protocol.Range, bool, error)
Completion resolves the grammar slot at the cursor and returns the candidates for that slot, the edit range, and whether the list was truncated by the cap.
Source Files
¶
- completion_utils.go
- context.go
- cycle_detect.go
- definition.go
- diagnostic.go
- document.go
- fieldid_check.go
- folding.go
- format.go
- hits.go
- hover.go
- links.go
- name.go
- parse.go
- provider.go
- reference.go
- rename.go
- semantic.go
- semantic_analysis.go
- semantic_based_completion.go
- semantic_completion.go
- target.go
- token_completion.go
- type_definition.go
- types.go
- utils.go
- workspace.go