aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/server/src/main_loop/handlers.rs21
-rw-r--r--crates/server/src/main_loop/mod.rs4
-rw-r--r--crates/server/src/req.rs8
3 files changed, 30 insertions, 3 deletions
diff --git a/crates/server/src/main_loop/handlers.rs b/crates/server/src/main_loop/handlers.rs
index ee4072084..ec5421f06 100644
--- a/crates/server/src/main_loop/handlers.rs
+++ b/crates/server/src/main_loop/handlers.rs
@@ -7,7 +7,7 @@ use languageserver_types::{
7 CompletionItem, 7 CompletionItem,
8}; 8};
9use serde_json::{to_value, from_value}; 9use serde_json::{to_value, from_value};
10use libanalysis::{Query, QuickFix}; 10use libanalysis::{Query, QuickFix, FileId};
11use libeditor; 11use libeditor;
12use libsyntax2::{ 12use libsyntax2::{
13 TextUnit, 13 TextUnit,
@@ -401,18 +401,33 @@ pub fn publish_diagnostics(
401 Ok(req::PublishDiagnosticsParams { uri, diagnostics }) 401 Ok(req::PublishDiagnosticsParams { uri, diagnostics })
402} 402}
403 403
404pub fn handle_decorations(
405 world: ServerWorld,
406 params: TextDocumentIdentifier,
407) -> Result<Vec<Decoration>> {
408 let file_id = params.try_conv_with(&world)?;
409 highlight(&world, file_id)
410}
411
404pub fn publish_decorations( 412pub fn publish_decorations(
405 world: ServerWorld, 413 world: ServerWorld,
406 uri: Url 414 uri: Url
407) -> Result<req::PublishDecorationsParams> { 415) -> Result<req::PublishDecorationsParams> {
408 let file_id = world.uri_to_file_id(&uri)?; 416 let file_id = world.uri_to_file_id(&uri)?;
417 Ok(req::PublishDecorationsParams {
418 uri,
419 decorations: highlight(&world, file_id)?
420 })
421}
422
423fn highlight(world: &ServerWorld, file_id: FileId) -> Result<Vec<Decoration>> {
409 let file = world.analysis().file_syntax(file_id)?; 424 let file = world.analysis().file_syntax(file_id)?;
410 let line_index = world.analysis().file_line_index(file_id)?; 425 let line_index = world.analysis().file_line_index(file_id)?;
411 let decorations = libeditor::highlight(&file) 426 let res = libeditor::highlight(&file)
412 .into_iter() 427 .into_iter()
413 .map(|h| Decoration { 428 .map(|h| Decoration {
414 range: h.range.conv_with(&line_index), 429 range: h.range.conv_with(&line_index),
415 tag: h.tag, 430 tag: h.tag,
416 }).collect(); 431 }).collect();
417 Ok(req::PublishDecorationsParams { uri, decorations }) 432 Ok(res)
418} 433}
diff --git a/crates/server/src/main_loop/mod.rs b/crates/server/src/main_loop/mod.rs
index 6d6ca6ae9..da1121cb4 100644
--- a/crates/server/src/main_loop/mod.rs
+++ b/crates/server/src/main_loop/mod.rs
@@ -30,6 +30,7 @@ use {
30 handle_join_lines, 30 handle_join_lines,
31 handle_completion, 31 handle_completion,
32 handle_runnables, 32 handle_runnables,
33 handle_decorations,
33 }, 34 },
34}; 35};
35 36
@@ -157,6 +158,9 @@ fn on_request(
157 handle_request_on_threadpool::<req::JoinLines>( 158 handle_request_on_threadpool::<req::JoinLines>(
158 &mut req, pool, world, sender, handle_join_lines, 159 &mut req, pool, world, sender, handle_join_lines,
159 )?; 160 )?;
161 handle_request_on_threadpool::<req::DecorationsRequest>(
162 &mut req, pool, world, sender, handle_decorations,
163 )?;
160 dispatch::handle_request::<req::ExecuteCommand, _>(&mut req, |params, resp| { 164 dispatch::handle_request::<req::ExecuteCommand, _>(&mut req, |params, resp| {
161 io.send(RawMsg::Response(resp.into_response(Ok(None))?)); 165 io.send(RawMsg::Response(resp.into_response(Ok(None))?));
162 166
diff --git a/crates/server/src/req.rs b/crates/server/src/req.rs
index 269246dff..999fdb7c2 100644
--- a/crates/server/src/req.rs
+++ b/crates/server/src/req.rs
@@ -84,6 +84,14 @@ pub struct FindMatchingBraceParams {
84 pub offsets: Vec<Position>, 84 pub offsets: Vec<Position>,
85} 85}
86 86
87pub enum DecorationsRequest {}
88
89impl Request for DecorationsRequest {
90 type Params = TextDocumentIdentifier;
91 type Result = Vec<Decoration>;
92 const METHOD: &'static str = "m/decorationsRequest";
93}
94
87pub enum PublishDecorations {} 95pub enum PublishDecorations {}
88 96
89impl Notification for PublishDecorations { 97impl Notification for PublishDecorations {