aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_lsp_server/src/main_loop
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_lsp_server/src/main_loop')
-rw-r--r--crates/ra_lsp_server/src/main_loop/handlers.rs47
1 files changed, 46 insertions, 1 deletions
diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs
index eb8a53545..530081494 100644
--- a/crates/ra_lsp_server/src/main_loop/handlers.rs
+++ b/crates/ra_lsp_server/src/main_loop/handlers.rs
@@ -11,7 +11,7 @@ use ra_ide_api::{
11 FileId, FilePosition, FileRange, FoldKind, Query, RangeInfo, RunnableKind, Severity, Cancelable, 11 FileId, FilePosition, FileRange, FoldKind, Query, RangeInfo, RunnableKind, Severity, Cancelable,
12 AssistId, 12 AssistId,
13}; 13};
14use ra_syntax::{AstNode, SyntaxKind, TextUnit}; 14use ra_syntax::{AstNode, SyntaxKind, TextUnit, TextRange};
15use ra_prof::profile; 15use ra_prof::profile;
16use rustc_hash::FxHashMap; 16use rustc_hash::FxHashMap;
17use serde::{Serialize, Deserialize}; 17use serde::{Serialize, Deserialize};
@@ -39,10 +39,15 @@ pub fn handle_syntax_tree(world: ServerWorld, params: req::SyntaxTreeParams) ->
39 Ok(res) 39 Ok(res)
40} 40}
41 41
42// FIXME: drop this API
42pub fn handle_extend_selection( 43pub fn handle_extend_selection(
43 world: ServerWorld, 44 world: ServerWorld,
44 params: req::ExtendSelectionParams, 45 params: req::ExtendSelectionParams,
45) -> Result<req::ExtendSelectionResult> { 46) -> Result<req::ExtendSelectionResult> {
47 log::error!(
48 "extend selection is deprecated and will be removed soon,
49 use the new selection range API in LSP",
50 );
46 let file_id = params.text_document.try_conv_with(&world)?; 51 let file_id = params.text_document.try_conv_with(&world)?;
47 let line_index = world.analysis().file_line_index(file_id); 52 let line_index = world.analysis().file_line_index(file_id);
48 let selections = params 53 let selections = params
@@ -55,6 +60,46 @@ pub fn handle_extend_selection(
55 Ok(req::ExtendSelectionResult { selections }) 60 Ok(req::ExtendSelectionResult { selections })
56} 61}
57 62
63pub fn handle_selection_range(
64 world: ServerWorld,
65 params: req::SelectionRangeParams,
66) -> Result<Vec<req::SelectionRange>> {
67 let file_id = params.text_document.try_conv_with(&world)?;
68 let line_index = world.analysis().file_line_index(file_id);
69 params
70 .positions
71 .into_iter()
72 .map_conv_with(&line_index)
73 .map(|position| {
74 let mut ranges = Vec::new();
75 {
76 let mut range = TextRange::from_to(position, position);
77 loop {
78 ranges.push(range);
79 let frange = FileRange { file_id, range };
80 let next = world.analysis().extend_selection(frange)?;
81 if next == range {
82 break;
83 } else {
84 range = next
85 }
86 }
87 }
88 let mut range = req::SelectionRange {
89 range: ranges.last().unwrap().conv_with(&line_index),
90 parent: None,
91 };
92 for r in ranges.iter().rev().skip(1) {
93 range = req::SelectionRange {
94 range: r.conv_with(&line_index),
95 parent: Some(Box::new(range)),
96 }
97 }
98 Ok(range)
99 })
100 .collect()
101}
102
58pub fn handle_find_matching_brace( 103pub fn handle_find_matching_brace(
59 world: ServerWorld, 104 world: ServerWorld,
60 params: req::FindMatchingBraceParams, 105 params: req::FindMatchingBraceParams,