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 ¶
- Constants
- 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 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 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 MakeAddMissingIncludeAction(ctx context.Context, ss *cache.Snapshot, fh cache.FileHandle, ...) (*protocol.CodeAction, error)
- func MakeEnumValuesExplicitAction(ctx context.Context, ss *cache.Snapshot, fh cache.FileHandle, ...) (*protocol.CodeAction, error)
- func MakeFieldQualifierAction(ctx context.Context, ss *cache.Snapshot, fh cache.FileHandle, ...) ([]protocol.CodeAction, error)
- func MakeRemoveUnusedIncludeAction(ctx context.Context, ss *cache.Snapshot, fh cache.FileHandle, ...) (*protocol.CodeAction, error)
- 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 RangesOverlap(a, b protocol.Range) bool
- func Reference(ctx context.Context, ss *cache.Snapshot, file uri.URI, pos protocol.Position) ([]protocol.Location, 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 DuplicateCheck
- type EnumValueCheck
- type FieldIDCheck
- type Hit
- type Include
- type Index
- func (x *Index) FindInWorkspace(ctx context.Context, name string) (*Resolved, error)
- func (x *Index) References(ctx context.Context, file uri.URI, name string, kinds ...cache.RefKind) ([]Hit, error)
- func (x *Index) ReferencesTo(ctx context.Context, def *Resolved, kinds ...cache.RefKind) ([]Hit, error)
- func (x *Index) ReferencingFiles(file uri.URI) []uri.URI
- func (x *Index) ResolveService(ctx context.Context, from *cache.ParsedFile, ident *syntax.Identifier) (*Resolved, error)
- func (x *Index) ResolveType(ctx context.Context, from *cache.ParsedFile, ft *syntax.FieldType) (*Resolved, error)
- func (x *Index) ResolveValue(ctx context.Context, from *cache.ParsedFile, v *syntax.ConstValue) (*Resolved, error)
- type Interface
- type Parse
- type Provider
- type Resolved
- type SemanticAnalysis
- type TargetKind
- type TokenCompletion
- type UnusedIncludeCheck
Constants ¶
const ( CodeParseError = "parse-error" CodeIncludeCycle = "include-cycle" CodeFieldIDRange = "field-id-range" CodeFieldIDConflict = "field-id-conflict" CodeDuplicateDef = "duplicate-definition" CodeDuplicateEnumVal = "duplicate-enum-value" CodeDuplicateValue = "duplicate-value" CodeImplicitEnumValue = "implicit-enum-value" CodeUnusedInclude = "unused-include" CodeUndefinedType = "undefined-type" CodeUndefinedValue = "undefined-value" CodeValueTypeMismatch = "value-type-mismatch" CodeNonScalarMapKey = "non-scalar-map-key" )
Diagnostic codes carried on every diagnostic thrift-ls publishes. Code actions match on these — never on the message text, which is free to change.
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 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 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 document highlight ranges for the symbol at pos.
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 MakeAddMissingIncludeAction ¶ added in v0.1.2
func MakeAddMissingIncludeAction(ctx context.Context, ss *cache.Snapshot, fh cache.FileHandle, rng protocol.Range, diags []protocol.Diagnostic) (*protocol.CodeAction, error)
MakeAddMissingIncludeAction returns the quickfix that adds an include of the file defining a type flagged "field type doesn't exist" on the selection. The definition is searched in every thrift file under the workspace folder, so the fix works across the whole project. It returns nil when the selection has no such diagnostic, the referenced type is not found anywhere, or the current file cannot be edited (parse errors).
func MakeEnumValuesExplicitAction ¶ added in v0.1.2
func MakeEnumValuesExplicitAction(ctx context.Context, ss *cache.Snapshot, fh cache.FileHandle, rng protocol.Range) (*protocol.CodeAction, error)
MakeEnumValuesExplicitAction returns the code action that appends an explicit value to every member of the enum under rng, mirroring the auto-incremented constants the compiler would assign: 0 for the first member, one greater than the preceding member's value otherwise.
It returns nil when the selection is outside every enum, the enum is already fully explicit, the implicit values cannot be computed (an unparseable explicit constant), or the document has parse errors.
func MakeFieldQualifierAction ¶ added in v0.1.2
func MakeRemoveUnusedIncludeAction ¶ added in v0.1.2
func MakeRemoveUnusedIncludeAction(ctx context.Context, ss *cache.Snapshot, fh cache.FileHandle, rng protocol.Range, diags []protocol.Diagnostic) (*protocol.CodeAction, error)
MakeRemoveUnusedIncludeAction returns the quickfix that deletes the include line for an "unused include" diagnostic on the selection. It returns nil when no such diagnostic overlaps the selection.
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 RangesOverlap ¶ added in v0.1.2
RangesOverlap reports whether two ranges share at least one position, degenerate single-point ranges included: a cursor at either endpoint of a diagnostic's range counts as overlapping it.
func Reference ¶
func Reference(ctx context.Context, ss *cache.Snapshot, file uri.URI, pos protocol.Position) ([]protocol.Location, error)
Reference returns every usage of the symbol at pos, including usage in files that include the definition.
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
// Documentation holds document text for this completion
Documentation string
}
func BuildCompletionItem ¶
func BuildCompletionItem(candidate Candidate) *CompletionItem
type CompletionRequest ¶
type CompletionRequest struct {
Pos protocol.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 )
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 DuplicateCheck ¶ added in v0.1.2
type DuplicateCheck struct{}
DuplicateCheck reports the duplicates the compiler rejects: a name defined twice in one scope — structs, unions, exceptions, enums, members, fields, function arguments, service functions, typedefs, constants — enum members whose resolved value collides, and map keys or set values that repeat in a constant. Duplicates are ambiguous on the wire and in generated code, so they are errors.
func (*DuplicateCheck) Diagnostic ¶ added in v0.1.2
func (c *DuplicateCheck) Diagnostic(ctx context.Context, ss *cache.Snapshot, changeFiles []uri.URI) (DiagnosticResult, error)
func (*DuplicateCheck) Name ¶ added in v0.1.2
func (c *DuplicateCheck) Name() string
type EnumValueCheck ¶ added in v0.1.2
type EnumValueCheck struct{}
func (*EnumValueCheck) Diagnostic ¶ added in v0.1.2
func (c *EnumValueCheck) Diagnostic(ctx context.Context, ss *cache.Snapshot, changeFiles []uri.URI) (DiagnosticResult, error)
EnumValueCheck warns on enum members that lack an explicit value.
The compiler auto-increments implicit members: 0 for the first member, one greater than the preceding member's value otherwise. Their on-wire value therefore follows their position; inserting, removing, or reordering members silently changes serialized data.
func (*EnumValueCheck) Name ¶ added in v0.1.2
func (c *EnumValueCheck) Name() string
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 Hit ¶ added in v0.1.2
type Hit struct {
File uri.URI
Range protocol.Range
Text string // as written: "User", "shared.User", "shared.thrift.User"
// Kind is the grammar slot the reference sits in, so callers can tell
// type hits from value hits (e.g. for highlight kinds).
Kind cache.RefKind
}
Hit is one reference occurrence of a name, with the qualifying text preserved so a rename can rewrite includes correctly.
type Index ¶ added in v0.1.2
type Index struct {
// contains filtered or unexported fields
}
Index answers cross-file semantic queries over one snapshot: definition resolution and reference search. It composes per-file cache.FileIndexes over the include graph.
An Index is cheap — construct one per request with NewIndex.
func (*Index) FindInWorkspace ¶ added in v0.1.2
FindInWorkspace returns the definition of name in any known file of the workspace, falling back to a directory walk when the workspace has not been indexed yet (e.g. a quick-fix on the first didOpen).
func (*Index) References ¶ added in v0.1.2
func (x *Index) References(ctx context.Context, file uri.URI, name string, kinds ...cache.RefKind) ([]Hit, error)
References returns every occurrence of name in file and in every file that transitively includes it, restricted to the given reference kinds. The definition site is not included (no self-referencing hit). Hits are matched by bare name only; use ReferencesTo for resolution-matched results.
func (*Index) ReferencesTo ¶ added in v0.1.4
func (x *Index) ReferencesTo(ctx context.Context, def *Resolved, kinds ...cache.RefKind) ([]Hit, error)
ReferencesTo returns every reference to def: in def.File and every file that transitively includes it. Hits are name- and resolution-matched, so same-named definitions elsewhere are not reported.
For an enum def, value references qualified with the enum name ("Color.RED", "shared.Color.RED") are matched too, provided the qualifier resolves to this very enum; the hit covers only the enum segment, so a rename rewrites the qualifier while keeping the member name.
func (*Index) ReferencingFiles ¶ added in v0.1.2
ReferencingFiles returns every file that directly includes file, in graph order.
func (*Index) ResolveService ¶ added in v0.1.2
func (x *Index) ResolveService(ctx context.Context, from *cache.ParsedFile, ident *syntax.Identifier) (*Resolved, error)
ResolveService resolves a service name or extends reference, or returns nil when unresolved.
func (*Index) ResolveType ¶ added in v0.1.2
func (x *Index) ResolveType(ctx context.Context, from *cache.ParsedFile, ft *syntax.FieldType) (*Resolved, error)
ResolveType resolves a type reference to its definition, or returns nil when unresolved (base types, unresolvable name). parseDefinitionFile errors are propagated.
func (*Index) ResolveValue ¶ added in v0.1.2
func (x *Index) ResolveValue(ctx context.Context, from *cache.ParsedFile, v *syntax.ConstValue) (*Resolved, error)
ResolveValue resolves a const-value identifier to its definition (an enum value or a const), or returns nil when unresolved.
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 {
// 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 Resolved ¶ added in v0.1.2
type Resolved struct {
File uri.URI
Parsed *cache.ParsedFile
// Name is the definition's identifier node, whose range is the jump
// target.
Name *syntax.Identifier
// Node is the definition itself: *syntax.Struct, *syntax.Enum, etc.
// For an enum value, Node is the *syntax.Identifier (same as Name).
Node syntax.Node
Kind DefinitionKind
}
Resolved is a resolved definition: the target file, the parsed document, the definition identifier (jump target), and its kind.
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.
type UnusedIncludeCheck ¶ added in v0.1.2
type UnusedIncludeCheck struct{}
UnusedIncludeCheck reports an include no reference in the file resolves into. Unused includes bloat the compile and make the dependency graph look worse than it is.
func (*UnusedIncludeCheck) Diagnostic ¶ added in v0.1.2
func (c *UnusedIncludeCheck) Diagnostic(ctx context.Context, ss *cache.Snapshot, changeFiles []uri.URI) (DiagnosticResult, error)
func (*UnusedIncludeCheck) Name ¶ added in v0.1.2
func (c *UnusedIncludeCheck) Name() string
Source Files
¶
- codes.go
- completion_utils.go
- context.go
- cycle_detect.go
- definition.go
- diagnostic.go
- document.go
- duplicate_check.go
- enum_value_action.go
- enum_value_check.go
- field_qualifier_action.go
- fieldid_check.go
- folding.go
- format.go
- hover.go
- include_action.go
- index.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
- unused_include_check.go
- utils.go
- workspace.go