aboutsummaryrefslogtreecommitdiff
path: root/crates/server/src/main_loop/handlers.rs
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-08-27 22:20:59 +0100
committerAleksey Kladov <[email protected]>2018-08-27 22:20:59 +0100
commit8f5330cb0796670a93089107c8b15cdef3fa7c94 (patch)
tree02ce05a2222adb4ab1fb3464da926ec0fd0fb234 /crates/server/src/main_loop/handlers.rs
parent010075be6a6b866f6a3f981a61ad2e746cb44f00 (diff)
More robust highlighting
Diffstat (limited to 'crates/server/src/main_loop/handlers.rs')
-rw-r--r--crates/server/src/main_loop/handlers.rs21
1 files changed, 18 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}