aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-08-10 22:55:32 +0100
committerAleksey Kladov <[email protected]>2018-08-10 22:55:32 +0100
commit9863b9161d8d702848516be70c5c8161b7f382e8 (patch)
tree3aa95abbacf0897e4e738e1fc8ccf10492b7c60c /crates
parent836e0c1863eaea5dffdf76a658c2ee9d7bc22e6f (diff)
decorations
Diffstat (limited to 'crates')
-rw-r--r--crates/libanalysis/src/lib.rs4
-rw-r--r--crates/server/Cargo.toml1
-rw-r--r--crates/server/src/handlers.rs14
-rw-r--r--crates/server/src/main.rs21
-rw-r--r--crates/server/src/req.rs24
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)]
27pub struct World { 28pub 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)]
123struct WorldData { 124struct 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)]
128struct FileData { 130struct 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"
15flexi_logger = "0.9.0" 15flexi_logger = "0.9.0"
16log = "0.4.3" 16log = "0.4.3"
17url = "1.1.0" 17url = "1.1.0"
18url_serde = "0.2.0"
18 19
19libeditor = { path = "../libeditor" } 20libeditor = { path = "../libeditor" }
20libanalysis = { path = "../libanalysis" } 21libanalysis = { 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;
4use libeditor::{self, LineIndex, LineCol, TextRange, TextUnit}; 4use libeditor::{self, LineIndex, LineCol, TextRange, TextUnit};
5 5
6use ::{ 6use ::{
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
54pub 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
55fn to_text_range(line_index: &LineIndex, range: Range) -> TextRange { 67fn 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]
13extern crate log; 13extern crate log;
14extern crate url; 14extern crate url;
15extern crate url_serde;
15extern crate flexi_logger; 16extern crate flexi_logger;
16extern crate libeditor; 17extern crate libeditor;
17extern crate libanalysis; 18extern crate libanalysis;
@@ -31,7 +32,7 @@ use libanalysis::{WorldState, World};
31 32
32use ::{ 33use ::{
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
257fn update_diagnostics_on_threadpool( 258fn 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 @@
1use serde::{ser::Serialize, de::DeserializeOwned}; 1use serde::{ser::Serialize, de::DeserializeOwned};
2use url::Url;
2use languageserver_types::{TextDocumentIdentifier, Range}; 3use languageserver_types::{TextDocumentIdentifier, Range};
4use url_serde;
3 5
4pub use languageserver_types::{ 6pub use languageserver_types::{
5 request::*, notification::*, 7 request::*, notification::*,
@@ -58,3 +60,25 @@ pub struct ExtendSelectionParams {
58pub struct ExtendSelectionResult { 60pub struct ExtendSelectionResult {
59 pub selections: Vec<Range>, 61 pub selections: Vec<Range>,
60} 62}
63
64pub enum PublishDecorations {}
65
66impl 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")]
73pub 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")]
81pub struct Decoration {
82 pub range: Range,
83 pub tag: &'static str
84}