languageservices

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2026 License: Apache-2.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ReasonCodeResourceDefUnknownField         = "resource_def_unknown_field"
	ReasonCodeResourceDefMissingRequiredField = "resource_def_missing_required_field"
	ReasonCodeResourceDefNotAllowedValue      = "resource_def_not_allowed_value"
	ReasonCodeMissingVersion                  = "missing_version"
	ReasonCodeVariableValidationErrors        = "variable_validation_errors"
)

Reason codes for quick fixes

View Source
const (
	DiagnosticCodeDuplicateKey = "duplicate-key"
	DiagnosticSourceSyntax     = "blueprint-syntax"
)
View Source
const (
	// CompletionColumnLeeway is the number of columns to allow for leeway
	// when determining if a position is within a range.
	// This accounts for the case when a completion trigger character such
	// as "." is not a change that leads to succesfully parsing the source,
	// meaning the range end positions in the schema tree are not updated.
	CompletionColumnLeeway = 2
)

Variables

This section is empty.

Functions

func DuplicateKeysToDiagnostics added in v0.2.0

func DuplicateKeysToDiagnostics(result *docmodel.DuplicateKeyResult) []lsp.Diagnostic

DuplicateKeysToDiagnostics converts duplicate key detection results to LSP diagnostics.

Types

type ChildBlueprintInfo added in v0.2.0

type ChildBlueprintInfo struct {
	Blueprint *schema.Blueprint
	Exports   map[string]*ChildExportInfo
	FilePath  string
}

ChildBlueprintInfo holds the resolved child blueprint and its export information.

type ChildBlueprintResolver added in v0.2.0

type ChildBlueprintResolver struct {
	// contains filtered or unexported fields
}

ChildBlueprintResolver resolves child blueprint include paths, loads and parses child blueprints from disk, caches the results, and provides export info for completions and future hover features.

func NewChildBlueprintResolver added in v0.2.0

func NewChildBlueprintResolver(logger *zap.Logger) *ChildBlueprintResolver

NewChildBlueprintResolver creates a new resolver for child blueprints.

func (*ChildBlueprintResolver) InvalidateByURI added in v0.2.0

func (r *ChildBlueprintResolver) InvalidateByURI(uri string)

InvalidateByURI removes cached entries that may be affected by a document change.

func (*ChildBlueprintResolver) ResolveChildExports added in v0.2.0

func (r *ChildBlueprintResolver) ResolveChildExports(
	parentDocURI string,
	include *schema.Include,
) *ChildBlueprintInfo

ResolveChildExports resolves and returns the export info for a child blueprint. Returns nil if the child blueprint cannot be resolved.

func (*ChildBlueprintResolver) ResolveIncludePath added in v0.2.0

func (r *ChildBlueprintResolver) ResolveIncludePath(
	parentDocURI string,
	include *schema.Include,
) string

ResolveIncludePath resolves an include path to an absolute filesystem path. Returns an empty string if the path cannot be resolved (remote includes, unresolvable substitutions, or missing parent directory).

type ChildExportInfo added in v0.2.0

type ChildExportInfo struct {
	Name        string
	Type        schema.ExportType
	Description string
	Field       string
}

ChildExportInfo holds export information for a single child blueprint export.

type CodeActionService added in v0.2.0

type CodeActionService struct {
	// contains filtered or unexported fields
}

CodeActionService provides functionality for generating LSP code actions (quick fixes) from enhanced diagnostics.

func NewCodeActionService added in v0.2.0

func NewCodeActionService(
	state *State,
	logger *zap.Logger,
) *CodeActionService

NewCodeActionService creates a new service for generating code actions.

func (*CodeActionService) GetCodeActions added in v0.2.0

func (s *CodeActionService) GetCodeActions(
	params *lsp.CodeActionParams,
) ([]lsp.CodeAction, error)

GetCodeActions returns code actions for the given document and range. It filters enhanced diagnostics by the requested range and generates appropriate quick fix actions based on the diagnostic metadata.

type CompletionFormatter added in v0.2.0

