diff options
author | Aleksey Kladov <[email protected]> | 2018-08-10 22:55:32 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2018-08-10 22:55:32 +0100 |
commit | 9863b9161d8d702848516be70c5c8161b7f382e8 (patch) | |
tree | 3aa95abbacf0897e4e738e1fc8ccf10492b7c60c /crates | |
parent | 836e0c1863eaea5dffdf76a658c2ee9d7bc22e6f (diff) |
decorations
Diffstat (limited to 'crates')
-rw-r--r-- | crates/libanalysis/src/lib.rs | 4 | ||||
-rw-r--r-- | crates/server/Cargo.toml | 1 | ||||
-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 |
5 files changed, 57 insertions, 7 deletions
diff --git a/crates/libanalysis/src/lib.rs b/crates/libanalysis/src/lib.rs index 6a946a0b0..74f043a9b 100644 --- a/crates/libanalysis/src/lib.rs +++ b/crates/libanalysis/src/lib.rs | |||
@@ -24,6 +24,7 @@ pub struct WorldState { | |||
24 | data: Arc<WorldData> | 24 | data: Arc<WorldData> |
25 | } | 25 | } |
26 | 26 | ||
27 | #[derive(Clone, Debug)] | ||
27 | pub struct World { | 28 | pub struct World { |
28 | data: Arc<WorldData>, | 29 | data: Arc<WorldData>, |
29 | } | 30 | } |
@@ -119,12 +120,13 @@ impl World { | |||
119 | } | 120 | } |
120 | 121 | ||
121 | 122 | ||
122 | #[derive(Default)] | 123 | #[derive(Default, Debug)] |
123 | struct WorldData { | 124 | struct WorldData { |
124 | mem_map: HashMap<PathBuf, Arc<String>>, | 125 | mem_map: HashMap<PathBuf, Arc<String>>, |
125 | file_map: RwLock<HashMap<PathBuf, Arc<FileData>>>, | 126 | file_map: RwLock<HashMap<PathBuf, Arc<FileData>>>, |
126 | } | 127 | } |
127 | 128 | ||
129 | #[derive(Debug)] | ||
128 | struct FileData { | 130 | struct FileData { |
129 | text: Option<String>, | 131 | text: Option<String>, |
130 | syntax: OnceCell<ast::File>, | 132 | syntax: OnceCell<ast::File>, |
diff --git a/crates/server/Cargo.toml b/crates/server/Cargo.toml index b2a7ce5b4..b5e4e1926 100644 --- a/crates/server/Cargo.toml +++ b/crates/server/Cargo.toml | |||
@@ -15,6 +15,7 @@ threadpool = "1.7.1" | |||
15 | flexi_logger = "0.9.0" | 15 | flexi_logger = "0.9.0" |
16 | log = "0.4.3" | 16 | log = "0.4.3" |
17 | url = "1.1.0" | 17 | url = "1.1.0" |
18 | url_serde = "0.2.0" | ||
18 | 19 | ||
19 | libeditor = { path = "../libeditor" } | 20 | libeditor = { path = "../libeditor" } |
20 | libanalysis = { path = "../libanalysis" } | 21 | libanalysis = { path = "../libanalysis" } |
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 | } | ||