diff options
Diffstat (limited to 'crates/server/src')
-rw-r--r-- | crates/server/src/handlers.rs | 14 | ||||
-rw-r--r-- | crates/server/src/main.rs | 21 | ||||
-rw-r--r-- | crates/server/src/req.rs | 24 |
3 files changed, 53 insertions, 6 deletions
diff --git a/crates/server/src/handlers.rs b/crates/server/src/handlers.rs index de1fd557d..8b7e00c92 100644 --- a/crates/server/src/handlers.rs +++ b/crates/server/src/handlers.rs | |||
@@ -4,7 +4,7 @@ use libanalysis::World; | |||
4 | use libeditor::{self, LineIndex, LineCol, TextRange, TextUnit}; | 4 | use libeditor::{self, LineIndex, LineCol, TextRange, TextUnit}; |
5 | 5 | ||
6 | use ::{ | 6 | use ::{ |
7 | req, Result, | 7 | req::{self, Decoration}, Result, |
8 | util::FilePath, | 8 | util::FilePath, |
9 | }; | 9 | }; |
10 | 10 | ||
@@ -51,6 +51,18 @@ pub fn publish_diagnostics(world: World, uri: Url) -> Result<req::PublishDiagnos | |||
51 | Ok(req::PublishDiagnosticsParams { uri, diagnostics }) | 51 | Ok(req::PublishDiagnosticsParams { uri, diagnostics }) |
52 | } | 52 | } |
53 | 53 | ||
54 | pub fn publish_decorations(world: World, uri: Url) -> Result<req::PublishDecorationsParams> { | ||
55 | let path = uri.file_path()?; | ||
56 | let file = world.file_syntax(&path)?; | ||
57 | let line_index = world.file_line_index(&path)?; | ||
58 | let decorations = libeditor::highlight(&file) | ||
59 | .into_iter() | ||
60 | .map(|h| Decoration { | ||
61 | range: to_vs_range(&line_index, h.range), | ||
62 | tag: h.tag, | ||
63 | }).collect(); | ||
64 | Ok(req::PublishDecorationsParams { uri, decorations }) | ||
65 | } | ||
54 | 66 | ||
55 | fn to_text_range(line_index: &LineIndex, range: Range) -> TextRange { | 67 | fn to_text_range(line_index: &LineIndex, range: Range) -> TextRange { |
56 | TextRange::from_to( | 68 | TextRange::from_to( |
diff --git a/crates/server/src/main.rs b/crates/server/src/main.rs index 0e4f5f86a..900ee555f 100644 --- a/crates/server/src/main.rs +++ b/crates/server/src/main.rs | |||
@@ -12,6 +12,7 @@ extern crate threadpool; | |||
12 | #[macro_use] | 12 | #[macro_use] |
13 | extern crate log; | 13 | extern crate log; |
14 | extern crate url; | 14 | extern crate url; |
15 | extern crate url_serde; | ||
15 | extern crate flexi_logger; | 16 | extern crate flexi_logger; |
16 | extern crate libeditor; | 17 | extern crate libeditor; |
17 | extern crate libanalysis; | 18 | extern crate libanalysis; |
@@ -31,7 +32,7 @@ use libanalysis::{WorldState, World}; | |||
31 | 32 | ||
32 | use ::{ | 33 | use ::{ |
33 | io::{Io, RawMsg, RawRequest}, | 34 | io::{Io, RawMsg, RawRequest}, |
34 | handlers::{handle_syntax_tree, handle_extend_selection, publish_diagnostics}, | 35 | handlers::{handle_syntax_tree, handle_extend_selection, publish_diagnostics, publish_decorations}, |
35 | util::{FilePath, FnBox} | 36 | util::{FilePath, FnBox} |
36 | }; | 37 | }; |
37 | 38 | ||
@@ -198,7 +199,7 @@ fn main_loop( | |||
198 | dispatch::handle_notification::<req::DidOpenTextDocument, _>(&mut not, |params| { | 199 | dispatch::handle_notification::<req::DidOpenTextDocument, _>(&mut not, |params| { |
199 | let path = params.text_document.file_path()?; | 200 | let path = params.text_document.file_path()?; |
200 | world.change_overlay(path, Some(params.text_document.text)); | 201 | world.change_overlay(path, Some(params.text_document.text)); |
201 | update_diagnostics_on_threadpool( | 202 | update_file_notifications_on_threadpool( |
202 | pool, world.snapshot(), sender.clone(), params.text_document.uri, | 203 | pool, world.snapshot(), sender.clone(), params.text_document.uri, |
203 | ); | 204 | ); |
204 | Ok(()) | 205 | Ok(()) |
@@ -209,7 +210,7 @@ fn main_loop( | |||
209 | .ok_or_else(|| format_err!("empty changes"))? | 210 | .ok_or_else(|| format_err!("empty changes"))? |
210 | .text; | 211 | .text; |
211 | world.change_overlay(path, Some(text)); | 212 | world.change_overlay(path, Some(text)); |
212 | update_diagnostics_on_threadpool( | 213 | update_file_notifications_on_threadpool( |
213 | pool, world.snapshot(), sender.clone(), params.text_document.uri, | 214 | pool, world.snapshot(), sender.clone(), params.text_document.uri, |
214 | ); | 215 | ); |
215 | Ok(()) | 216 | Ok(()) |
@@ -254,14 +255,14 @@ fn handle_request_on_threadpool<R: req::ClientRequest>( | |||
254 | }) | 255 | }) |
255 | } | 256 | } |
256 | 257 | ||
257 | fn update_diagnostics_on_threadpool( | 258 | fn update_file_notifications_on_threadpool( |
258 | pool: &ThreadPool, | 259 | pool: &ThreadPool, |
259 | world: World, | 260 | world: World, |
260 | sender: Sender<Thunk>, | 261 | sender: Sender<Thunk>, |
261 | uri: Url, | 262 | uri: Url, |
262 | ) { | 263 | ) { |
263 | pool.execute(move || { | 264 | pool.execute(move || { |
264 | match publish_diagnostics(world, uri) { | 265 | match publish_diagnostics(world.clone(), uri.clone()) { |
265 | Err(e) => { | 266 | Err(e) => { |
266 | error!("failed to compute diagnostics: {:?}", e) | 267 | error!("failed to compute diagnostics: {:?}", e) |
267 | } | 268 | } |
@@ -271,5 +272,15 @@ fn update_diagnostics_on_threadpool( | |||
271 | })) | 272 | })) |
272 | } | 273 | } |
273 | } | 274 | } |
275 | match publish_decorations(world, uri) { | ||
276 | Err(e) => { | ||
277 | error!("failed to compute decortions: {:?}", e) | ||
278 | } | ||
279 | Ok(params) => { | ||
280 | sender.send(Box::new(|io: &mut Io| { | ||
281 | dispatch::send_notification::<req::PublishDecorations>(io, params) | ||
282 | })) | ||
283 | } | ||
284 | } | ||
274 | }); | 285 | }); |
275 | } | 286 | } |
diff --git a/crates/server/src/req.rs b/crates/server/src/req.rs index 645a17306..480fbabcd 100644 --- a/crates/server/src/req.rs +++ b/crates/server/src/req.rs | |||
@@ -1,5 +1,7 @@ | |||
1 | use serde::{ser::Serialize, de::DeserializeOwned}; | 1 | use serde::{ser::Serialize, de::DeserializeOwned}; |
2 | use url::Url; | ||
2 | use languageserver_types::{TextDocumentIdentifier, Range}; | 3 | use languageserver_types::{TextDocumentIdentifier, Range}; |
4 | use url_serde; | ||
3 | 5 | ||
4 | pub use languageserver_types::{ | 6 | pub use languageserver_types::{ |
5 | request::*, notification::*, | 7 | request::*, notification::*, |
@@ -58,3 +60,25 @@ pub struct ExtendSelectionParams { | |||
58 | pub struct ExtendSelectionResult { | 60 | pub struct ExtendSelectionResult { |
59 | pub selections: Vec<Range>, | 61 | pub selections: Vec<Range>, |
60 | } | 62 | } |
63 | |||
64 | pub enum PublishDecorations {} | ||
65 | |||
66 | impl Notification for PublishDecorations { | ||
67 | type Params = PublishDecorationsParams; | ||
68 | const METHOD: &'static str = "m/publishDecorations"; | ||
69 | } | ||
70 | |||
71 | #[derive(Serialize, Debug)] | ||
72 | #[serde(rename_all = "camelCase")] | ||
73 | pub struct PublishDecorationsParams { | ||
74 | #[serde(with = "url_serde")] | ||
75 | pub uri: Url, | ||
76 | pub decorations: Vec<Decoration>, | ||
77 | } | ||
78 | |||
79 | #[derive(Serialize, Debug)] | ||
80 | #[serde(rename_all = "camelCase")] | ||
81 | pub struct Decoration { | ||
82 | pub range: Range, | ||
83 | pub tag: &'static str | ||
84 | } | ||