1use async_trait::async_trait;
4use std::path::Path;
5
6use super::{
7 DependencyConflict, Package, Requirement, ResolvedContext, Result, Version, VersionConstraint,
8};
9
10#[async_trait]
12pub trait ConfigProvider: Send + Sync {
13 async fn get_package_paths(&self) -> Result<Vec<std::path::PathBuf>>;
15
16 async fn get_local_packages_path(&self) -> Result<Option<std::path::PathBuf>>;
18
19 async fn get_release_packages_path(&self) -> Result<Option<std::path::PathBuf>>;
21
22 async fn validate(&self) -> Result<()>;
24
25 async fn reload(&mut self) -> Result<()>;
27}
28
29#[async_trait]
31pub trait PackageDiscovery: Send + Sync {
32 async fn scan_packages(&mut self) -> Result<()>;
34
35 async fn find_packages(&self, pattern: &str) -> Result<Vec<Package>>;
37
38 async fn get_package_versions(&self, name: &str) -> Result<Vec<Package>>;
40
41 async fn get_all_package_names(&self) -> Result<Vec<String>>;
43
44 async fn get_package(&self, name: &str, version: &Version) -> Result<Option<Package>>;
46
47 async fn get_stats(&self) -> Result<(usize, usize)>; async fn clear_cache(&mut self) -> Result<()>;
52}
53
54#[async_trait]
56pub trait PackageParser: Send + Sync {
57 async fn parse_package_file(&self, path: &Path) -> Result<Package>;
59
60 async fn parse_package_content(&self, content: &str, base_path: &Path) -> Result<Package>;
62
63 async fn validate_syntax(&self, content: &str) -> Result<Vec<SyntaxError>>;
65
66 async fn extract_requirements(&self, content: &str) -> Result<Vec<Requirement>>;
68}
69
70#[async_trait]
72pub trait DependencyResolver: Send + Sync {
73 async fn resolve(&self, requirements: &[Requirement]) -> Result<ResolvedContext>;
75
76 async fn can_resolve(&self, requirements: &[Requirement]) -> Result<bool>;
78
79 async fn find_conflicts(&self, requirements: &[Requirement])
81 -> Result<Vec<DependencyConflict>>;
82
83 async fn get_latest_version(
85 &self,
86 name: &str,
87 constraint: &VersionConstraint,
88 ) -> Result<Option<Version>>;
89}
90
91#[async_trait]
93pub trait CompletionProvider: Send + Sync {
94 async fn complete_package_names(&self, prefix: &str) -> Result<Vec<CompletionItem>>;
96
97 async fn complete_versions(
99 &self,
100 package_name: &str,
101 prefix: &str,
102 ) -> Result<Vec<CompletionItem>>;
103
104 async fn complete_requirements(&self, prefix: &str) -> Result<Vec<CompletionItem>>;
106
107 async fn complete_tools(&self, prefix: &str) -> Result<Vec<CompletionItem>>;
109}
110
111#[async_trait]
113pub trait HoverProvider: Send + Sync {
114 async fn hover_package(
116 &self,
117 name: &str,
118 version: Option<&Version>,
119 ) -> Result<Option<HoverInfo>>;
120
121 async fn hover_requirement(&self, requirement: &str) -> Result<Option<HoverInfo>>;
123
124 async fn hover_tool(&self, tool: &str) -> Result<Option<HoverInfo>>;
126}
127
128#[async_trait]
130pub trait DiagnosticProvider: Send + Sync {
131 async fn analyze_package(&self, content: &str, path: &Path) -> Result<Vec<Diagnostic>>;
133
134 async fn check_conflicts(&self, requirements: &[Requirement]) -> Result<Vec<Diagnostic>>;
136
137 async fn validate_syntax(&self, content: &str) -> Result<Vec<Diagnostic>>;
139}
140
141#[derive(Debug, Clone)]
143pub struct CompletionItem {
144 pub label: String,
146 pub kind: CompletionItemKind,
148 pub detail: Option<String>,
150 pub documentation: Option<String>,
152 pub insert_text: Option<String>,
154 pub sort_text: Option<String>,
156}
157
158#[derive(Debug, Clone, Copy, PartialEq, Eq)]
160pub enum CompletionItemKind {
161 Package,
163 Version,
165 Tool,
167 Requirement,
169 Keyword,
171 Variable,
173 Function,
175}
176
177#[derive(Debug, Clone)]
179pub struct HoverInfo {
180 pub content: String,
182 pub range: Option<Range>,
184}
185
186#[derive(Debug, Clone, Copy, PartialEq, Eq)]
188pub struct Range {
189 pub start: Position,
191 pub end: Position,
193}
194
195#[derive(Debug, Clone, Copy, PartialEq, Eq)]
197pub struct Position {
198 pub line: u32,
200 pub character: u32,
202}
203
204#[derive(Debug, Clone)]
206pub struct Diagnostic {
207 pub range: Range,
209 pub severity: DiagnosticSeverity,
211 pub message: String,
213 pub source: Option<String>,
215 pub code: Option<String>,
217}
218
219#[derive(Debug, Clone, Copy, PartialEq, Eq)]
221pub enum DiagnosticSeverity {
222 Error,
224 Warning,
226 Information,
228 Hint,
230}
231
232#[derive(Debug, Clone)]
234pub struct SyntaxError {
235 pub range: Range,
237 pub message: String,
239 pub suggestions: Vec<String>,
241}