project

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var NewFileGraph = navigator.NewFileGraph

NewFileGraph delegates to navigator.NewFileGraph.

Functions

func CollectExternalRefTargets

func CollectExternalRefTargets(sourceURI string, idx *openapi.Index) []string

CollectExternalRefTargets returns the set of unique target URIs referenced by external $refs in the given index.

func PathToURI

func PathToURI(fsPath string) string

PathToURI converts an absolute filesystem path to a normalized file:// URI.

func URIToPath

func URIToPath(uri string) string

URIToPath converts a file:// URI to an absolute filesystem path.

func UpdateGraphFromIndex

func UpdateGraphFromIndex(g *FileGraph, sourceURI string, idx *openapi.Index)

UpdateGraphFromIndex clears old edges for sourceURI and adds new ones derived from the index's external $ref usages.

Types

type CrossFileResolver

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

CrossFileResolver resolves $ref values that span across files within a project. It uses the project's merged set of indexes to locate the target document and then delegates to its local resolver.

func NewCrossFileResolver

func NewCrossFileResolver(docs map[string]*openapi.Index) *CrossFileResolver

NewCrossFileResolver creates a resolver over the given set of document indexes.

func (*CrossFileResolver) CanResolve

func (r *CrossFileResolver) CanResolve(fromURI, ref string) bool

CanResolve checks whether a $ref from the given source can be resolved.

func (*CrossFileResolver) Resolve

func (r *CrossFileResolver) Resolve(fromURI, ref string) (*ResolveResult, error)

