use super::*;
use std::path::{Component, Path, PathBuf};
pub(crate) fn create_error_diagnostic(code: &str, message: String) -> Diagnostic {
Diagnostic {
range: Range {
start: Position {
line: 0,
character: 0,
},
end: Position {
line: 0,
character: 0,
},
},
severity: Some(DiagnosticSeverity::ERROR),
code: Some(NumberOrString::String(code.to_string())),
code_description: None,
source: Some("agnix".to_string()),
message,
related_information: None,
tags: None,
data: None,
}
}
pub(crate) fn normalize_path(path: &Path) -> PathBuf {
let mut components: Vec<Component<'_>> = Vec::new();
for component in path.components() {
match component {
Component::CurDir => {}
Component::ParentDir => {
match components.last() {
Some(Component::Normal(_)) => {
components.pop();
}
Some(Component::RootDir) | Some(Component::Prefix(_)) => {}
_ => components.push(component),
}
}
_ => components.push(component),
}
}
components.iter().collect()
}
impl Backend {
pub(crate) fn is_project_level_trigger(path: &Path) -> bool {
let file_name = match path.file_name().and_then(|n| n.to_str()) {
Some(name) => name,
None => return false,
};
if file_name.eq_ignore_ascii_case(".agnix.toml") {
return true;
}
file_name.eq_ignore_ascii_case("claude.md")
|| file_name.eq_ignore_ascii_case("claude.local.md")
|| file_name.eq_ignore_ascii_case("agents.md")
|| file_name.eq_ignore_ascii_case("agents.local.md")
|| file_name.eq_ignore_ascii_case("agents.override.md")
|| file_name.eq_ignore_ascii_case("gemini.md")
|| file_name.eq_ignore_ascii_case("gemini.local.md")
|| file_name.eq_ignore_ascii_case(".clinerules")
|| file_name.eq_ignore_ascii_case(".cursorrules")
|| file_name.eq_ignore_ascii_case(".cursorrules.md")
|| file_name.eq_ignore_ascii_case("copilot-instructions.md")
|| file_name.to_lowercase().ends_with(".instructions.md")
|| file_name.to_lowercase().ends_with(".mdc")
|| file_name.eq_ignore_ascii_case("opencode.json")
}
pub(crate) async fn get_document_content(&self, uri: &Url) -> Option<Arc<String>> {
self.documents.read().await.get(uri).cloned()
}
pub(crate) async fn get_document_version(&self, uri: &Url) -> Option<i32> {
self.document_versions.read().await.get(uri).copied()
}
}