tools

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2026 License: BSD-3-Clause Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyTextEdits

func ApplyTextEdits(ctx context.Context, client *lsp.Client, filePath string, edits []TextEdit) (string, error)

func ExecuteCodeLens

func ExecuteCodeLens(ctx context.Context, client *lsp.Client, filePath string, index int) (string, error)

ExecuteCodeLens executes a specific code lens command from a file.

func ExtractTextFromLocation

func ExtractTextFromLocation(loc protocol.Location) (string, error)

func FindReferences

func FindReferences(ctx context.Context, client *lsp.Client, symbolName string) (string, error)

func FindReferencesAtPosition added in v0.4.2

func FindReferencesAtPosition(ctx context.Context, client *lsp.Client, filePath string, line, column int) (string, error)

FindReferencesAtPosition resolves references for the symbol at the given 1-indexed (line, column) via textDocument/references. Avoids the workspace/symbol fan-out used by FindReferences, so it can disambiguate same-named symbols and won't duplicate the reference set for symbols that have multiple workspace/symbol hits (decl + export + dist copies).

func FormatDocument

func FormatDocument(ctx context.Context, client *lsp.Client, filePath string, mode string, startLine, startCol, endLine, endCol int, triggerChar string) (string, error)

FormatDocument formats a document using the LSP formatting capabilities.

Modes: - "full": Format the entire document (textDocument/formatting) - "range": Format a specific range (textDocument/rangeFormatting) - "ontype": Format on typing a character (textDocument/onTypeFormatting)

For "full" mode, the range parameters are ignored. For "range" mode, startLine/startCol and endLine/endCol define the range. For "ontype" mode, startLine/startCol define the position, and triggerChar is the typed character.

func FormatLinesWithRanges

func FormatLinesWithRanges(lines []string, ranges []LineRange) string

FormatLinesWithRanges formats file content using line ranges

func GetCodeActions

func GetCodeActions(ctx context.Context, client *lsp.Client, filePath string, startLine, startColumn, endLine, endColumn int) (string, error)

GetCodeActions returns available code actions for a range in a file.

func GetCodeLens

func GetCodeLens(ctx context.Context, client *lsp.Client, filePath string) (string, error)

GetCodeLens retrieves code lens hints for a given file location

func GetDiagnosticsForFile

func GetDiagnosticsForFile(ctx context.Context, client *lsp.Client, filePath string, contextLines int, showLineNumbers bool) (string, error)

GetDiagnosticsForFile retrieves diagnostics for a specific file from the language server

func GetDocumentHighlights added in v0.4.3

func GetDocumentHighlights(ctx context.Context, client *lsp.Client, filePath string, line, column int) (string, error)

GetDocumentHighlights returns the highlight ranges for the symbol at the given 1-indexed (line, column), grouped by kind (Read / Write / Text). Each highlight is shown alongside the source line it covers.

func GetDocumentSymbols

func GetDocumentSymbols(ctx context.Context, client *lsp.Client, filePath string) (string, error)

GetDocumentSymbols returns the hierarchical symbol outline of a file

func GetFoldingRanges added in v0.4.3

func GetFoldingRanges(ctx context.Context, client *lsp.Client, filePath string) (string, error)

GetFoldingRanges returns each foldable range in the file as `L<start>-<end>` plus the first line of the covered text. Civet uses whitespace-significant blocks, so this is the primary verification that fold boundaries land on the right lines after the .civet → .ts source map.

func GetFullDefinition

func GetFullDefinition(ctx context.Context, client *lsp.Client, startLocation protocol.Location) (string, protocol.Location, error)

Gets the full code block surrounding the start of the input location

func GetHoverInfo

func GetHoverInfo(ctx context.Context, client *lsp.Client, filePath string, line, column int) (string, error)

GetHoverInfo retrieves hover information (type, documentation) for a symbol at the specified position

func GetImplementation added in v0.4.3

func GetImplementation(ctx context.Context, client *lsp.Client, filePath string, line, column int) (string, error)

GetImplementation resolves implementation locations for the symbol at the given 1-indexed (line, column) via textDocument/implementation. For civet-lsp this exercises interface→class jumps surviving the sourcemap remap.

func GetLineRangesToDisplay

func GetLineRangesToDisplay(ctx context.Context, client *lsp.Client, locations []protocol.Location, totalLines int, contextLines int) (map[int]bool, error)

