aboutsummaryrefslogtreecommitdiff
path: root/crates/server/src/main_loop
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-08-15 22:23:22 +0100
committerAleksey Kladov <[email protected]>2018-08-15 22:23:22 +0100
commitc631b585a7358d1569a051f2529ecaae222e95cd (patch)
tree2e8332d166900c29cf485297b8510451b97accd0 /crates/server/src/main_loop
parentaa0d344581dcfd7f18c595688a4b2709b0f2421e (diff)
matching brace
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, 24 insertions, 1 deletions
diff --git a/crates/server/src/main_loop/handlers.rs b/crates/server/src/main_loop/handlers.rs
index 078abfbfa..d7b78b4fa 100644
--- a/crates/server/src/main_loop/handlers.rs
+++ b/crates/server/src/main_loop/handlers.rs
@@ -3,7 +3,7 @@ use std::collections::HashMap;
3use languageserver_types::{ 3use languageserver_types::{
4 Diagnostic, DiagnosticSeverity, Url, DocumentSymbol, 4 Diagnostic, DiagnosticSeverity, Url, DocumentSymbol,
5 Command, TextDocumentIdentifier, WorkspaceEdit, 5 Command, TextDocumentIdentifier, WorkspaceEdit,
6 SymbolInformation, 6 SymbolInformation, Position,
7}; 7};
8use libanalysis::{World, Query}; 8use libanalysis::{World, Query};
9use libeditor; 9use libeditor;
@@ -42,6 +42,25 @@ pub fn handle_extend_selection(
42 Ok(req::ExtendSelectionResult { selections }) 42 Ok(req::ExtendSelectionResult { selections })
43} 43}
44 44
45pub fn handle_find_matching_brace(
46 world: World,
47 path_map: PathMap,
48 params: req::FindMatchingBraceParams,
49) -> Result<Vec<Position>> {
50 let file_id = params.text_document.try_conv_with(&path_map)?;
51 let file = world.file_syntax(file_id)?;
52 let line_index = world.file_line_index(file_id)?;
53 let res = params.offsets
54 .into_iter()
55 .map_conv_with(&line_index)
56 .map(|offset| {
57 libeditor::matching_brace(&file, offset).unwrap_or(offset)
58 })
59 .map_conv_with(&line_index)
60 .collect();
61 Ok(res)
62}
63
45pub fn handle_document_symbol( 64pub fn handle_document_symbol(
46 world: World, 65 world: World,
47 path_map: PathMap, 66 path_map: PathMap,
diff --git a/crates/server/src/main_loop/mod.rs b/crates/server/src/main_loop/mod.rs
index 2a31297be..4d5dfb437 100644
--- a/crates/server/src/main_loop/mod.rs
+++ b/crates/server/src/main_loop/mod.rs
@@ -26,6 +26,7 @@ use {
26 handle_execute_command, 26 handle_execute_command,
27 handle_workspace_symbol, 27 handle_workspace_symbol,
28 handle_goto_definition, 28 handle_goto_definition,
29 handle_find_matching_brace,
29 }, 30 },
30}; 31};
31 32
@@ -148,6 +149,9 @@ fn on_request(
148 handle_request_on_threadpool::<req::ExtendSelection>( 149 handle_request_on_threadpool::<req::ExtendSelection>(
149 &mut req, pool, path_map, world, sender, handle_extend_selection, 150 &mut req, pool, path_map, world, sender, handle_extend_selection,
150 )?; 151 )?;
152 handle_request_on_threadpool::<req::FindMatchingBrace>(
153 &mut req, pool, path_map, world, sender, handle_find_matching_brace,
154 )?;
151 handle_request_on_threadpool::<req::DocumentSymbolRequest>( 155 handle_request_on_threadpool::<req::DocumentSymbolRequest>(
152 &mut req, pool, path_map, world, sender, handle_document_symbol, 156 &mut req, pool, path_map, world, sender, handle_document_symbol,
153 )?; 157 )?;