type CompletionFormatter interface {
	// FormatValue formats a value for insertion (handles quoting, spacing).
	// hasLeadingQuote indicates the user already typed an opening quote.
	// hasLeadingSpace indicates there's whitespace before the cursor.
	FormatValue(value string, hasLeadingQuote bool, hasLeadingSpace bool) string

	// FormatKey formats a key/field name for insertion (adds colon, quotes as needed).
	// Returns the text to insert for a field name completion.
	FormatKey(keyName string) string

	// FormatArrayItem formats an array item value for insertion.
	FormatArrayItem(value string) string

	// GetInsertRange calculates the insertion range based on typed prefix length.
	GetInsertRange(position *lsp.Position, prefixLen int) *lsp.Range

	// NeedsQuoting returns whether a value needs quoting in this format.
	NeedsQuoting(value string) bool

	// GetFormat returns the document format this formatter handles.
	GetFormat() docmodel.DocumentFormat
}

CompletionFormatter handles format-specific completion item formatting. It abstracts the differences between YAML and JSONC completion item generation.

func NewCompletionFormatter added in v0.2.0

func NewCompletionFormatter(format docmodel.DocumentFormat) CompletionFormatter

NewCompletionFormatter creates the appropriate formatter for a document format.

type CompletionResult added in v0.2.0

type CompletionResult struct {
	Items []*lsp.CompletionItem
	// IsIncomplete indicates whether the completion list should be marked as incomplete.
	// When true, the client will re-request completions on each keystroke for server-side filtering.
	// This is needed for substitution contexts where client-side filtering doesn't work reliably.
	IsIncomplete bool
}

CompletionResult contains the completion items and metadata for the response.

type CompletionService

type CompletionService struct {
	// contains filtered or unexported fields
}

CompletionService is a service that provides functionality for completion suggestions.

func NewCompletionService

func NewCompletionService(
	resourceRegistry resourcehelpers.Registry,
	dataSourceRegistry provider.DataSourceRegistry,
	customVarTypeRegistry provider.CustomVariableTypeRegistry,
	functionRegistry provider.FunctionRegistry,
	childResolver *ChildBlueprintResolver,
	state *State,
	logger *zap.Logger,
) *CompletionService

NewCompletionService creates a new service for completion suggestions.

func (*CompletionService) GetCompletionItems

GetCompletionItems returns completion items for a given position in a document. Uses DocumentContext for position resolution with tree-sitter based AST analysis. Returns a CompletionResult with items and metadata (IsIncomplete flag for substitution contexts).

func (*CompletionService) ResolveCompletionItem

func (s *CompletionService) ResolveCompletionItem(
	ctx *common.LSPContext,
	item *lsp.CompletionItem,
	completionType string,
) (*lsp.CompletionItem, error)

ResolveCompletionItem resolves extra information such as detailed descriptions for a completion item.

func (*CompletionService) UpdateRegistries added in v0.2.0

func (s *CompletionService) UpdateRegistries(
	resourceRegistry resourcehelpers.Registry,
	dataSourceRegistry provider.DataSourceRegistry,
	customVarTypeRegistry provider.CustomVariableTypeRegistry,
	functionRegistry provider.FunctionRegistry,
	linkSource linkinfo.Source,
)

UpdateRegistries updates the registries used by the completion service. This is called after plugin loading to include plugin-provided types.

type DiagnosticErrorService

type DiagnosticErrorService struct {
	// contains filtered or unexported fields
}

DiagnosticErrorService is a service that provides functionality for converting validation errors into LSP diagnostics.

func NewDiagnosticErrorService

func NewDiagnosticErrorService(
	state *State,
	logger *zap.Logger,
) *DiagnosticErrorService

NewDiagnosticErrorService creates a new service for converting validation errors into LSP diagnostics.

func (*DiagnosticErrorService) BlueprintErrorToDiagnostics

func (s *DiagnosticErrorService) BlueprintErrorToDiagnostics(
	err error,
	docURI lsp.URI,
) ([]lsp.Diagnostic, []*EnhancedDiagnostic)

BlueprintErrorToDiagnostics converts a blueprint error into LSP diagnostics. It returns both the standard LSP diagnostics and enhanced diagnostics that include error context metadata for use in code actions.

type DiagnosticsService

