aboutsummaryrefslogtreecommitdiff
path: root/crates/server/src/handlers.rs
diff options
context:
space:
mode:
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(