Skip to main content

Ecosystem

Trait Ecosystem 

Source
pub trait Ecosystem:
    Send
    + Sync
    + Sealed {
Show 14 methods // Required methods fn id(&self) -> &'static str; fn display_name(&self) -> &'static str; fn manifest_filenames(&self) -> &[&'static str]; fn parse_manifest<'a>( &'a self, content: &'a str, uri: &'a Uri, ) -> BoxFuture<'a, Result<Box<dyn ParseResult>>>; fn registry(&self) -> Arc<dyn Registry>; fn formatter(&self) -> &dyn EcosystemFormatter; fn generate_completions<'a>( &'a self, parse_result: &'a dyn ParseResult, position: Position, content: &'a str, ) -> BoxFuture<'a, Vec<CompletionItem>>; fn as_any(&self) -> &dyn Any; // Provided methods fn lockfile_filenames(&self) -> &[&'static str] { ... } fn lockfile_provider(&self) -> Option<Arc<dyn LockFileProvider>> { ... } fn generate_inlay_hints<'a>( &'a self, parse_result: &'a dyn ParseResult, cached_versions: &'a HashMap<String, String>, resolved_versions: &'a HashMap<String, String>, loading_state: LoadingState, config: &'a EcosystemConfig, ) -> BoxFuture<'a, Vec<InlayHint>> { ... } fn generate_hover<'a>( &'a self, parse_result: &'a dyn ParseResult, position: Position, cached_versions: &'a HashMap<String, String>, resolved_versions: &'a HashMap<String, String>, ) -> BoxFuture<'a, Option<Hover>> { ... } fn generate_code_actions<'a>( &'a self, parse_result: &'a dyn ParseResult, position: Position, _cached_versions: &'a HashMap<String, String>, uri: &'a Uri, ) -> BoxFuture<'a, Vec<CodeAction>> { ... } fn generate_diagnostics<'a>( &'a self, parse_result: &'a dyn ParseResult, cached_versions: &'a HashMap<String, String>, resolved_versions: &'a HashMap<String, String>, _uri: &'a Uri, ) -> BoxFuture<'a, Vec<Diagnostic>> { ... }
}
Expand description

Main trait that all ecosystem implementations must implement.

Each ecosystem (Cargo, npm, PyPI, etc.) provides its own implementation. This trait defines the contract for parsing manifests, fetching registry data, and generating LSP responses.

§Type Erasure

This trait uses Box<dyn Trait> instead of associated types to allow runtime polymorphism and dynamic ecosystem registration.

§Examples

use deps_core::{Ecosystem, ParseResult, Registry, EcosystemConfig};
use deps_core::lsp_helpers::EcosystemFormatter;
use std::sync::Arc;
use std::any::Any;
use tower_lsp_server::ls_types::{Uri, CompletionItem, Position};

struct MyFormatter;
impl EcosystemFormatter for MyFormatter {
    fn format_version_for_text_edit(&self, version: &str) -> String { version.to_string() }
    fn package_url(&self, name: &str) -> String { format!("https://example.com/{name}") }
}

struct MyEcosystem {
    registry: Arc<dyn Registry>,
    formatter: MyFormatter,
}

impl deps_core::ecosystem::private::Sealed for MyEcosystem {}

impl Ecosystem for MyEcosystem {
    fn id(&self) -> &'static str { "my-ecosystem" }
    fn display_name(&self) -> &'static str { "My Ecosystem" }
    fn manifest_filenames(&self) -> &[&'static str] { &["my-manifest.toml"] }

    fn parse_manifest<'a>(
        &'a self,
        _content: &'a str,
        _uri: &'a Uri,
    ) -> deps_core::ecosystem::BoxFuture<'a, deps_core::error::Result<Box<dyn ParseResult>>> {
        Box::pin(async move { todo!() })
    }

    fn registry(&self) -> Arc<dyn Registry> { self.registry.clone() }

    fn formatter(&self) -> &dyn EcosystemFormatter { &self.formatter }

    fn generate_completions<'a>(
        &'a self,
        _parse_result: &'a dyn ParseResult,
        _position: Position,
        _content: &'a str,
    ) -> deps_core::ecosystem::BoxFuture<'a, Vec<CompletionItem>> {
        Box::pin(async move { vec![] })
    }

    fn as_any(&self) -> &dyn Any { self }
}