type DiagnosticsService struct {
	// contains filtered or unexported fields
}

DiagnosticsService is a service that provides functionality for diagnostics.

func NewDiagnosticsService

func NewDiagnosticsService(
	state *State,
	settingsService *SettingsService,
	diagnosticErrorService *DiagnosticErrorService,
	loader container.Loader,
	logger *zap.Logger,
) *DiagnosticsService

NewDiagnosticsService creates a new service for diagnostics.

func (*DiagnosticsService) SetShowAnyTypeWarnings added in v0.2.0

func (s *DiagnosticsService) SetShowAnyTypeWarnings(show bool)

SetShowAnyTypeWarnings configures whether "any" type warnings are included in published diagnostics.

func (*DiagnosticsService) UpdateLoader added in v0.2.0

func (s *DiagnosticsService) UpdateLoader(loader container.Loader)

UpdateLoader updates the blueprint loader used by the diagnostics service. This is called after plugin loading to use a loader with plugin providers.

func (*DiagnosticsService) ValidateTextDocument

func (s *DiagnosticsService) ValidateTextDocument(
	lspCtx *common.LSPContext,
	docURI lsp.URI,
) ([]lsp.Diagnostic, []*EnhancedDiagnostic, *schema.Blueprint, error)

ValidateTextDocument validates a text document and returns diagnostics. It returns both standard LSP diagnostics and enhanced diagnostics with error context metadata for use in code actions.

func (*DiagnosticsService) ValidateTextDocumentBackground added in v0.2.0

func (s *DiagnosticsService) ValidateTextDocumentBackground(
	docURI lsp.URI,
) ([]lsp.Diagnostic, []*EnhancedDiagnostic, *schema.Blueprint, error)

ValidateTextDocumentBackground validates a document without requiring an LSPContext. This is used for debounced validation where the original request context may be cancelled. It uses cached settings or defaults instead of making RPC calls to the client.

type DocSettings

type DocSettings struct {
	Trace               DocTraceSettings `json:"trace"`
	MaxNumberOfProblems int              `json:"maxNumberOfProblems"`
}

DocSettings holds settings for a document.

type DocTraceSettings

type DocTraceSettings struct {
	Server string `json:"server"`
}

DocTraceSettings holds settings for tracing in a document.

type ElementCategory added in v0.2.0

type ElementCategory int

ElementCategory identifies what kind of blueprint element is being referenced.

const (
	ElementCategoryResource ElementCategory = iota
	ElementCategoryVariable
	ElementCategoryValue
	ElementCategoryDataSource
	ElementCategoryChild
)

type EnhancedDiagnostic added in v0.2.0

type EnhancedDiagnostic struct {
	// Diagnostic is the standard LSP diagnostic sent to the client
	Diagnostic lsp.Diagnostic

	// ErrorContext contains structured information for error resolution
	// including suggested actions, reason codes, and metadata
	ErrorContext *errors.ErrorContext

	// Original error location fields for precise text edits
	// These are 1-indexed (matching blueprint error conventions)
	Line      *int
	Column    *int
	EndLine   *int
	EndColumn *int
}

EnhancedDiagnostic pairs an LSP diagnostic with its source error context for use in generating code actions. The error context contains metadata like typo suggestions, allowed values, and missing field names that can be used to provide quick fixes.

type FindReferencesService added in v0.2.0

type FindReferencesService struct {
	// contains filtered or unexported fields
}

FindReferencesService provides find-all-references functionality for blueprint documents.

func NewFindReferencesService added in v0.2.0

func NewFindReferencesService(
	state *State,
	logger *zap.Logger,
) *FindReferencesService

NewFindReferencesService creates a new service for find-all-references support.

func (*FindReferencesService) GetReferencesFromContext added in v0.2.0

func (s *FindReferencesService) GetReferencesFromContext(
	docCtx *docmodel.DocumentContext,
	params *lsp.ReferencesParams,
) ([]lsp.Location, error)

GetReferencesFromContext returns all reference locations for the element at the given cursor position.

type GotoDefinitionService

type GotoDefinitionService struct {
	// contains filtered or unexported fields
}

GotoDefinitionService provides go-to-definition functionality for blueprint documents.