GetLineRangesToDisplay determines which lines should be displayed for a set of locations. Caches `textDocument/documentSymbol` per URI so a 17k-diagnostic file (civet-lsp on parser.hera with broken types) does one LSP round-trip instead of one-per-location — previously this loop hammered the LSP with N identical documentSymbol RPCs and hung for minutes.

func GetLinkedEditingRange added in v0.4.3

func GetLinkedEditingRange(ctx context.Context, client *lsp.Client, filePath string, line, column int) (string, error)

GetLinkedEditingRange returns the set of ranges that should be edited together with the symbol at the given 1-indexed (line, column). Primary use is JSX open/close tag mirroring. The LSP returns null when no linked-edit region exists at the cursor — that's surfaced explicitly rather than treated as an error.

func GetSelectionRange added in v0.4.3

func GetSelectionRange(ctx context.Context, client *lsp.Client, filePath string, line, column int) (string, error)

GetSelectionRange asks the LSP for the "smart expand" selection ranges containing the given 1-indexed (line, column), then flattens the recursive parent chain outermost-first. Each level is rendered as `L<start>-<end>` plus the first line of the covered text.

LSP takes a list of positions; this tool wraps a single position into a one-element array, which is the only shape that's useful to an agent.

func GetSemanticTokens

func GetSemanticTokens(ctx context.Context, client *lsp.Client, caps *protocol.ServerCapabilities, filePath string) (string, error)

GetSemanticTokens retrieves full semantic tokens for a file and renders them in a human-readable form. Intended primarily as a debug surface for LSP implementors — the full token list is emitted (no truncation) so provider output can be diffed against expectations.

func GetSignatureHelp added in v0.4.3

func GetSignatureHelp(ctx context.Context, client *lsp.Client, filePath string, line, column int, triggerCharacter, triggerKind string, isRetrigger bool) (string, error)

GetSignatureHelp returns the signature(s) and active parameter at the given 1-indexed (line, column). triggerCharacter / triggerKind / isRetrigger are optional and feed into SignatureHelpContext so the LSP can branch on how signature help was invoked (manual vs. trigger char vs. retrigger).

triggerKind values: "invoked" (1, default), "trigger" (2), "content" (3). If triggerCharacter is non-empty, triggerKind defaults to "trigger".

func GetTypeDefinition added in v0.4.3

func GetTypeDefinition(ctx context.Context, client *lsp.Client, filePath string, line, column int) (string, error)

GetTypeDefinition resolves the type-definition location for the symbol at the given 1-indexed (line, column) via textDocument/typeDefinition. For civet-lsp this exercises the TS service's mapping of *type* (not value) back through the sourcemap to the original `.civet`.

func PrepareRename added in v0.4.3

func PrepareRename(ctx context.Context, client *lsp.Client, filePath string, line, column int) (string, error)

PrepareRename probes whether a rename is possible at the given 1-indexed (line, column) and reports the range that would be renamed plus an optional placeholder. The LSP response is one of: Range | { range, placeholder } | { defaultBehavior: true } | null.

func ReadDefinition

func ReadDefinition(ctx context.Context, client *lsp.Client, symbolName string) (string, error)

func ReadDefinitionAtPosition added in v0.4.2

func ReadDefinitionAtPosition(ctx context.Context, client *lsp.Client, filePath string, line, column int) (string, error)

ReadDefinitionAtPosition resolves the definition for the symbol at the given 1-indexed (line, column) via textDocument/definition. Unlike ReadDefinition it does not rely on workspace/symbol, so it can disambiguate same-named symbols by call site and won't surface build-output copies the LSP happens to index.

func RenameSymbol

func RenameSymbol(ctx context.Context, client *lsp.Client, filePath string, line, column int, newName string) (string, error)

RenameSymbol renames a symbol (variable, function, class, etc.) at the specified position It uses the LSP rename functionality to handle all references across files

Types

type LineRange

type LineRange struct {
	Start int
	End   int
}

LineRange represents a continuous range of lines to display

func ConvertLinesToRanges

func ConvertLinesToRanges(linesToShow map[int]bool, totalLines int) []LineRange

ConvertLinesToRanges converts a set of lines to continuous ranges

type TextEdit

type TextEdit struct {
	StartLine int    `json:"startLine" jsonschema:"required,description=Start line to replace, inclusive"`
	EndLine   int    `json:"endLine" jsonschema:"required,description=End line to replace, inclusive"`
	NewText   string `json:"newText" jsonschema:"description=Replacement text. Replace with the new text. Leave blank to remove lines."`
}

Jump to

Keyboard shortcuts

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