diag

package
v1.10.7 Latest Latest
Warning

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

Go to latest
Published: May 5, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package diag implements diagnostics tools: publishDiagnostics subscription, code action forwarding, and code formatting via LSP.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyCodeAction

func ApplyCodeAction(ctx context.Context, lease *lspool.WorkerLease, action CodeActionResult) error

ApplyCodeAction applies a code action's workspace edit by writing file changes. If the action has no edit, it returns an error.

func ApplyFormatEdits

func ApplyFormatEdits(path string, edits []TextEditResult) error

ApplyFormatEdits applies text edits to a file on disk. Edits are applied in reverse document order (bottom-up) to preserve earlier line numbers. The write is atomic: content is written to a temp file then renamed.

func RegisterTools

func RegisterTools(server *mcp.SerenaMCPServer, store *DiagnosticStore, workspaceRoot func() string, leaseFn LeaseProvider, tracer trace.Tracer)

RegisterTools registers the 3 diagnostic MCP tools with the server. Each handler is wrapped with kernel.WrapToolSpan to produce kernel.tool.{name} sub-spans under the TelemetryMiddleware span (Phase 12, TRACE-03).

Types

type CodeActionResult

type CodeActionResult struct {
	Title       string
	Kind        string
	IsPreferred bool
	Edit        *gen.WorkspaceEdit // nil if action requires a command
	Diagnostics []gen.Diagnostic
}

CodeActionResult is a simplified view of a CodeAction returned by the LS.

func GetCodeActions

func GetCodeActions(ctx context.Context, lease *lspool.WorkerLease, uri string, startLine, startCol, endLine, endCol int) ([]CodeActionResult, error)

GetCodeActions sends textDocument/codeAction and returns the available actions for the given position or range in the file identified by uri. Line and column values are 0-indexed (LSP convention).

type DiagnosticStore

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

DiagnosticStore collects and serves publishDiagnostics notifications from language servers. It is safe for concurrent use.

func NewDiagnosticStore

func NewDiagnosticStore() *DiagnosticStore

NewDiagnosticStore creates a new empty diagnostic store.

func (*DiagnosticStore) Clear

func (d *DiagnosticStore) Clear(uri string)

Clear removes stored diagnostics for a URI.

func (*DiagnosticStore) GetAllDiagnostics

func (d *DiagnosticStore) GetAllDiagnostics() map[string][]gen.Diagnostic

GetAllDiagnostics returns a snapshot of all stored diagnostics keyed by URI.

func (*DiagnosticStore) GetDiagnostics

func (d *DiagnosticStore) GetDiagnostics(uri string) []gen.Diagnostic

GetDiagnostics returns the current diagnostics for a file URI.

func (*DiagnosticStore) HandleNotification

func (d *DiagnosticStore) HandleNotification(method string, params json.RawMessage)

HandleNotification is a JSON-RPC notification callback that dispatches textDocument/publishDiagnostics to HandlePublishDiagnostics.

func (*DiagnosticStore) HandlePublishDiagnostics

func (d *DiagnosticStore) HandlePublishDiagnostics(params gen.PublishDiagnosticsParams)

HandlePublishDiagnostics processes a textDocument/publishDiagnostics notification. It replaces all stored diagnostics for the URI and wakes any waiters.

func (*DiagnosticStore) WaitForDiagnostics

func (d *DiagnosticStore) WaitForDiagnostics(ctx context.Context, uri string, timeout time.Duration) ([]gen.Diagnostic, error)

WaitForDiagnostics blocks until diagnostics arrive for the given URI or the timeout expires. If the context is cancelled, it returns the context error.

type DiagnosticsSkill

type DiagnosticsSkill struct{}

DiagnosticsSkill is a ToolProvider adapter that exposes the 3 diagnostic tools through the skill interface for daemon discovery.

func (*DiagnosticsSkill) Description

func (s *DiagnosticsSkill) Description() string

Description returns a human-readable description of this skill.

func (*DiagnosticsSkill) Init

func (s *DiagnosticsSkill) Init(deps skill.SkillDeps) error

Init is a no-op; kernel tools get their dependencies from the daemon, not SkillDeps.

func (*DiagnosticsSkill) Name

func (s *DiagnosticsSkill) Name() string

Name returns the unique skill identifier.

func (*DiagnosticsSkill) Tools

func (s *DiagnosticsSkill) Tools() []*mcp.ToolDef

Tools returns the 3 ToolDefs for diagnostics. RegisterFn is nil because the daemon owns MCP registration (D-01).

type FormatCodeArgs

type FormatCodeArgs struct {
	Path      string `json:"path" jsonschema:"File path to format"`
	TabSize   int    `json:"tab_size,omitempty" jsonschema:"Tab size (default: 4)"`
	UseSpaces bool   `json:"use_spaces,omitempty" jsonschema:"Use spaces instead of tabs (default: true)"`
}

FormatCodeArgs is the input schema for the format_code tool.

type FormatOptions

type FormatOptions struct {
	TabSize      int
	InsertSpaces bool
}

FormatOptions controls formatting behaviour.

type GetCodeActionsArgs

type GetCodeActionsArgs struct {
	Path    string `json:"path" jsonschema:"File path"`
	Line    int    `json:"line" jsonschema:"Line number (1-indexed)"`
	Col     int    `json:"column" jsonschema:"Column number (1-indexed)"`
	EndLine int    `json:"end_line,omitempty" jsonschema:"End line for range selection"`
	EndCol  int    `json:"end_column,omitempty" jsonschema:"End column for range selection"`
}

GetCodeActionsArgs is the input schema for the get_code_actions tool.

type GetDiagnosticsArgs

type GetDiagnosticsArgs struct {
	Path string `json:"path" jsonschema:"File path to check diagnostics for"`
}

GetDiagnosticsArgs is the input schema for the get_diagnostics tool.

type LeaseProvider

type LeaseProvider func(ctx context.Context, uri string) (*lspool.WorkerLease, error)

LeaseProvider returns a worker lease for an LSP request against the given file URI. It abstracts the kernel/pool layer so tools don't depend on kernel directly.

type TextEditResult

type TextEditResult struct {
	StartLine int
	StartCol  int
	EndLine   int
	EndCol    int
	NewText   string
}

TextEditResult is a simplified representation of a text edit from the LS.

func FormatDocument

func FormatDocument(ctx context.Context, lease *lspool.WorkerLease, uri string, opts FormatOptions) ([]TextEditResult, error)

FormatDocument sends textDocument/formatting and returns the resulting edits.

Jump to

Keyboard shortcuts

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