func NewGotoDefinitionService

func NewGotoDefinitionService(
	state *State,
	childResolver *ChildBlueprintResolver,
	logger *zap.Logger,
) *GotoDefinitionService

NewGotoDefinitionService creates a new service for go-to-definition support.

func (*GotoDefinitionService) GetDefinitionsFromContext added in v0.2.0

func (s *GotoDefinitionService) GetDefinitionsFromContext(
	docCtx *docmodel.DocumentContext,
	params *lsp.TextDocumentPositionParams,
) ([]lsp.LocationLink, error)

GetDefinitionsFromContext returns definition links using the DocumentContext.

type HoverContent

type HoverContent struct {
	Value string
	Range *lsp.Range
}

HoverContent represents the content for a hover message.

type HoverService

type HoverService struct {
	// contains filtered or unexported fields
}

HoverService is a service that provides functionality for hover messages.

func NewHoverService

func NewHoverService(
	funcRegistry provider.FunctionRegistry,
	resourceRegistry resourcehelpers.Registry,
	dataSourceRegistry provider.DataSourceRegistry,
	linkSource linkinfo.Source,
	signatureService *SignatureService,
	childResolver *ChildBlueprintResolver,
	logger *zap.Logger,
) *HoverService

NewHoverService creates a new service for hover messages.

func (*HoverService) GetHoverContent

func (s *HoverService) GetHoverContent(
	ctx *common.LSPContext,
	docCtx *docmodel.DocumentContext,
	params *lsp.TextDocumentPositionParams,
) (*HoverContent, error)

GetHoverContent returns hover content using DocumentContext for position resolution. This provides tree-sitter based position resolution with fallback to last-known-good state.

func (*HoverService) UpdateRegistries added in v0.2.0

func (s *HoverService) UpdateRegistries(
	funcRegistry provider.FunctionRegistry,
	resourceRegistry resourcehelpers.Registry,
	dataSourceRegistry provider.DataSourceRegistry,
	linkSource linkinfo.Source,
)

UpdateRegistries updates the registries used by the hover service. This is called after plugin loading to include plugin-provided types.

type JSONCFormatter added in v0.2.0

type JSONCFormatter struct{}

JSONCFormatter implements CompletionFormatter for JSONC documents. JSONC uses delimiter-based structure and always quotes string values.

func (*JSONCFormatter) FormatArrayItem added in v0.2.0

func (f *JSONCFormatter) FormatArrayItem(value string) string

FormatArrayItem formats an array item for JSONC insertion. JSONC array items are quoted strings.

func (*JSONCFormatter) FormatKey added in v0.2.0

func (f *JSONCFormatter) FormatKey(keyName string) string

FormatKey formats a key name for JSONC insertion. JSONC keys are quoted and followed by ": ".

func (*JSONCFormatter) FormatValue added in v0.2.0

func (f *JSONCFormatter) FormatValue(value string, hasLeadingQuote bool, hasLeadingSpace bool) string

FormatValue formats a value for JSONC insertion. If hasLeadingQuote is true, user already typed the opening quote. If hasLeadingSpace is true, there's already whitespace before the cursor.

func (*JSONCFormatter) GetFormat added in v0.2.0

func (f *JSONCFormatter) GetFormat() docmodel.DocumentFormat

GetFormat returns FormatJSONC.

func (*JSONCFormatter) GetInsertRange added in v0.2.0

func (f *JSONCFormatter) GetInsertRange(position *lsp.Position, prefixLen int) *lsp.Range

GetInsertRange returns the range to replace with the completion.

func (*JSONCFormatter) NeedsQuoting added in v0.2.0

func (f *JSONCFormatter) NeedsQuoting(_ string) bool

NeedsQuoting returns true - JSONC always requires quotes for string values.

type ResolvedElement added in v0.2.0

type ResolvedElement struct {
	Category       ElementCategory
	Name           string
	DefinitionPath string
}

ResolvedElement represents the identity of a blueprint element resolved from a cursor position.

type SettingsService

type SettingsService struct {
	// contains filtered or unexported fields
}

SettingsService is a service that provides shared functionality for working with settings across multiple documents.

func NewSettingsService

