use std::collections::HashMap;
use serde_json::Value;
#[derive(Debug, Clone)]
pub enum LspEvent {
Diagnostics {
client: String,
uri: String,
items: Vec<Diagnostic>,
},
Message { level: u8, text: String },
Response {
client: String,
id: u64,
result: Option<Value>,
error: Option<String>,
},
Error { client: String, message: String },
}
#[derive(Debug, Clone)]
pub struct Diagnostic {
pub range: Range,
pub severity: Severity,
pub message: String,
pub source: Option<String>,
}
#[derive(Debug, Clone, Copy)]
pub struct Range {
pub start: Position,
pub end: Position,
}
#[derive(Debug, Clone, Copy)]
pub struct Position {
pub line: u32,
pub character: u32,
}
#[derive(Debug, Clone)]
pub struct Location {
pub uri: String,
pub range: Range,
}
#[derive(Debug, Clone)]
pub struct Hover {
pub contents: String,
}
#[derive(Debug, Clone)]
pub struct TextEdit {
pub range: Range,
pub new_text: String,
}
#[derive(Debug, Clone)]
pub struct CompletionItem {
pub label: String,
pub kind: u8,
pub text_edit: Option<TextEdit>,
pub insert_text: Option<String>,
pub filter_text: Option<String>,
pub sort_text: Option<String>,
pub detail: Option<String>,
pub additional_text_edits: Vec<TextEdit>,
pub raw: Value,
pub source: String,
}
#[derive(Debug, Clone, Default)]
pub struct WorkspaceEdit {
pub changes: HashMap<String, Vec<TextEdit>>,
}
#[derive(Debug, Clone)]
pub struct CodeAction {
pub title: String,
pub edit: Option<WorkspaceEdit>,
pub raw: Value,
pub source: String,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Severity {
Error,
Warning,
Info,
Hint,
}
impl Severity {
pub(super) fn from_code(c: i64) -> Severity {
match c {
1 => Severity::Error,
2 => Severity::Warning,
3 => Severity::Info,
_ => Severity::Hint,
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn severity_from_code_defaults_to_hint() {
assert_eq!(Severity::from_code(1), Severity::Error);
assert_eq!(Severity::from_code(4), Severity::Hint);
assert_eq!(Severity::from_code(99), Severity::Hint);
}
}