use async_trait::async_trait;
use std::path::Path;
use super::{
DependencyConflict, Package, Requirement, ResolvedContext, Result, Version, VersionConstraint,
};
#[async_trait]
pub trait ConfigProvider: Send + Sync {
async fn get_package_paths(&self) -> Result<Vec<std::path::PathBuf>>;
async fn get_local_packages_path(&self) -> Result<Option<std::path::PathBuf>>;
async fn get_release_packages_path(&self) -> Result<Option<std::path::PathBuf>>;
async fn validate(&self) -> Result<()>;
async fn reload(&mut self) -> Result<()>;
}
#[async_trait]
pub trait PackageDiscovery: Send + Sync {
async fn scan_packages(&mut self) -> Result<()>;
async fn find_packages(&self, pattern: &str) -> Result<Vec<Package>>;
async fn get_package_versions(&self, name: &str) -> Result<Vec<Package>>;
async fn get_all_package_names(&self) -> Result<Vec<String>>;
async fn get_package(&self, name: &str, version: &Version) -> Result<Option<Package>>;
async fn get_stats(&self) -> Result<(usize, usize)>;
async fn clear_cache(&mut self) -> Result<()>;
}
#[async_trait]
pub trait PackageParser: Send + Sync {
async fn parse_package_file(&self, path: &Path) -> Result<Package>;
async fn parse_package_content(&self, content: &str, base_path: &Path) -> Result<Package>;
async fn validate_syntax(&self, content: &str) -> Result<Vec<SyntaxError>>;
async fn extract_requirements(&self, content: &str) -> Result<Vec<Requirement>>;
}
#[async_trait]
pub trait DependencyResolver: Send + Sync {
async fn resolve(&self, requirements: &[Requirement]) -> Result<ResolvedContext>;
async fn can_resolve(&self, requirements: &[Requirement]) -> Result<bool>;
async fn find_conflicts(&self, requirements: &[Requirement])
-> Result<Vec<DependencyConflict>>;
async fn get_latest_version(
&self,
name: &str,
constraint: &VersionConstraint,
) -> Result<Option<Version>>;
}
#[async_trait]
pub trait CompletionProvider: Send + Sync {
async fn complete_package_names(&self, prefix: &str) -> Result<Vec<CompletionItem>>;
async fn complete_versions(
&self,
package_name: &str,
prefix: &str,
) -> Result<Vec<CompletionItem>>;
async fn complete_requirements(&self, prefix: &str) -> Result<Vec<CompletionItem>>;
async fn complete_tools(&self, prefix: &str) -> Result<Vec<CompletionItem>>;
}
#[async_trait]
pub trait HoverProvider: Send + Sync {
async fn hover_package(
&self,
name: &str,
version: Option<&Version>,
) -> Result<Option<HoverInfo>>;
async fn hover_requirement(&self, requirement: &str) -> Result<Option<HoverInfo>>;
async fn hover_tool(&self, tool: &str) -> Result<Option<HoverInfo>>;
}
#[async_trait]
pub trait DiagnosticProvider: Send + Sync {
async fn analyze_package(&self, content: &str, path: &Path) -> Result<Vec<Diagnostic>>;
async fn check_conflicts(&self, requirements: &[Requirement]) -> Result<Vec<Diagnostic>>;
async fn validate_syntax(&self, content: &str) -> Result<Vec<Diagnostic>>;
}
#[derive(Debug, Clone)]
pub struct CompletionItem {
pub label: String,
pub kind: CompletionItemKind,
pub detail: Option<String>,
pub documentation: Option<String>,
pub insert_text: Option<String>,
pub sort_text: Option<String>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum CompletionItemKind {
Package,
Version,
Tool,
Requirement,
Keyword,
Variable,
Function,
}
#[derive(Debug, Clone)]
pub struct HoverInfo {
pub content: String,
pub range: Option<Range>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Range {
pub start: Position,
pub end: Position,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Position {
pub line: u32,
pub character: u32,
}
#[derive(Debug, Clone)]
pub struct Diagnostic {
pub range: Range,
pub severity: DiagnosticSeverity,
pub message: String,
pub source: Option<String>,
pub code: Option<String>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum DiagnosticSeverity {
Error,
Warning,
Information,
Hint,
}
#[derive(Debug, Clone)]
pub struct SyntaxError {
pub range: Range,
pub message: String,
pub suggestions: Vec<String>,
}