Files
modeling-app/rust/kcl-lib/src/lsp/mod.rs
Jess Frazelle 94452cce88 ability to set suggestions on lints (#6535)
* fix the lint tests which were not compiling

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* updates

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* apply sugggestions for offsetplanes

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* updates

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* diagnostics and suggestions for offset planes

Signed-off-by: Jess Frazelle <github@jessfraz.com>

---------

Signed-off-by: Jess Frazelle <github@jessfraz.com>
2025-04-29 07:07:10 +12:00

54 lines
1.4 KiB
Rust

//! The servers that power the text editor.
pub mod backend;
pub mod copilot;
pub mod kcl;
#[cfg(any(test, feature = "lsp-test-util"))]
pub mod test_util;
#[cfg(test)]
mod tests;
pub mod util;
use tower_lsp::lsp_types::{Diagnostic, DiagnosticSeverity, DiagnosticTag};
pub use util::IntoDiagnostic;
use crate::{
errors::{Severity, Tag},
CompilationError,
};
impl IntoDiagnostic for CompilationError {
fn to_lsp_diagnostics(&self, code: &str) -> Vec<Diagnostic> {
let edit = self.suggestion.as_ref().map(|s| s.to_lsp_edit(code));
vec![Diagnostic {
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(),
data: edit.map(|e| serde_json::to_value(e).unwrap()),
}]
}
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,
}
}
}