aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_lsp_server/src/main_loop/handlers.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_lsp_server/src/main_loop/handlers.rs')
-rw-r--r--crates/ra_lsp_server/src/main_loop/handlers.rs45
1 files changed, 9 insertions, 36 deletions
diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs
index 62c8cbf71..ab9ed5080 100644
--- a/crates/ra_lsp_server/src/main_loop/handlers.rs
+++ b/crates/ra_lsp_server/src/main_loop/handlers.rs
@@ -9,8 +9,7 @@ use lsp_types::{
9 TextDocumentIdentifier, TextEdit, WorkspaceEdit, 9 TextDocumentIdentifier, TextEdit, WorkspaceEdit,
10}; 10};
11use ra_ide_api::{ 11use ra_ide_api::{
12 AssistId, Cancelable, FileId, FilePosition, FileRange, FoldKind, Query, RangeInfo, 12 AssistId, Cancelable, FileId, FilePosition, FileRange, FoldKind, Query, RunnableKind, Severity,
13 RunnableKind, Severity,
14}; 13};
15use ra_prof::profile; 14use ra_prof::profile;
16use ra_syntax::{AstNode, SyntaxKind, TextRange, TextUnit}; 15use ra_syntax::{AstNode, SyntaxKind, TextRange, TextUnit};
@@ -21,7 +20,7 @@ use url_serde::Ser;
21 20
22use crate::{ 21use crate::{
23 cargo_target_spec::{runnable_args, CargoTargetSpec}, 22 cargo_target_spec::{runnable_args, CargoTargetSpec},
24 conv::{to_location, to_location_link, Conv, ConvWith, MapConvWith, TryConvWith}, 23 conv::{to_location, Conv, ConvWith, MapConvWith, TryConvWith, TryConvWithToVec},
25 req::{self, Decoration}, 24 req::{self, Decoration},
26 world::WorldSnapshot, 25 world::WorldSnapshot,
27 LspError, Result, 26 LspError, Result,
@@ -263,19 +262,12 @@ pub fn handle_goto_definition(
263 params: req::TextDocumentPositionParams, 262 params: req::TextDocumentPositionParams,
264) -> Result<Option<req::GotoDefinitionResponse>> { 263) -> Result<Option<req::GotoDefinitionResponse>> {
265 let position = params.try_conv_with(&world)?; 264 let position = params.try_conv_with(&world)?;
266 let line_index = world.analysis().file_line_index(position.file_id);
267 let nav_info = match world.analysis().goto_definition(position)? { 265 let nav_info = match world.analysis().goto_definition(position)? {
268 None => return Ok(None), 266 None => return Ok(None),
269 Some(it) => it, 267 Some(it) => it,
270 }; 268 };
271 let nav_range = nav_info.range; 269 let res = (position.file_id, nav_info).try_conv_with(&world)?;
272 let res = nav_info 270 Ok(Some(res))
273 .info
274 .into_iter()
275 .map(|nav| RangeInfo::new(nav_range, nav))
276 .map(|nav| to_location_link(&nav, &world, &line_index))
277 .collect::<Result<Vec<_>>>()?;
278 Ok(Some(res.into()))
279} 271}
280 272
281pub fn handle_goto_implementation( 273pub fn handle_goto_implementation(
@@ -283,19 +275,12 @@ pub fn handle_goto_implementation(
283 params: req::TextDocumentPositionParams, 275 params: req::TextDocumentPositionParams,
284) -> Result<Option<req::GotoImplementationResponse>> { 276) -> Result<Option<req::GotoImplementationResponse>> {
285 let position = params.try_conv_with(&world)?; 277 let position = params.try_conv_with(&world)?;
286 let line_index = world.analysis().file_line_index(position.file_id);
287 let nav_info = match world.analysis().goto_implementation(position)? { 278 let nav_info = match world.analysis().goto_implementation(position)? {
288 None => return Ok(None), 279 None => return Ok(None),
289 Some(it) => it, 280 Some(it) => it,
290 }; 281 };
291 let nav_range = nav_info.range; 282 let res = (position.file_id, nav_info).try_conv_with(&world)?;
292 let res = nav_info 283 Ok(Some(res))
293 .info
294 .into_iter()
295 .map(|nav| RangeInfo::new(nav_range, nav))
296 .map(|nav| to_location_link(&nav, &world, &line_index))
297 .collect::<Result<Vec<_>>>()?;
298 Ok(Some(res.into()))
299} 284}
300 285
301pub fn handle_goto_type_definition( 286pub fn handle_goto_type_definition(
@@ -303,19 +288,12 @@ pub fn handle_goto_type_definition(
303 params: req::TextDocumentPositionParams, 288 params: req::TextDocumentPositionParams,
304) -> Result<Option<req::GotoTypeDefinitionResponse>> { 289) -> Result<Option<req::GotoTypeDefinitionResponse>> {
305 let position = params.try_conv_with(&world)?; 290 let position = params.try_conv_with(&world)?;
306 let line_index = world.analysis().file_line_index(position.file_id);
307 let nav_info = match world.analysis().goto_type_definition(position)? { 291 let nav_info = match world.analysis().goto_type_definition(position)? {
308 None => return Ok(None), 292 None => return Ok(None),
309 Some(it) => it, 293 Some(it) => it,
310 }; 294 };
311 let nav_range = nav_info.range; 295 let res = (position.file_id, nav_info).try_conv_with(&world)?;
312 let res = nav_info 296 Ok(Some(res))
313 .info
314 .into_iter()
315 .map(|nav| RangeInfo::new(nav_range, nav))
316 .map(|nav| to_location_link(&nav, &world, &line_index))
317 .collect::<Result<Vec<_>>>()?;
318 Ok(Some(res.into()))
319} 297}
320 298
321pub fn handle_parent_module( 299pub fn handle_parent_module(
@@ -323,12 +301,7 @@ pub fn handle_parent_module(
323 params: req::TextDocumentPositionParams, 301 params: req::TextDocumentPositionParams,
324) -> Result<Vec<Location>> { 302) -> Result<Vec<Location>> {
325 let position = params.try_conv_with(&world)?; 303 let position = params.try_conv_with(&world)?;
326 world 304 world.analysis().parent_module(position)?.iter().try_conv_with_to_vec(&world)
327 .analysis()
328 .parent_module(position)?
329 .into_iter()
330 .map(|nav| nav.try_conv_with(&world))
331 .collect::<Result<Vec<_>>>()
332} 305}
333 306
334pub fn handle_runnables( 307pub fn handle_runnables(