2024-02-15 13:56:31 -08:00
|
|
|
//! The servers that power the text editor.
|
2023-09-05 16:02:27 -07:00
|
|
|
|
2024-04-15 17:18:32 -07:00
|
|
|
pub mod backend;
|
2024-02-15 13:56:31 -08:00
|
|
|
pub mod copilot;
|
2024-02-19 12:33:16 -08:00
|
|
|
pub mod kcl;
|
2024-06-27 15:43:49 -07:00
|
|
|
#[cfg(any(test, feature = "lsp-test-util"))]
|
|
|
|
pub mod test_util;
|
2024-03-12 23:57:43 -07:00
|
|
|
#[cfg(test)]
|
|
|
|
mod tests;
|
2024-04-15 17:18:32 -07:00
|
|
|
pub mod util;
|
2024-06-11 19:23:35 -04:00
|
|
|
|
2024-12-06 13:57:31 +13:00
|
|
|
use tower_lsp::lsp_types::{Diagnostic, DiagnosticSeverity, DiagnosticTag};
|
2024-06-11 19:23:35 -04:00
|
|
|
pub use util::IntoDiagnostic;
|
2024-12-06 13:57:31 +13:00
|
|
|
|
|
|
|
use crate::{
|
|
|
|
errors::{Severity, Tag},
|
|
|
|
CompilationError,
|
|
|
|
};
|
|
|
|
|
|
|
|
impl IntoDiagnostic for CompilationError {
|
2025-02-26 19:29:59 -08:00
|
|
|
fn to_lsp_diagnostics(&self, code: &str) -> Vec<Diagnostic> {
|
2025-04-28 12:07:10 -07:00
|
|
|
let edit = self.suggestion.as_ref().map(|s| s.to_lsp_edit(code));
|
2024-12-06 13:57:31 +13:00
|
|
|
|
2025-02-26 19:29:59 -08:00
|
|
|
vec![Diagnostic {
|
2024-12-06 13:57:31 +13:00
|
|
|
range: self.source_range.to_lsp_range(code),
|
|
|
|
severity: Some(self.severity()),
|
|
|
|
code: None,
|
|
|
|
code_description: None,
|
|
|
|
source: Some("kcl".to_string()),
|
|
|
|
message: self.message.clone(),
|
|
|
|
related_information: None,
|
|
|
|
tags: self.tag.to_lsp_tags(),
|
2025-04-28 12:07:10 -07:00
|
|
|
data: edit.map(|e| serde_json::to_value(e).unwrap()),
|
2025-02-26 19:29:59 -08:00
|
|
|
}]
|
2024-12-06 13:57:31 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
fn severity(&self) -> DiagnosticSeverity {
|
|
|
|
match self.severity {
|
|
|
|
Severity::Warning => DiagnosticSeverity::WARNING,
|
|
|
|
_ => DiagnosticSeverity::ERROR,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Tag {
|
|
|
|
fn to_lsp_tags(self) -> Option<Vec<DiagnosticTag>> {
|
|
|
|
match self {
|
|
|
|
Tag::Deprecated => Some(vec![DiagnosticTag::DEPRECATED]),
|
|
|
|
Tag::Unnecessary => Some(vec![DiagnosticTag::UNNECESSARY]),
|
|
|
|
Tag::None => None,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|