Documentation
¶
Overview ¶
Package diagnostics provides rich diagnostic information for db-catalyst.
Package diagnostics provides rich diagnostic information for db-catalyst.
Package diagnostics provides rich diagnostic information for db-catalyst. It captures file locations, contextual code snippets, suggestions for fixes, and severity levels to help users understand and resolve issues.
Package diagnostics provides rich diagnostic information for db-catalyst.
Index ¶
- Constants
- func BatchEnrich(c *Collection, extractor *ContextExtractor, contextLines int)
- func CodeDescription(code string) string
- func CollectionToQueryAnalyzer(c *Collection) []queryanalyzer.Diagnostic
- func EnrichWithContext(c *Collection, extractor *ContextExtractor, contextLines int)
- func EnrichWithSuggestions(c *Collection)
- func ExtractLine(content []byte, lineNum int) (string, error)
- func ExtractLines(content []byte, startLine, endLine int) ([]string, error)
- func FormatForTerminal(c *Collection, verbose bool) string
- func PrintToWriter(w io.Writer, c *Collection, verbose bool) error
- func ToQueryAnalyzer(d Diagnostic) queryanalyzer.Diagnostic
- type Builder
- func (b *Builder) At(path string, line, column int) *Builder
- func (b *Builder) AtLocation(loc Location) *Builder
- func (b *Builder) Build() Diagnostic
- func (b *Builder) WithCode(code string) *Builder
- func (b *Builder) WithContext(context string) *Builder
- func (b *Builder) WithNote(note string) *Builder
- func (b *Builder) WithRelated(path string, line, column int, message string) *Builder
- func (b *Builder) WithSource(source string) *Builder
- func (b *Builder) WithSpan(start, end Location) *Builder
- func (b *Builder) WithSuggestion(message, replacement string) *Builder
- type CategorizedSummary
- type Collection
- func (c *Collection) Add(d Diagnostic)
- func (c *Collection) AddAll(other *Collection)
- func (c *Collection) All() []Diagnostic
- func (c *Collection) ByCode(code string) []Diagnostic
- func (c *Collection) BySeverity(severity Severity) []Diagnostic
- func (c *Collection) BySource(source string) []Diagnostic
- func (c *Collection) Categorize() CategorizedSummary
- func (c *Collection) Errors() []Diagnostic
- func (c *Collection) Filter(predicate func(Diagnostic) bool) []Diagnostic
- func (c *Collection) HasErrors() bool
- func (c *Collection) Len() int
- func (c *Collection) SortByLocation()
- func (c *Collection) Summary() Summary
- func (c *Collection) Warnings() []Diagnostic
- type Context
- type ContextExtractor
- type Diagnostic
- func CreateConfigError(path string, line, column int, message string) Diagnostic
- func CreateQueryError(path string, line, column int, message string) Diagnostic
- func CreateSchemaError(path string, line, column int, message string) Diagnostic
- func CreateWarning(path string, line, column int, message string) Diagnostic
- func EnrichDiagnostic(d Diagnostic, extractor *ContextExtractor, contextLines int) Diagnostic
- func FromQueryAnalyzer(d queryanalyzer.Diagnostic) Diagnostic
- func FromQueryParser(d queryparser.Diagnostic) Diagnostic
- func FromSchemaParser(d schemaparser.Diagnostic) Diagnostic
- type Formatter
- func (f *Formatter) Format(d Diagnostic) string
- func (f *Formatter) FormatAll(c *Collection) string
- func (f *Formatter) PrintCategorizedSummary(w io.Writer, c *Collection)
- func (f *Formatter) PrintSummary(w io.Writer, c *Collection)
- func (f *Formatter) Write(w io.Writer, d Diagnostic) error
- func (f *Formatter) WriteAll(w io.Writer, c *Collection) error
- type JSONFormatter
- type Location
- type RelatedInfo
- type Severity
- type SimpleFormatter
- type SnippetExtractor
- type Span
- type Suggestion
- type Summary
Constants ¶
const ( // Schema parsing errors (E1xx) ErrSchemaParseError = "E101" ErrSchemaDuplicateTable = "E102" ErrSchemaDuplicateView = "E103" ErrSchemaDuplicateCol = "E104" ErrSchemaInvalidType = "E105" ErrSchemaUnknownTable = "E106" ErrSchemaUnknownColumn = "E107" ErrSchemaInvalidFK = "E108" ErrSchemaInvalidPK = "E109" ErrSchemaInvalidIndex = "E110" // Query parsing errors (E2xx) ErrQueryParseError = "E201" ErrQueryInvalidVerb = "E202" ErrQueryInvalidParam = "E203" ErrQueryInvalidCTE = "E204" ErrQueryMissingAlias = "E205" ErrQueryAmbiguousCol = "E206" ErrQueryUnknownTable = "E207" ErrQueryUnknownColumn = "E208" ErrQueryTypeMismatch = "E209" ErrQueryInvalidSyntax = "E210" // Configuration errors (E3xx) ErrConfigInvalid = "E301" ErrConfigMissingPackage = "E302" ErrConfigMissingOut = "E303" ErrConfigInvalidPath = "E304" ErrConfigUnknownKey = "E305" ErrConfigInvalidDriver = "E306" ErrConfigInvalidLang = "E307" ErrConfigInvalidDB = "E308" // Code generation errors (E4xx) ErrCodeGenFailed = "E401" ErrCodeGenWriteFailed = "E402" ErrCodeGenTypeError = "E403" // Warnings (W1xx) WarnDeprecatedFeature = "W101" WarnUnnecessaryAlias = "W102" WarnTypeInference = "W103" WarnUnusedParam = "W104" WarnSchemaMismatch = "W105" )
ErrorCodes provides standardized error codes for diagnostics. These codes help users identify and search for specific issues.
Variables ¶
This section is empty.
Functions ¶
func BatchEnrich ¶
func BatchEnrich(c *Collection, extractor *ContextExtractor, contextLines int)
BatchEnrich enriches all diagnostics in a collection with context and suggestions. This is a convenience function that combines EnrichWithContext and EnrichWithSuggestions.
func CodeDescription ¶
CodeDescription returns a human-readable description for an error code.
func CollectionToQueryAnalyzer ¶
func CollectionToQueryAnalyzer(c *Collection) []queryanalyzer.Diagnostic
CollectionToQueryAnalyzer converts a collection to a slice of query analyzer diagnostics.
func EnrichWithContext ¶
func EnrichWithContext(c *Collection, extractor *ContextExtractor, contextLines int)
EnrichWithContext adds code context to diagnostics that have file locations.
func EnrichWithSuggestions ¶
func EnrichWithSuggestions(c *Collection)
EnrichWithSuggestions adds suggestions to common error patterns.
func ExtractLine ¶
ExtractLine extracts a specific line from content.
func ExtractLines ¶
ExtractLines extracts a range of lines from content.
func FormatForTerminal ¶
func FormatForTerminal(c *Collection, verbose bool) string
FormatForTerminal formats diagnostics for terminal output with colors.
func PrintToWriter ¶
func PrintToWriter(w io.Writer, c *Collection, verbose bool) error
PrintToWriter prints formatted diagnostics to a writer.
func ToQueryAnalyzer ¶
func ToQueryAnalyzer(d Diagnostic) queryanalyzer.Diagnostic
ToQueryAnalyzer converts a rich diagnostic to a query analyzer diagnostic. This is useful for backward compatibility.
Types ¶
type Builder ¶
type Builder struct {
// contains filtered or unexported fields
}
Builder provides a fluent API for constructing diagnostics.
func NewBuilder ¶
NewBuilder creates a new diagnostic builder with the given severity and message.
func (*Builder) AtLocation ¶
AtLocation sets the location from a Location struct.
func (*Builder) Build ¶
func (b *Builder) Build() Diagnostic
Build returns the constructed diagnostic.
func (*Builder) WithContext ¶
WithContext sets the code context.
func (*Builder) WithRelated ¶
WithRelated adds related information.
func (*Builder) WithSource ¶
WithSource sets the source component.
func (*Builder) WithSuggestion ¶
WithSuggestion adds a suggestion.
type CategorizedSummary ¶
type CategorizedSummary struct {
SchemaErrors []Diagnostic
QueryErrors []Diagnostic
ConfigErrors []Diagnostic
CodegenErrors []Diagnostic
Warnings []Diagnostic
Infos []Diagnostic
Uncategorized []Diagnostic
}
CategorizedSummary groups diagnostics by category based on error codes.
func (CategorizedSummary) ErrorCount ¶
func (cs CategorizedSummary) ErrorCount() int
ErrorCount returns the total number of errors (excluding warnings and infos).
func (CategorizedSummary) HasDiagnostics ¶
func (cs CategorizedSummary) HasDiagnostics() bool
HasDiagnostics returns true if any category has diagnostics.
func (CategorizedSummary) Total ¶
func (cs CategorizedSummary) Total() int
Total returns the total number of diagnostics across all categories.
type Collection ¶
type Collection struct {
// contains filtered or unexported fields
}
Collection holds a set of diagnostics.
func CollectionFromQueryAnalyzer ¶
func CollectionFromQueryAnalyzer(diags []queryanalyzer.Diagnostic) *Collection
CollectionFromQueryAnalyzer converts a slice of query analyzer diagnostics to a collection.
func NewCollection ¶
func NewCollection() *Collection
NewCollection creates a new empty diagnostic collection.
func (*Collection) Add ¶
func (c *Collection) Add(d Diagnostic)
Add adds a diagnostic to the collection.
func (*Collection) AddAll ¶
func (c *Collection) AddAll(other *Collection)
AddAll adds all diagnostics from another collection.
func (*Collection) ByCode ¶
func (c *Collection) ByCode(code string) []Diagnostic
ByCode returns diagnostics with a specific error code.
func (*Collection) BySeverity ¶
func (c *Collection) BySeverity(severity Severity) []Diagnostic
BySeverity returns diagnostics of a specific severity.
func (*Collection) BySource ¶
func (c *Collection) BySource(source string) []Diagnostic
BySource returns diagnostics from a specific source.
func (*Collection) Categorize ¶
func (c *Collection) Categorize() CategorizedSummary
Categorize groups diagnostics by their error code category.
func (*Collection) Errors ¶
func (c *Collection) Errors() []Diagnostic
Errors returns all error-level diagnostics.
func (*Collection) Filter ¶
func (c *Collection) Filter(predicate func(Diagnostic) bool) []Diagnostic
Filter returns diagnostics matching the given predicate.
func (*Collection) HasErrors ¶
func (c *Collection) HasErrors() bool
HasErrors returns true if the collection contains any errors.
func (*Collection) SortByLocation ¶
func (c *Collection) SortByLocation()
SortByLocation sorts diagnostics by file path and line number.
func (*Collection) Summary ¶
func (c *Collection) Summary() Summary
Summary returns a summary of the diagnostics collection.
func (*Collection) Warnings ¶
func (c *Collection) Warnings() []Diagnostic
Warnings returns all warning-level diagnostics.
type Context ¶
type Context struct {
Lines []string
StartLine int
ErrorLine int
ErrorColumn int
EndLine int
EndColumn int
IsSpan bool
}
Context represents extracted code context.
func (Context) GetErrorLine ¶
GetErrorLine returns the line containing the error.
type ContextExtractor ¶
type ContextExtractor struct {
// contains filtered or unexported fields
}
ContextExtractor extracts code context from source files.
func NewContextExtractor ¶
func NewContextExtractor() *ContextExtractor
NewContextExtractor creates a new context extractor.
func (*ContextExtractor) ExtractContext ¶
func (e *ContextExtractor) ExtractContext(path string, line, column int, contextLines int) (Context, error)
ExtractContext extracts lines around a specific location. Returns the context lines and the position within those lines.
func (*ContextExtractor) ExtractSpan ¶
func (e *ContextExtractor) ExtractSpan(path string, startLine, endLine, startCol, endCol int) (Context, error)
ExtractSpan extracts context for a span of lines.
type Diagnostic ¶
type Diagnostic struct {
// Core diagnostic information
Severity Severity
Message string
Code string // Optional error code (e.g., "E001", "W003")
// Location information
Location Location
Span *Span // Optional span for multi-line diagnostics
// Context
Context string // Code snippet showing the problematic area
// Help information
Suggestions []Suggestion // Suggested fixes
Notes []string // Additional notes explaining the issue
Related []RelatedInfo // Related locations (e.g., previous definition)
// Source information
Source string // Component that produced the diagnostic (e.g., "schema-parser", "query-analyzer")
}
Diagnostic represents a rich diagnostic message with context.
func CreateConfigError ¶
func CreateConfigError(path string, line, column int, message string) Diagnostic
CreateConfigError creates a rich diagnostic for configuration errors.
func CreateQueryError ¶
func CreateQueryError(path string, line, column int, message string) Diagnostic
CreateQueryError creates a rich diagnostic for query analysis errors.
func CreateSchemaError ¶
func CreateSchemaError(path string, line, column int, message string) Diagnostic
CreateSchemaError creates a rich diagnostic for schema parsing errors.
func CreateWarning ¶
func CreateWarning(path string, line, column int, message string) Diagnostic
CreateWarning creates a rich diagnostic for warnings.
func EnrichDiagnostic ¶
func EnrichDiagnostic(d Diagnostic, extractor *ContextExtractor, contextLines int) Diagnostic
EnrichDiagnostic adds context and suggestions to a single diagnostic. This is useful when you want to enrich diagnostics one at a time.
func FromQueryAnalyzer ¶
func FromQueryAnalyzer(d queryanalyzer.Diagnostic) Diagnostic
FromQueryAnalyzer converts a query analyzer diagnostic to a rich diagnostic.
func FromQueryParser ¶
func FromQueryParser(d queryparser.Diagnostic) Diagnostic
FromQueryParser converts a query parser diagnostic to a rich diagnostic.
func FromSchemaParser ¶
func FromSchemaParser(d schemaparser.Diagnostic) Diagnostic
FromSchemaParser converts a schema parser diagnostic to a rich diagnostic.
func (Diagnostic) Error ¶
func (d Diagnostic) Error() string
Error implements the error interface for error-level diagnostics.
func (Diagnostic) HasLocation ¶
func (d Diagnostic) HasLocation() bool
HasLocation returns true if the diagnostic has a valid location.
func (Diagnostic) HasSpan ¶
func (d Diagnostic) HasSpan() bool
HasSpan returns true if the diagnostic has a valid span.
func (Diagnostic) IsError ¶
func (d Diagnostic) IsError() bool
IsError returns true if the diagnostic is an error.
func (Diagnostic) IsInfo ¶
func (d Diagnostic) IsInfo() bool
IsInfo returns true if the diagnostic is informational.
func (Diagnostic) IsWarning ¶
func (d Diagnostic) IsWarning() bool
IsWarning returns true if the diagnostic is a warning.
func (Diagnostic) String ¶
func (d Diagnostic) String() string
String returns a human-readable string representation of the diagnostic.
type Formatter ¶
type Formatter struct {
// ShowContext controls whether to display code snippets.
ShowContext bool
// ShowSuggestions controls whether to display suggestions.
ShowSuggestions bool
// ShowNotes controls whether to display notes.
ShowNotes bool
// ShowRelated controls whether to display related information.
ShowRelated bool
// ShowSource controls whether to display the source component.
ShowSource bool
// ShowCode controls whether to display error codes.
ShowCode bool
// ShowCodeDescription controls whether to display error code descriptions.
ShowCodeDescription bool
// Colorize controls whether to use ANSI color codes.
Colorize bool
// ContextLines is the number of context lines to show around the error.
ContextLines int
}
Formatter formats diagnostics for display.
func NewFormatter ¶
func NewFormatter() *Formatter
NewFormatter creates a new formatter with default settings.
func NewSimpleFormatter ¶
func NewSimpleFormatter() *Formatter
NewSimpleFormatter creates a formatter with minimal output.
func NewVerboseFormatter ¶
func NewVerboseFormatter() *Formatter
NewVerboseFormatter creates a formatter with all options enabled.
func (*Formatter) Format ¶
func (f *Formatter) Format(d Diagnostic) string
Format formats a single diagnostic as a string.
func (*Formatter) FormatAll ¶
func (f *Formatter) FormatAll(c *Collection) string
FormatAll formats all diagnostics in a collection.
func (*Formatter) PrintCategorizedSummary ¶
func (f *Formatter) PrintCategorizedSummary(w io.Writer, c *Collection)
PrintCategorizedSummary prints a categorized summary of diagnostics.
func (*Formatter) PrintSummary ¶
func (f *Formatter) PrintSummary(w io.Writer, c *Collection)
PrintSummary prints a summary of diagnostics.
type JSONFormatter ¶
type JSONFormatter struct {
Indent bool
}
JSONFormatter formats diagnostics as JSON.
func (*JSONFormatter) Format ¶
func (f *JSONFormatter) Format(d Diagnostic) string
Format formats a diagnostic as JSON.
func (*JSONFormatter) FormatCollection ¶
func (f *JSONFormatter) FormatCollection(c *Collection) string
FormatCollection formats an entire collection as a JSON array.
type RelatedInfo ¶
RelatedInfo represents related context for a diagnostic.
type Severity ¶
type Severity int
Severity indicates the seriousness of a diagnostic.
func SeverityFromString ¶
SeverityFromString parses a severity level from a string.
type SimpleFormatter ¶
type SimpleFormatter struct{}
SimpleFormatter provides a simple one-line format for diagnostics.
func (*SimpleFormatter) Format ¶
func (f *SimpleFormatter) Format(d Diagnostic) string
Format formats a diagnostic in simple format.
type SnippetExtractor ¶
type SnippetExtractor struct {
// contains filtered or unexported fields
}
SnippetExtractor extracts short code snippets from SQL/content.
func NewSnippetExtractor ¶
func NewSnippetExtractor() *SnippetExtractor
NewSnippetExtractor creates a new snippet extractor.
func (*SnippetExtractor) Extract ¶
func (e *SnippetExtractor) Extract(content []byte, offset int) string
Extract extracts a snippet around a position in content.
func (*SnippetExtractor) WithMaxLength ¶
func (e *SnippetExtractor) WithMaxLength(maxLen int) *SnippetExtractor
WithMaxLength sets the maximum snippet length.
type Suggestion ¶
Suggestion represents a suggested fix for a diagnostic.