Resolve follows a $ref value from the given source document. For local refs (#/...) it uses the source document's index. For external refs (./file.yaml#/...) it resolves the file path relative to the source and then resolves the fragment within the target index.

type DiscoveredFile

type DiscoveredFile struct {
	Path  string // absolute filesystem path
	URI   string // file:// URI
	Role  FileRole
	MTime int64 // modification time (Unix nanos) for cache invalidation
}

DiscoveredFile holds information about a file found during workspace scanning.

type Discovery

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

Discovery scans workspace directories for YAML/JSON files and classifies them as OpenAPI roots or fragments. Results are cached by mtime.

func NewDiscovery

func NewDiscovery(exclude []string) *Discovery

NewDiscovery creates a Discovery with the given exclude patterns. Patterns follow filepath.Match syntax (e.g., "node_modules/**").

func (*Discovery) AllFiles

func (d *Discovery) AllFiles() []*DiscoveredFile

AllFiles returns all discovered files.

func (*Discovery) FileByPath

func (d *Discovery) FileByPath(path string) *DiscoveredFile

FileByPath returns the discovered file for a filesystem path, or nil.

func (*Discovery) FileByURI

func (d *Discovery) FileByURI(uri string) *DiscoveredFile

FileByURI returns the discovered file for a URI, or nil.

func (*Discovery) IsRoot

func (d *Discovery) IsRoot(uri string) bool

IsRoot reports whether the given URI is a root document.

func (*Discovery) RemoveFile

func (d *Discovery) RemoveFile(path string)

RemoveFile removes a file from the discovery cache (after deletion).

func (*Discovery) Roots

func (d *Discovery) Roots() []string

Roots returns the URIs of all discovered root documents.

func (*Discovery) Scan

func (d *Discovery) Scan(workspaceRoot string) error

Scan walks the given workspace root, discovering and classifying all YAML and JSON files. Files matching exclude patterns are skipped. The scan replaces any previous results.

func (*Discovery) UpdateFile

func (d *Discovery) UpdateFile(path string) *DiscoveredFile

UpdateFile re-classifies a single file (after a change event) and updates the discovery cache. Returns the updated DiscoveredFile.

type FileGraph

type FileGraph = navigator.FileGraph

FileGraph is an alias for navigator.FileGraph.

type FileRole

type FileRole int

FileRole classifies a file's role in an OpenAPI project.

const (
	RoleUnknown  FileRole = iota
	RoleRoot              // Has openapi/swagger version key + paths (entry point)
	RoleFragment          // Referenced via $ref, no root version key, or no paths
)

type Manager

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

Manager coordinates workspace scanning, project context building, and repo-wide diagnostic publishing. It is the top-level orchestrator for cross-file OpenAPI analysis.

func NewManager

func NewManager(indexCache *openapi.IndexCache, logger *slog.Logger) *Manager

NewManager creates a project Manager.

func (*Manager) Discovery

func (m *Manager) Discovery() *Discovery

Discovery returns the underlying file discovery instance.

func (*Manager) Initialize

func (m *Manager) Initialize(workspaceRoot string, exclude []string)

Initialize performs workspace discovery and builds project contexts for all root documents. Call this on server initialized.

func (*Manager) OnFileChanged

func (m *Manager) OnFileChanged(uri string)

OnFileChanged should be called when a file is modified. It rebuilds the affected project indexes and re-publishes diagnostics.

func (*Manager) OnFileCreated

func (m *Manager) OnFileCreated(path string)

OnFileCreated should be called when a new file appears. It may need to add the file to existing projects or create new ones.

func (*Manager) OnFileDeleted

func (m *Manager) OnFileDeleted(path string)

OnFileDeleted should be called when a file is removed.

func (*Manager) ProjectForFile

func (m *Manager) ProjectForFile(uri string) *ProjectContext

ProjectForFile returns the ProjectContext that contains the given URI. Returns nil if the file is not part of any known project.

func (*Manager) Projects

func (m *Manager) Projects() map[string]*ProjectContext

Projects returns all current project contexts.

func (*Manager) ResolverForFile

func (m *Manager) ResolverForFile(uri string) rules.CrossRefResolver

ResolverForFile returns a CrossRefResolver for the given file's project, satisfying the rules.CrossRefResolver interface. Returns nil if the file is not part of any known project.

func (*Manager) SetAnalyzers

func (m *Manager) SetAnalyzers(a []rules.NamedAnalyzer)

SetAnalyzers sets the rule analyzers to run during startup diagnostics.

func (*Manager) SetOnDiscovered

func (m *Manager) SetOnDiscovered(fn func([]*DiscoveredFile))

SetOnDiscovered registers a callback that receives the full workspace file list after discovery completes and before project contexts are built.

func (*Manager) SetPublish

func (m *Manager) SetPublish(fn PublishFunc)

SetPublish sets the function used to send project-level diagnostics.

func (*Manager) SetResolver

func (m *Manager) SetResolver(resolver rules.CrossRefResolver)

SetResolver sets the cross-file resolver used for analyzer inputs and unresolved-ref checks. When nil, the manager falls back to project-local resolvers.

func (*Manager) SetShouldPublish

func (m *Manager) SetShouldPublish(fn func(uri string) bool)

SetShouldPublish sets a URI-level filter for project diagnostic publishing. When nil, all URIs are publishable.

func (*Manager) WaitReady

func (m *Manager) WaitReady(timeout time.Duration) bool

WaitReady blocks until project initialization has completed or the timeout elapses. Returns true if the manager is ready, false on timeout.

type ProjectContext

type ProjectContext struct {
	RootURI  string
	Docs     map[string]*openapi.Index
	Graph    *FileGraph
	Resolver *CrossFileResolver
	// contains filtered or unexported fields
}

ProjectContext represents a single OpenAPI "project" consisting of a root document and all files transitively referenced via $ref. It is analogous to a TypeScript Program that includes all source files reachable from the tsconfig entry points.

func BuildProjectContext

func BuildProjectContext(rootURI string, indexCache *openapi.IndexCache, logger *slog.Logger) (*ProjectContext, error)

BuildProjectContext creates a ProjectContext starting from a root document URI. It reads the root file from disk, builds its index, follows all external $refs transitively, and constructs the dependency graph.

The indexCache is consulted first; if the URI is already cached (e.g., from an open document), that index is used instead of re-reading from disk.

func (*ProjectContext) AllURIs

func (p *ProjectContext) AllURIs() []string

AllURIs returns every file URI in the project.

func (*ProjectContext) ContainsFile

func (p *ProjectContext) ContainsFile(uri string) bool

ContainsFile reports whether the given URI is part of this project. The URI is normalized before lookup to handle encoding differences.

func (*ProjectContext) DocIndex

func (p *ProjectContext) DocIndex(uri string) *openapi.Index

DocIndex returns the index for a single URI, or nil if not found.

func (*ProjectContext) DocsSnapshot

func (p *ProjectContext) DocsSnapshot() map[string]*openapi.Index

DocsSnapshot returns a shallow copy of the Docs map for safe iteration.

func (*ProjectContext) GetResolver

func (p *ProjectContext) GetResolver() *CrossFileResolver

GetResolver returns the current cross-file resolver.

func (*ProjectContext) RebuildIndex

func (p *ProjectContext) RebuildIndex(uri string, cache *openapi.IndexCache) error

RebuildIndex re-indexes a single file within the project, updating the graph and resolver. Newly referenced files are loaded transitively.

type PublishFunc

type PublishFunc func(ctx context.Context, uri protocol.DocumentURI, diags []protocol.Diagnostic) error

PublishFunc sends diagnostics for a given URI to the LSP client.

type RefEdge

type RefEdge = navigator.RefEdge

RefEdge is an alias for navigator.RefEdge.

func ExtractExternalRefs

func ExtractExternalRefs(sourceURI string, idx *openapi.Index) []RefEdge

ExtractExternalRefs scans an index's $ref usages and returns RefEdge entries for references that point to external files. Local-only refs (#/...) are skipped.

type ResolveResult

type ResolveResult struct {
	TargetURI   string
	TargetIndex *openapi.Index
	Value       interface{}
}

ResolveResult holds the outcome of a cross-file $ref resolution.

Jump to

Keyboard shortcuts

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