From 36d922c87d0c933803441bde825ace5658af78b2 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 10 Aug 2018 23:30:11 +0300 Subject: diagnostics --- crates/server/src/handlers.rs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'crates/server/src/handlers.rs') diff --git a/crates/server/src/handlers.rs b/crates/server/src/handlers.rs index 5ee87a4dd..1f55e8669 100644 --- a/crates/server/src/handlers.rs +++ b/crates/server/src/handlers.rs @@ -1,6 +1,8 @@ -use languageserver_types::{Range, Position}; +use url::Url; +use languageserver_types::{Range, Position, Diagnostic, DiagnosticSeverity}; use libanalysis::World; use libeditor::{self, LineIndex, LineCol, TextRange, TextUnit}; + use {req, Result, FilePath}; pub fn handle_syntax_tree( @@ -29,6 +31,23 @@ pub fn handle_extend_selection( Ok(req::ExtendSelectionResult { selections }) } +pub fn publish_diagnostics(world: World, uri: Url) -> Result { + let path = uri.file_path()?; + let file = world.file_syntax(&path)?; + let line_index = world.file_line_index(&path)?; + let diagnostics = libeditor::diagnostics(&file) + .into_iter() + .map(|d| Diagnostic { + range: to_vs_range(&line_index, d.range), + severity: Some(DiagnosticSeverity::Error), + code: None, + source: Some("libsyntax2".to_string()), + message: d.msg, + related_information: None, + }).collect(); + Ok(req::PublishDiagnosticsParams { uri, diagnostics }) +} + fn to_text_range(line_index: &LineIndex, range: Range) -> TextRange { TextRange::from_to( -- cgit v1.2.3