Required Methods§

Source

fn id(&self) -> &'static str

Unique identifier (e.g., “cargo”, “npm”, “pypi”)

This identifier is used for ecosystem registration and routing.

Source

fn display_name(&self) -> &'static str

Human-readable name (e.g., “Cargo (Rust)”, “npm (JavaScript)”)

This name is displayed in diagnostic messages and logs.

Source

fn manifest_filenames(&self) -> &[&'static str]

Manifest filenames this ecosystem handles (e.g., [“Cargo.toml”])

The ecosystem registry uses these filenames to route file URIs to the appropriate ecosystem implementation.

Source

fn parse_manifest<'a>( &'a self, content: &'a str, uri: &'a Uri, ) -> BoxFuture<'a, Result<Box<dyn ParseResult>>>

Parse a manifest file and return parsed result

§Arguments
  • content - Raw file content
  • uri - Document URI for position tracking
§Errors

Returns error if manifest cannot be parsed

Source

fn registry(&self) -> Arc<dyn Registry>

Get the registry client for this ecosystem

The registry provides version lookup and package search capabilities.

Source

fn formatter(&self) -> &dyn EcosystemFormatter

Get the ecosystem-specific formatter for LSP response generation.

The formatter handles version comparison, package URLs, and text formatting. Override this to customize LSP response generation.

Source

fn generate_completions<'a>( &'a self, parse_result: &'a dyn ParseResult, position: Position, content: &'a str, ) -> BoxFuture<'a, Vec<CompletionItem>>

Generate completions for a position.

Provides autocomplete suggestions for package names and versions.

Source

fn as_any(&self) -> &dyn Any

Support for downcasting to concrete ecosystem type

This allows ecosystem-specific operations when needed.

Provided Methods§

Source

fn lockfile_filenames(&self) -> &[&'static str]

Lock file filenames this ecosystem uses (e.g., [“Cargo.lock”])

Used for file watching - LSP will monitor changes to these files and refresh UI when they change. Returns empty slice if ecosystem doesn’t use lock files.

§Default Implementation

Returns empty slice by default, indicating no lock files are used.

Source

fn lockfile_provider(&self) -> Option<Arc<dyn LockFileProvider>>

Get the lock file provider for this ecosystem.

Returns None if the ecosystem doesn’t support lock files. Lock files provide resolved dependency versions without network requests.

Source

fn generate_inlay_hints<'a>( &'a self, parse_result: &'a dyn ParseResult, cached_versions: &'a HashMap<String, String>, resolved_versions: &'a HashMap<String, String>, loading_state: LoadingState, config: &'a EcosystemConfig, ) -> BoxFuture<'a, Vec<InlayHint>>

Generate inlay hints for the document.

Default implementation delegates to lsp_helpers::generate_inlay_hints using self.formatter(). Override only if custom behavior is needed.

Source

fn generate_hover<'a>( &'a self, parse_result: &'a dyn ParseResult, position: Position, cached_versions: &'a HashMap<String, String>, resolved_versions: &'a HashMap<String, String>, ) -> BoxFuture<'a, Option<Hover>>

Generate hover information for a position.

Default implementation delegates to lsp_helpers::generate_hover using self.formatter() and self.registry().

Source

fn generate_code_actions<'a>( &'a self, parse_result: &'a dyn ParseResult, position: Position, _cached_versions: &'a HashMap<String, String>, uri: &'a Uri, ) -> BoxFuture<'a, Vec<CodeAction>>

Generate code actions for a position.

Default implementation delegates to lsp_helpers::generate_code_actions using self.formatter() and self.registry().

Source

fn generate_diagnostics<'a>( &'a self, parse_result: &'a dyn ParseResult, cached_versions: &'a HashMap<String, String>, resolved_versions: &'a HashMap<String, String>, _uri: &'a Uri, ) -> BoxFuture<'a, Vec<Diagnostic>>

Generate diagnostics for the document.

Default implementation delegates to lsp_helpers::generate_diagnostics_from_cache using self.formatter().

Implementors§