Documentation
¶
Overview ¶
Package features provides a searchable catalog of CalcMark features for help systems, autocompletion, and documentation generation.
Index ¶
- func ExtractPrefix(line string, col int) string
- func MatchesPrefix(s string, prefix string) bool
- type Alias
- type Category
- type Feature
- type Registry
- func (r *Registry) All() []Feature
- func (r *Registry) ByCategory(cat Category) []Feature
- func (r *Registry) Categories() []Category
- func (r *Registry) GetByName(name string) *Feature
- func (r *Registry) IdentCallableFunctionNames() []string
- func (r *Registry) NLTriggerKeywords() []string
- func (r *Registry) Search(query string) []Feature
- type Suggestion
- func DateSuggestions(prefix string) []Suggestion
- func DirectiveSuggestions(prefix string, scaleFactor string, globals map[string]string) []Suggestion
- func FilterSuggestions(suggestions []Suggestion, prefix string) []Suggestion
- func FunctionSuggestions(prefix string, implementedNames map[string]bool) []Suggestion
- func UnitSuggestions(prefix string) []Suggestion
- func VariableSuggestions(vars map[string]string, prefix string, cursorLine int, ...) []Suggestion
- type SuggestionSource
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExtractPrefix ¶
ExtractPrefix extracts the completion prefix from a line at the given column. Handles @globals.field patterns and word boundaries. Uses rune-aware indexing for UTF-8 safety.
func MatchesPrefix ¶
MatchesPrefix checks if s starts with prefix (case-insensitive).
Types ¶
type Alias ¶
type Alias struct {
Name string // Alternative name (e.g., "average of", "round trip time")
Parseable bool // true if this alias works as input syntax, false if search-only
Example string // Concrete NL example for autosuggest (e.g., "average of 1, 2, 3")
}
Alias represents an alternative name for a feature, with a flag indicating whether it can be used as input syntax (Parseable) or is search-only.
type Category ¶
type Category string
Category represents a type of CalcMark feature.
const ( CategoryFunction Category = "function" CategoryUnit Category = "unit" CategoryKeyword Category = "keyword" CategoryOperator Category = "operator" CategoryDate Category = "date" CategoryNetwork Category = "network" CategoryStorage Category = "storage" CategoryCompression Category = "compression" CategoryGrowth Category = "growth" CategoryFrontmatter Category = "frontmatter" )
type Feature ¶
type Feature struct {
Name string // Primary name (e.g., "avg", "meter", "today")
Category Category // Type of feature (function, unit, keyword, etc.)
Subcategory string // Grouping within category for help display (e.g., "Math", "Network", "Storage")
Quantity string // Unit category for units (e.g., "Force", "Length"); empty for non-unit features
Syntax string // Usage syntax (e.g., "avg(a, b, c)")
Description string // Human-readable description
Aliases []Alias // Alternative names/spellings
Synonyms []string // Runtime-dispatchable alternative names (e.g., "average", "mean" for "avg")
Params []types.ParamSpec // Parameter specifications for functions (empty for non-functions)
Example string // Example usage (function-call form for help display)
NLExample string // Natural language example for autosuggest (e.g., "100 MB/s over 1 day")
// InsertText is the literal text to insert when the user accepts
// this completion. When empty, suggestion-builders fall back to
// `Name`. Use the LSP `${N:default}` snippet syntax for entries
// that need user-fillable placeholders (e.g., year-bearing date
// literals like `FY${1:NNNN}`). When set, downstream LSP layers
// flag the resulting completion item as InsertTextFormat: Snippet.
InsertText string
}
Feature represents a single CalcMark feature that users can discover.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry holds all discoverable CalcMark features.
func DefaultRegistry ¶
func DefaultRegistry() *Registry
DefaultRegistry returns a shared, read-only Registry instance. Use this for production code; use NewRegistry() in tests that need a fresh instance.
func NewRegistry ¶
func NewRegistry() *Registry
NewRegistry creates a registry with all CalcMark features.
func (*Registry) ByCategory ¶
ByCategory returns all features of a specific category.
func (*Registry) Categories ¶
Categories returns all available category names.
func (*Registry) GetByName ¶
GetByName returns the first feature with the given name, or nil if not found. Returns a copy to prevent mutation of the shared DefaultRegistry() singleton.
func (*Registry) IdentCallableFunctionNames ¶ added in v2.2.1
IdentCallableFunctionNames returns the names of all registered functions that lex as a plain IDENTIFIER (i.e., the lexer does NOT assign them a dedicated `FUNC_*` token). These are the only function names that the document detector needs to treat specially when classifying lines like `name(args)`: built-in functions with dedicated lexer tokens (avg, sum, sqrt, number) already drive the calc verdict via their own token type in `isFunctionToken`, so they are intentionally omitted here.
Names are returned lower-cased to match the case-folding used by the detector and classifier when looking up identifiers.
The detector consults this list (alongside NLTriggerKeywords and doc-defined names) so a line `accumulate(5mb, 1 hour)` — registered function, no dedicated lexer token — admits as a calculation, while `frobnicate(x)` — not registered — is correctly demoted to text.
func (*Registry) NLTriggerKeywords ¶
NLTriggerKeywords returns the set of keywords that begin NL function syntax. These are extracted from parseable aliases: the first word of each alias name (before "...") is the trigger keyword. Both the document detector and the line classifier use this to identify NL function lines without hard-coding.
type Suggestion ¶
type Suggestion struct {
Name string // Display name (may include synonyms for display)
Category string // Category (function, unit, variable, etc.)
Description string // Brief description
Syntax string // Syntax example
InsertText string // Actual text to insert (without synonyms/formatting)
FunctionName string // Canonical function name for spec lookup (set only for function suggestions)
SortCategory string // Override category for sorting (e.g., NL rows use parent fn category)
}
Suggestion represents an autocompletion suggestion. This type is shared between the TUI editor and the LSP server.
func DateSuggestions ¶
func DateSuggestions(prefix string) []Suggestion
DateSuggestions returns date keyword suggestions matching prefix. Surfaces date-related features like "today", "next Friday", "this quarter", "ago", "end of".
func DirectiveSuggestions ¶
func DirectiveSuggestions(prefix string, scaleFactor string, globals map[string]string) []Suggestion
DirectiveSuggestions returns @scale and @globals.field suggestions. scaleFactor is the string representation of the scale factor (empty if no scale). globals maps global names to their values (nil or empty if no globals).
func FilterSuggestions ¶
func FilterSuggestions(suggestions []Suggestion, prefix string) []Suggestion
FilterSuggestions returns suggestions that match the given prefix. This is a pure helper function for suggestion sources.
func FunctionSuggestions ¶
func FunctionSuggestions(prefix string, implementedNames map[string]bool) []Suggestion
FunctionSuggestions returns function suggestions matching prefix. implementedNames filters to only functions that have interpreter implementations. Pass nil to include all registered functions.
func UnitSuggestions ¶
func UnitSuggestions(prefix string) []Suggestion
UnitSuggestions returns unit suggestions matching prefix. Deduplicates by canonical name.
func VariableSuggestions ¶
func VariableSuggestions(vars map[string]string, prefix string, cursorLine int, definedLines map[string]int) []Suggestion
VariableSuggestions returns variable suggestions matching prefix. Filters out variables defined at or after cursorLine when definedLines is provided. vars maps variable names to their formatted display values.
type SuggestionSource ¶
type SuggestionSource interface {
// GetSuggestions returns suggestions matching the given prefix.
GetSuggestions(prefix string) []Suggestion
}
SuggestionSource provides suggestions for a given prefix.