source

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 3, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

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 view: parsing and file I/O happen in the caller.

Package links computes document links: include paths resolving to their target files. Pure over the view: 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 view: parsing and file I/O happen in the caller.

Index

Constants

This section is empty.

Variables

View Source
var ErrNotParseable = errors.New("document does not parse")

ErrNotParseable is returned by Format when the document has parse errors: it cannot be formatted safely. The Parse checker reports the errors to the client, so callers skip formatting (nil edits) instead of failing the request.

Functions

func Definition

func Definition(ctx context.Context, view *store.View, 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, view *store.View, file uri.URI) []*protocol.DocumentSymbol

DocumentSymbols returns the document symbols of a file, in source order.

func Format

func Format(ctx context.Context, view *store.View, fh store.FileHandle, opts formatter.Options) (string, error)

Format returns the whole-document formatting of fh's content.

func FormatDocument

func FormatDocument(ctx context.Context, view *store.View, fh store.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, view *store.View, fh store.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, view *store.View, 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, view *store.View, 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 Legend

func Legend() []string

Legend returns the semantic token types the server emits.

func Links(ctx context.Context, view *store.View, file uri.URI) []protocol.DocumentLink

Links returns the document links of a file, one per include and cpp_include, targeting the resolved file.

func OnTypeFormat added in v0.1.5

func OnTypeFormat(ctx context.Context, view *store.View, fh store.FileHandle, opts formatter.Options, pos protocol.Position) ([]protocol.TextEdit, error)

OnTypeFormat formats the construct whose closing delimiter was just typed: the whole struct/union/exception/enum/service block reflows. A document that does not parse, or a position outside any construct, formats nothing.

func PrepareRename

func PrepareRename(ctx context.Context, view *store.View, 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

func Ranges(ctx context.Context, view *store.View, file uri.URI) []protocol.FoldingRange

Ranges returns the folding ranges of a file, in source order. Degenerate single-line ranges are omitted.

func Reference

func Reference(ctx context.Context, view *store.View, 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, view *store.View, 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 RenameFileEdits added in v0.1.7

func RenameFileEdits(ctx context.Context, view *store.View, oldURI, newURI uri.URI) (map[uri.URI][]protocol.TextEdit, error)

RenameFileEdits returns, per including file, the edits retargeting every include of oldURI at newURI's location. Only direct includers carry an include literal naming the file; transitive dependents resolve through them and need no edit.

func ToProtocolDiagnostics added in v0.1.8

func ToProtocolDiagnostics(ctx context.Context, view *store.View, file uri.URI, diags []sema.Diagnostic) ([]protocol.Diagnostic, error)

ToProtocolDiagnostics translates one file's pipeline findings into LSP wire diagnostics: spans map through the file's mapper to UTF-16 columns, severities map onto the protocol scale, and the Source field is set here — it is LSP presentation, not core data.

func Tokens

func Tokens(ctx context.Context, view *store.View, file uri.URI) ([]uint32, error)

Tokens returns the delta-encoded semantic tokens of a file, in source order.

func TypeDefinition

func TypeDefinition(ctx context.Context, view *store.View, 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, view *store.View, 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

func ListDirAndFiles(dir string, includePaths []string, prefix string) []Candidate

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 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

	// 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  store.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.

func ResolveContext

func ResolveContext(doc *syntax.Document, pos syntax.Position) Context

ResolveContext classifies the grammar slot at pos. Token-level checks come first (cheap and precise: strings, braces, parens, separators), then the node path, then a CtxKeyword fallback.

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 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, view *store.View, 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, view *store.View, 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 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

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL