Documentation
¶
Overview ¶
Package analysis is the reusable analysis service that wraps Rune's parse → compose → analyze pipeline behind a source-overlay abstraction. It produces immutable Snapshots consumed by the CLI, `rune analyze`, the language server, and MCP task discovery, so every interface reports identical diagnostics (spec FR-002). Nothing in this package executes tasks, spawns processes, opens sockets, or writes project files (FR-028): it imports neither internal/runtime nor os/exec nor any network package.
Index ¶
- func ApplyByteEdit(text string, start, end int, newText string) string
- func Provider(ctx context.Context, s SourceStore) diag.SourceProvider
- type AnalyzeRequest
- type DiskSourceStore
- type DocumentURI
- type ImportGraph
- type OpenDocument
- type OverlaySourceStore
- func (o *OverlaySourceStore) Exists(ctx context.Context, uri DocumentURI) bool
- func (o *OverlaySourceStore) Get(uri DocumentURI) (OpenDocument, bool)
- func (o *OverlaySourceStore) Read(ctx context.Context, uri DocumentURI) ([]byte, error)
- func (o *OverlaySourceStore) Remove(uri DocumentURI)
- func (o *OverlaySourceStore) Set(doc OpenDocument)
- type Service
- type Snapshot
- type SourceStore
- type Workspace
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ApplyByteEdit ¶
ApplyByteEdit splices newText into text over the half-open byte range [start, end), returning the result. Offsets are clamped into [0, len(text)] and ordered (start <= end) so the function is TOTAL: it never panics and always terminates for any inputs. The LSP layer converts an LSP range to byte offsets (via the UTF-16-aware LineIndex) before calling this; keeping the UTF-16 conversion out of this package avoids a dependency on internal/lsp.
func Provider ¶
func Provider(ctx context.Context, s SourceStore) diag.SourceProvider
Provider adapts a SourceStore to the diag.SourceProvider signature used by the parser diagnostics renderer and config.Compose. A read error maps to (nil, false).
Types ¶
type AnalyzeRequest ¶
type AnalyzeRequest struct {
URI DocumentURI
Content string
Version int
}
AnalyzeRequest asks the service to analyze one entry document.
When Content is non-empty it is used as the entry document's source directly (the unsaved editor buffer); otherwise the entry is read through the service's SourceStore. Imported/mod files are always resolved through the store, so open overlays apply transitively (spec FR-003).
type DiskSourceStore ¶
type DiskSourceStore struct{}
DiskSourceStore reads documents straight from the filesystem.
func (DiskSourceStore) Exists ¶
func (DiskSourceStore) Exists(_ context.Context, uri DocumentURI) bool
func (DiskSourceStore) Read ¶
func (DiskSourceStore) Read(_ context.Context, uri DocumentURI) ([]byte, error)
type DocumentURI ¶
type DocumentURI = string
DocumentURI identifies a document. At the analysis layer it is a cleaned filesystem path (what the parser and import composer already use); the LSP layer converts file:// URIs to and from this form at its boundary. It is a type alias so it is interchangeable with the path strings the engine uses.
func DetectRoot ¶
func DetectRoot(explicit DocumentURI, docPath string, exists func(path string) bool) DocumentURI
DetectRoot resolves a workspace root using the spec's order (FR-021): an explicit client workspace folder, then the nearest ancestor directory containing a Runefile, then the nearest containing a .git, then the document's own directory. exists probes whether a path is present (injected so this is testable without a real filesystem).
type ImportGraph ¶
type ImportGraph struct {
ImportsByFile map[DocumentURI][]DocumentURI
ImportedByFile map[DocumentURI][]DocumentURI
}
ImportGraph records which files import which, in both directions, so a change to one file can invalidate its transitive importers (spec FR-022).
func (*ImportGraph) AddEdge ¶
func (g *ImportGraph) AddEdge(importer, imported DocumentURI)
AddEdge records that importer imports imported.
func (ImportGraph) TransitiveImporters ¶
func (g ImportGraph) TransitiveImporters(uri DocumentURI) []DocumentURI
TransitiveImporters returns every file that imports uri directly or indirectly (the set to re-analyze when uri changes, FR-022).
type OpenDocument ¶
type OpenDocument struct {
URI DocumentURI
Version int
Text string
}
OpenDocument is an editor-held document: its identity, monotonically increasing version, and current full text (the overlay source that takes precedence over disk). See spec data-model.
func (OpenDocument) WithText ¶
func (d OpenDocument) WithText(version int, text string) OpenDocument
WithText returns a copy of the document carrying new full text at a new version (used for full-sync changes and didSave).
type OverlaySourceStore ¶
type OverlaySourceStore struct {
// contains filtered or unexported fields
}
OverlaySourceStore serves open (possibly unsaved) editor documents in preference to disk, falling back to its disk backing for any document that is not open. This is the resolution rule from the spec (FR-003): use the editor overlay when a document is open, otherwise read from disk — and it applies to imported files too. It is safe for concurrent use.
func NewOverlaySourceStore ¶
func NewOverlaySourceStore(disk SourceStore) *OverlaySourceStore
NewOverlaySourceStore returns an overlay backed by disk (or the given store).
func (*OverlaySourceStore) Exists ¶
func (o *OverlaySourceStore) Exists(ctx context.Context, uri DocumentURI) bool
func (*OverlaySourceStore) Get ¶
func (o *OverlaySourceStore) Get(uri DocumentURI) (OpenDocument, bool)
Get returns the open document for uri, if one is open.
func (*OverlaySourceStore) Read ¶
func (o *OverlaySourceStore) Read(ctx context.Context, uri DocumentURI) ([]byte, error)
func (*OverlaySourceStore) Remove ¶
func (o *OverlaySourceStore) Remove(uri DocumentURI)
Remove drops an open document, so subsequent reads fall back to disk (textDocument/didClose).
func (*OverlaySourceStore) Set ¶
func (o *OverlaySourceStore) Set(doc OpenDocument)
Set records (or replaces) an open document in the overlay.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service is the reusable analysis layer shared by the CLI, `rune analyze`, the language server, and MCP task discovery (spec FR-002). It executes nothing.
func NewService ¶
func NewService(store SourceStore) *Service
NewService returns a Service backed by the given source store (a DiskSourceStore for one-shot CLI use, or an OverlaySourceStore for the LSP). A nil store defaults to disk.
func (*Service) Analyze ¶
Analyze runs parse → compose → analyze → build index → build import graph for one entry document and returns an immutable Snapshot. Unlike the execution path, it aggregates ALL diagnostics (it does not stop at the first failing stage) so editors and `rune analyze` see everything at once. It never executes tasks, shells, or network requests (spec FR-028).
func (*Service) Store ¶
func (s *Service) Store() SourceStore
Store exposes the service's source store (the LSP manages overlays through it).
type Snapshot ¶
type Snapshot struct {
URI DocumentURI
Version int
File *ast.File
Sources diag.SourceProvider
Diagnostics diag.List
Symbols *language.Index
Imports ImportGraph
}
Snapshot is the immutable result of analyzing one entry document at one version: the composed AST, a source provider for rendering, all diagnostics (parser + semantic + project, across files), the symbol index, and the import graph. Every interface (CLI, rune analyze, LSP, MCP) consumes this same shape so results are identical (spec FR-002).
type SourceStore ¶
type SourceStore interface {
Read(ctx context.Context, uri DocumentURI) ([]byte, error)
Exists(ctx context.Context, uri DocumentURI) bool
}
SourceStore resolves document content. It is READ-ONLY by contract: the analysis surface never writes project files (spec FR-028).
type Workspace ¶
type Workspace struct {
Root DocumentURI
EntryFile DocumentURI
Imports ImportGraph
}
Workspace is the scope of analysis: a project root, its entry file, and the import graph relating its documents. Each workspace folder is an independent project in the first release (spec FR-021).