Skip to content

Commit b042fae

Browse files
committed
simplify
1 parent 227bc0b commit b042fae

File tree

2 files changed

+20
-23
lines changed

2 files changed

+20
-23
lines changed

crates/ra_lsp_server/src/conv.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,19 @@ impl TryConvWith for (FileId, RangeInfo<NavigationTarget>) {
412412
}
413413
}
414414

415+
impl TryConvWith for (FileId, RangeInfo<Vec<NavigationTarget>>) {
416+
type Ctx = WorldSnapshot;
417+
type Output = req::GotoDefinitionResponse;
418+
fn try_conv_with(self, world: &WorldSnapshot) -> Result<req::GotoTypeDefinitionResponse> {
419+
let (file_id, RangeInfo { range, info: navs }) = self;
420+
let links = navs
421+
.into_iter()
422+
.map(|nav| (file_id, RangeInfo::new(range, nav)))
423+
.try_conv_with_to_vec(world)?;
424+
Ok(links.into())
425+
}
426+
}
427+
415428
pub fn to_location(
416429
file_id: FileId,
417430
range: TextRange,

crates/ra_lsp_server/src/main_loop/handlers.rs

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ use lsp_types::{
99
TextDocumentIdentifier, TextEdit, WorkspaceEdit,
1010
};
1111
use ra_ide_api::{
12-
AssistId, Cancelable, FileId, FilePosition, FileRange, FoldKind, Query, RangeInfo,
13-
RunnableKind, Severity,
12+
AssistId, Cancelable, FileId, FilePosition, FileRange, FoldKind, Query, RunnableKind, Severity,
1413
};
1514
use ra_prof::profile;
1615
use ra_syntax::{AstNode, SyntaxKind, TextRange, TextUnit};
@@ -267,13 +266,8 @@ pub fn handle_goto_definition(
267266
None => return Ok(None),
268267
Some(it) => it,
269268
};
270-
let nav_range = nav_info.range;
271-
let res = nav_info
272-
.info
273-
.into_iter()
274-
.map(|nav| (position.file_id, RangeInfo::new(nav_range, nav)))
275-
.try_conv_with_to_vec(&world)?;
276-
Ok(Some(res.into()))
269+
let res = (position.file_id, nav_info).try_conv_with(&world)?;
270+
Ok(Some(res))
277271
}
278272

279273
pub fn handle_goto_implementation(
@@ -285,13 +279,8 @@ pub fn handle_goto_implementation(
285279
None => return Ok(None),
286280
Some(it) => it,
287281
};
288-
let nav_range = nav_info.range;
289-
let res = nav_info
290-
.info
291-
.into_iter()
292-
.map(|nav| (position.file_id, RangeInfo::new(nav_range, nav)))
293-
.try_conv_with_to_vec(&world)?;
294-
Ok(Some(res.into()))
282+
let res = (position.file_id, nav_info).try_conv_with(&world)?;
283+
Ok(Some(res))
295284
}
296285

297286
pub fn handle_goto_type_definition(
@@ -303,13 +292,8 @@ pub fn handle_goto_type_definition(
303292
None => return Ok(None),
304293
Some(it) => it,
305294
};
306-
let nav_range = nav_info.range;
307-
let res = nav_info
308-
.info
309-
.into_iter()
310-
.map(|nav| (position.file_id, RangeInfo::new(nav_range, nav)))
311-
.try_conv_with_to_vec(&world)?;
312-
Ok(Some(res.into()))
295+
let res = (position.file_id, nav_info).try_conv_with(&world)?;
296+
Ok(Some(res))
313297
}
314298

315299
pub fn handle_parent_module(

0 commit comments

Comments
 (0)