aboutsummaryrefslogtreecommitdiff
path: root/crates/server/src/main_loop
diff options
context:
space:
mode:
Diffstat (limited to 'crates/server/src/main_loop')
-rw-r--r--crates/server/src/main_loop/handlers.rs21
-rw-r--r--crates/server/src/main_loop/mod.rs4
2 files changed, 22 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