aboutsummaryrefslogtreecommitdiff
path: root/crates/server/src/handlers.rs
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-08-10 21:30:11 +0100
committerAleksey Kladov <[email protected]>2018-08-10 21:30:11 +0100
commit36d922c87d0c933803441bde825ace5658af78b2 (patch)
tree3c14a27b678cc01a02c04be04784b21b4366e964 /crates/server/src/handlers.rs
parent5896cd51de65cb6f7b8f3a4df85c4eb8886b76e2 (diff)
diagnostics
Diffstat (limited to 'crates/server/src/handlers.rs')
-rw-r--r--crates/server/src/handlers.rs21
1 files changed, 20 insertions, 1 deletions
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 @@
1use languageserver_types::{Range, Position}; 1use url::Url;
2use languageserver_types::{Range, Position, Diagnostic, DiagnosticSeverity};
2use libanalysis::World; 3use libanalysis::World;
3use libeditor::{self, LineIndex, LineCol, TextRange, TextUnit}; 4use libeditor::{self, LineIndex, LineCol, TextRange, TextUnit};
5
4use {req, Result, FilePath}; 6use {req, Result, FilePath};
5 7
6pub fn handle_syntax_tree( 8pub fn handle_syntax_tree(
@@ -29,6 +31,23 @@ pub fn handle_extend_selection(
29 Ok(req::ExtendSelectionResult { selections }) 31 Ok(req::ExtendSelectionResult { selections })
30} 32}
31 33
34pub fn publish_diagnostics(world: World, uri: Url) -> Result<req::PublishDiagnosticsParams> {
35 let path = uri.file_path()?;
36 let file = world.file_syntax(&path)?;
37 let line_index = world.file_line_index(&path)?;
38 let diagnostics = libeditor::diagnostics(&file)
39 .into_iter()
40 .map(|d| Diagnostic {
41 range: to_vs_range(&line_index, d.range),
42 severity: Some(DiagnosticSeverity::Error),
43 code: None,
44 source: Some("libsyntax2".to_string()),
45 message: d.msg,
46 related_information: None,
47 }).collect();
48 Ok(req::PublishDiagnosticsParams { uri, diagnostics })
49}
50
32 51
33fn to_text_range(line_index: &LineIndex, range: Range) -> TextRange { 52fn to_text_range(line_index: &LineIndex, range: Range) -> TextRange {
34 TextRange::from_to( 53 TextRange::from_to(