func NewSettingsService(state *State, configSection string, logger *zap.Logger) *SettingsService

NewSettingsService creates a new service for managing settings.

func (*SettingsService) GetDocumentSettings

func (s *SettingsService) GetDocumentSettings(
	context *common.LSPContext,
	uri string,
) (*DocSettings, error)

GetDocumentSettings retrieves the settings for a document from the server cache if possible, otherwise it requests the settings from the client.

type SignatureService

type SignatureService struct {
	// contains filtered or unexported fields
}

SignatureService is a service that provides functionality for function signature help.

func NewSignatureService

func NewSignatureService(
	funcRegistry provider.FunctionRegistry,
	logger *zap.Logger,
) *SignatureService

NewSignatureService creates a new service for function signature help.

func (*SignatureService) GetFunctionSignatures

func (s *SignatureService) GetFunctionSignatures(
	ctx *common.LSPContext,
	docCtx *docmodel.DocumentContext,
	params *lsp.TextDocumentPositionParams,
) ([]*lsp.SignatureInformation, error)

GetFunctionSignatures returns the function signatures for the given document context and signature help parameters including the current position in the source document. Uses DocumentContext for position resolution.

func (*SignatureService) SignatureInfoFromFunction

func (s *SignatureService) SignatureInfoFromFunction(
	subFunc *substitutions.SubstitutionFunctionExpr,
	ctx *common.LSPContext,
) ([]*lsp.SignatureInformation, error)

func (*SignatureService) UpdateRegistry added in v0.2.0

func (s *SignatureService) UpdateRegistry(funcRegistry provider.FunctionRegistry)

UpdateRegistry updates the function registry used by the signature service. This is called after plugin loading to include plugin-provided functions.

type State

type State struct {
	// contains filtered or unexported fields
}

State holds the state shared between language server services to provide functionality for working with blueprint documents.

func NewState

func NewState() *State

NewState creates a new instance of the state service for the language server.

func (*State) ClearDocSettings

func (s *State) ClearDocSettings()

ClearDocSettings clears settings for all documents.

func (*State) GetDocumentContent

func (s *State) GetDocumentContent(uri string) *string

GetDocumentContent retrieves the content of a document by its URI.

func (*State) GetDocumentContext added in v0.2.0

func (s *State) GetDocumentContext(uri string) *docmodel.DocumentContext

GetDocumentContext retrieves the DocumentContext for a document by its URI.

func (*State) GetDocumentSchema

func (s *State) GetDocumentSchema(uri string) *schema.Blueprint

GetDocumentSchema retrieves the parsed blueprint schema for a document by its URI.

func (*State) GetDocumentSettings

func (s *State) GetDocumentSettings(uri string) *DocSettings

GetDocumentSettings retrieves the settings for a document by its URI.

func (*State) GetDocumentTree

func (s *State) GetDocumentTree(uri string) *schema.TreeNode

GetDocumentTree retrieves the document tree for a document by its URI.

func (*State) GetEnhancedDiagnostics added in v0.2.0

func (s *State) GetEnhancedDiagnostics(uri string) []*EnhancedDiagnostic

GetEnhancedDiagnostics retrieves the enhanced diagnostics for a document by its URI. Enhanced diagnostics include the error context metadata needed for code actions.

func (*State) GetPositionEncodingKind

func (s *State) GetPositionEncodingKind() lsp.PositionEncodingKind

GetPositionEncodingKind returns the encoding kind for positions in documents as specified by the client.

func (*State) HasConfigurationCapability

func (s *State) HasConfigurationCapability() bool

HasConfigurationCapability returns true if the language server has the capability to handle configuration.

func (*State) HasHierarchicalDocumentSymbolCapability

func (s *State) HasHierarchicalDocumentSymbolCapability() bool

HasHierarchicalDocumentSymbolCapability returns true if the language server has the capability to handle hierarchical document symbols.

func (*State) HasLinkSupportCapability

func (s *State) HasLinkSupportCapability() bool

HasLinkSupportCapability returns true if the language server has the capability to handle links using the LocationLink result type.

func (*State) HasWorkspaceFolderCapability

func (s *State) HasWorkspaceFolderCapability() bool

