diff options
Diffstat (limited to 'crates/server/src/handlers.rs')
-rw-r--r-- | crates/server/src/handlers.rs | 21 |
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 @@ | |||
1 | use languageserver_types::{Range, Position}; | 1 | use url::Url; |
2 | use languageserver_types::{Range, Position, Diagnostic, DiagnosticSeverity}; | ||
2 | use libanalysis::World; | 3 | use libanalysis::World; |
3 | use libeditor::{self, LineIndex, LineCol, TextRange, TextUnit}; | 4 | use libeditor::{self, LineIndex, LineCol, TextRange, TextUnit}; |
5 | |||
4 | use {req, Result, FilePath}; | 6 | use {req, Result, FilePath}; |
5 | 7 | ||
6 | pub fn handle_syntax_tree( | 8 | pub 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 | ||
34 | pub 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 | ||
33 | fn to_text_range(line_index: &LineIndex, range: Range) -> TextRange { | 52 | fn to_text_range(line_index: &LineIndex, range: Range) -> TextRange { |
34 | TextRange::from_to( | 53 | TextRange::from_to( |