aboutsummaryrefslogtreecommitdiff
path: root/crates/server/src/main_loop
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-08-13 13:35:53 +0100
committerAleksey Kladov <[email protected]>2018-08-13 13:35:53 +0100
commitd19f3ac83441420365bff5e4ce21d1d2175bd8c2 (patch)
tree0523dc698784bb2501998956f8111b31f4e0387b /crates/server/src/main_loop
parent133d001d8296e51bcb4d0dc0982671f55c2c77d9 (diff)
workspace symbols
Diffstat (limited to 'crates/server/src/main_loop')
-rw-r--r--crates/server/src/main_loop/handlers.rs29
-rw-r--r--crates/server/src/main_loop/mod.rs4
2 files changed, 31 insertions, 2 deletions
diff --git a/crates/server/src/main_loop/handlers.rs b/crates/server/src/main_loop/handlers.rs
index 14dcafc38..bd0e6825b 100644
--- a/crates/server/src/main_loop/handlers.rs
+++ b/crates/server/src/main_loop/handlers.rs
@@ -2,9 +2,10 @@ use std::collections::HashMap;
2 2
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, Location,
6}; 7};
7use libanalysis::World; 8use libanalysis::{World};
8use libeditor; 9use libeditor;
9use libsyntax2::TextUnit; 10use libsyntax2::TextUnit;
10use serde_json::{to_value, from_value}; 11use serde_json::{to_value, from_value};
@@ -94,6 +95,30 @@ pub fn handle_code_action(
94 Ok(ret) 95 Ok(ret)
95} 96}
96 97
98pub fn handle_workspace_symbol(
99 world: World,
100 params: req::WorkspaceSymbolParams,
101) -> Result<Option<Vec<SymbolInformation>>> {
102 let mut acc = Vec::new();
103 for (path, symbol) in world.world_symbols(&params.query).take(128) {
104 let line_index = world.file_line_index(path)?;
105
106 let info = SymbolInformation {
107 name: symbol.name.to_string(),
108 kind: symbol.kind.conv(),
109 location: Location::new(
110 Url::from_file_path(path)
111 .map_err(|()| format_err!("invalid url"))?,
112 symbol.node_range.conv_with(&line_index),
113 ),
114 container_name: None,
115 };
116 acc.push(info);
117 };
118
119 Ok(Some(acc))
120}
121
97pub fn handle_execute_command( 122pub fn handle_execute_command(
98 world: World, 123 world: World,
99 mut params: req::ExecuteCommandParams, 124 mut params: req::ExecuteCommandParams,
diff --git a/crates/server/src/main_loop/mod.rs b/crates/server/src/main_loop/mod.rs
index f954e632c..e8b24355c 100644
--- a/crates/server/src/main_loop/mod.rs
+++ b/crates/server/src/main_loop/mod.rs
@@ -25,6 +25,7 @@ use {
25 handle_document_symbol, 25 handle_document_symbol,
26 handle_code_action, 26 handle_code_action,
27 handle_execute_command, 27 handle_execute_command,
28 handle_workspace_symbol,
28 }, 29 },
29}; 30};
30 31
@@ -148,6 +149,9 @@ fn on_request(
148 handle_request_on_threadpool::<req::CodeActionRequest>( 149 handle_request_on_threadpool::<req::CodeActionRequest>(
149 &mut req, pool, world, sender, handle_code_action, 150 &mut req, pool, world, sender, handle_code_action,
150 )?; 151 )?;
152 handle_request_on_threadpool::<req::WorkspaceSymbol>(
153 &mut req, pool, world, sender, handle_workspace_symbol,
154 )?;
151 dispatch::handle_request::<req::ExecuteCommand, _>(&mut req, |params, resp| { 155 dispatch::handle_request::<req::ExecuteCommand, _>(&mut req, |params, resp| {
152 io.send(RawMsg::Response(resp.into_response(Ok(None))?)); 156 io.send(RawMsg::Response(resp.into_response(Ok(None))?));
153 157