HasWorkspaceFolderCapability returns true if the language server has the capability to handle workspace folders.

func (*State) SetConfigurationCapability

func (s *State) SetConfigurationCapability(value bool)

SetConfigurationCapability sets the capability to handle configuration.

func (*State) SetDocumentContent

func (s *State) SetDocumentContent(uri string, content string)

SetDocumentContent sets the content of a document by its URI.

func (*State) SetDocumentContext added in v0.2.0

func (s *State) SetDocumentContext(uri string, ctx *docmodel.DocumentContext)

SetDocumentContext sets the DocumentContext for a document by its URI.

func (*State) SetDocumentSettings

func (s *State) SetDocumentSettings(uri string, settings *DocSettings)

SetDocumentSettings sets the settings for a document by its URI.

func (*State) SetEnhancedDiagnostics added in v0.2.0

func (s *State) SetEnhancedDiagnostics(uri string, diagnostics []*EnhancedDiagnostic)

SetEnhancedDiagnostics sets the enhanced diagnostics for a document by its URI. This replaces any existing enhanced diagnostics for the document.

func (*State) SetHierarchicalDocumentSymbolCapability

func (s *State) SetHierarchicalDocumentSymbolCapability(value bool)

SetHierarchicalDocumentSymbolCapability sets the capability to handle hierarchical document symbols.

func (*State) SetLinkSupportCapability

func (s *State) SetLinkSupportCapability(value bool)

SetLinkSupportCapability sets the capability to handle links using the LocationLink result type.

func (*State) SetPositionEncodingKind

func (s *State) SetPositionEncodingKind(value lsp.PositionEncodingKind)

SetPositionEncodingKind sets the encoding kind for positions in documents as specified by the client.

func (*State) SetWorkspaceFolderCapability

func (s *State) SetWorkspaceFolderCapability(value bool)

SetWorkspaceFolderCapability sets the capability to handle workspace folders.

type SymbolService

type SymbolService struct {
	// contains filtered or unexported fields
}

SymbolService is a service that provides functionality for document symbols for an LSP client.

func NewSymbolService

func NewSymbolService(
	state *State,
	logger *zap.Logger,
) *SymbolService

NewSymbolService creates a new service for document symbols.

func (*SymbolService) GetDocumentSymbolsFromContext added in v0.2.0

func (s *SymbolService) GetDocumentSymbolsFromContext(
	docCtx *docmodel.DocumentContext,
) ([]lsp.DocumentSymbol, error)

GetDocumentSymbolsFromContext returns symbols using the unified document model.

type YAMLFormatter added in v0.2.0

type YAMLFormatter struct{}

YAMLFormatter implements CompletionFormatter for YAML documents. YAML uses indentation-based structure and has special quoting rules.

func (*YAMLFormatter) FormatArrayItem added in v0.2.0

func (f *YAMLFormatter) FormatArrayItem(value string) string

FormatArrayItem formats an array item for YAML insertion. YAML uses "- " prefix for block-style sequence items.

func (*YAMLFormatter) FormatKey added in v0.2.0

func (f *YAMLFormatter) FormatKey(keyName string) string

FormatKey formats a key name for YAML insertion. YAML keys are followed by ": " (colon and space).

func (*YAMLFormatter) FormatValue added in v0.2.0

func (f *YAMLFormatter) FormatValue(value string, _, _ bool) string

FormatValue formats a value for YAML insertion. Values that could be misinterpreted (booleans, nulls, special chars) need quoting.

func (*YAMLFormatter) GetFormat added in v0.2.0

func (f *YAMLFormatter) GetFormat() docmodel.DocumentFormat

GetFormat returns FormatYAML.

func (*YAMLFormatter) GetInsertRange added in v0.2.0

func (f *YAMLFormatter) GetInsertRange(position *lsp.Position, prefixLen int) *lsp.Range

GetInsertRange returns the range to replace with the completion.

func (*YAMLFormatter) NeedsQuoting added in v0.2.0

func (f *YAMLFormatter) NeedsQuoting(value string) bool

NeedsQuoting returns true if a value needs quoting in YAML.

Jump to

Keyboard shortcuts

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