aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_lsp_server/src
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-12-28 15:15:19 +0000
committerAleksey Kladov <[email protected]>2018-12-28 15:17:43 +0000
commitfd33c89207f6dc621ef6e8c26ea288089448d811 (patch)
tree7933988832041d364a0bab6a82061d5e33cc65e6 /crates/ra_lsp_server/src
parent02924174bb084d73cab67af6665ddf00e91983f6 (diff)
switch to FileRange
Diffstat (limited to 'crates/ra_lsp_server/src')
-rw-r--r--crates/ra_lsp_server/src/conv.rs13
-rw-r--r--crates/ra_lsp_server/src/main_loop/handlers.rs20
2 files changed, 21 insertions, 12 deletions
diff --git a/crates/ra_lsp_server/src/conv.rs b/crates/ra_lsp_server/src/conv.rs
index d3670104e..3d56ccd97 100644
--- a/crates/ra_lsp_server/src/conv.rs
+++ b/crates/ra_lsp_server/src/conv.rs
@@ -2,7 +2,7 @@ use languageserver_types::{
2 self, Location, Position, Range, SymbolKind, TextDocumentEdit, TextDocumentIdentifier, 2 self, Location, Position, Range, SymbolKind, TextDocumentEdit, TextDocumentIdentifier,
3 TextDocumentItem, TextDocumentPositionParams, Url, VersionedTextDocumentIdentifier, InsertTextFormat, 3 TextDocumentItem, TextDocumentPositionParams, Url, VersionedTextDocumentIdentifier, InsertTextFormat,
4}; 4};
5use ra_analysis::{FileId, FileSystemEdit, SourceChange, SourceFileEdit, FilePosition, CompletionItem, CompletionItemKind, InsertText}; 5use ra_analysis::{FileId, FileSystemEdit, SourceChange, SourceFileEdit, FilePosition,FileRange, CompletionItem, CompletionItemKind, InsertText};
6use ra_editor::{LineCol, LineIndex, translate_offset_with_edit}; 6use ra_editor::{LineCol, LineIndex, translate_offset_with_edit};
7use ra_text_edit::{AtomTextEdit, TextEdit}; 7use ra_text_edit::{AtomTextEdit, TextEdit};
8use ra_syntax::{SyntaxKind, TextRange, TextUnit}; 8use ra_syntax::{SyntaxKind, TextRange, TextUnit};
@@ -218,6 +218,17 @@ impl<'a> TryConvWith for &'a TextDocumentPositionParams {
218 } 218 }
219} 219}
220 220
221impl<'a> TryConvWith for (&'a TextDocumentIdentifier, Range) {
222 type Ctx = ServerWorld;
223 type Output = FileRange;
224 fn try_conv_with(self, world: &ServerWorld) -> Result<FileRange> {
225 let file_id = self.0.try_conv_with(world)?;
226 let line_index = world.analysis().file_line_index(file_id);
227 let range = self.1.conv_with(&line_index);
228 Ok(FileRange { file_id, range })
229 }
230}
231
221impl<T: TryConvWith> TryConvWith for Vec<T> { 232impl<T: TryConvWith> TryConvWith for Vec<T> {
222 type Ctx = <T as TryConvWith>::Ctx; 233 type Ctx = <T as TryConvWith>::Ctx;
223 type Output = Vec<<T as TryConvWith>::Output>; 234 type Output = Vec<<T as TryConvWith>::Output>;
diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs
index 0e9a66a8a..d6f3dbe28 100644
--- a/crates/ra_lsp_server/src/main_loop/handlers.rs
+++ b/crates/ra_lsp_server/src/main_loop/handlers.rs
@@ -8,7 +8,7 @@ use languageserver_types::{
8 PrepareRenameResponse, RenameParams, SymbolInformation, TextDocumentIdentifier, TextEdit, 8 PrepareRenameResponse, RenameParams, SymbolInformation, TextDocumentIdentifier, TextEdit,
9 WorkspaceEdit, ParameterInformation, ParameterLabel, SignatureInformation, Hover, HoverContents, 9 WorkspaceEdit, ParameterInformation, ParameterLabel, SignatureInformation, Hover, HoverContents,
10}; 10};
11use ra_analysis::{FileId, FoldKind, Query, RunnableKind, FilePosition, Severity}; 11use ra_analysis::{FileId, FoldKind, Query, RunnableKind, FileRange, FilePosition, Severity};
12use ra_syntax::{TextUnit, text_utils::intersect}; 12use ra_syntax::{TextUnit, text_utils::intersect};
13use ra_text_edit::text_utils::contains_offset_nonstrict; 13use ra_text_edit::text_utils::contains_offset_nonstrict;
14use rustc_hash::FxHashMap; 14use rustc_hash::FxHashMap;
@@ -33,13 +33,13 @@ pub fn handle_extend_selection(
33 params: req::ExtendSelectionParams, 33 params: req::ExtendSelectionParams,
34) -> Result<req::ExtendSelectionResult> { 34) -> Result<req::ExtendSelectionResult> {
35 let file_id = params.text_document.try_conv_with(&world)?; 35 let file_id = params.text_document.try_conv_with(&world)?;
36 let file = world.analysis().file_syntax(file_id);
37 let line_index = world.analysis().file_line_index(file_id); 36 let line_index = world.analysis().file_line_index(file_id);
38 let selections = params 37 let selections = params
39 .selections 38 .selections
40 .into_iter() 39 .into_iter()
41 .map_conv_with(&line_index) 40 .map_conv_with(&line_index)
42 .map(|r| world.analysis().extend_selection(&file, r)) 41 .map(|range| FileRange { file_id, range })
42 .map(|frange| world.analysis().extend_selection(frange))
43 .map_conv_with(&line_index) 43 .map_conv_with(&line_index)
44 .collect(); 44 .collect();
45 Ok(req::ExtendSelectionResult { selections }) 45 Ok(req::ExtendSelectionResult { selections })
@@ -71,13 +71,8 @@ pub fn handle_join_lines(
71 world: ServerWorld, 71 world: ServerWorld,
72 params: req::JoinLinesParams, 72 params: req::JoinLinesParams,
73) -> Result<req::SourceChange> { 73) -> Result<req::SourceChange> {
74 let file_id = params.text_document.try_conv_with(&world)?; 74 let frange = (&params.text_document, params.range).try_conv_with(&world)?;
75 let line_index = world.analysis().file_line_index(file_id); 75 world.analysis().join_lines(frange).try_conv_with(&world)
76 let range = params.range.conv_with(&line_index);
77 world
78 .analysis()
79 .join_lines(file_id, range)
80 .try_conv_with(&world)
81} 76}
82 77
83pub fn handle_on_enter( 78pub fn handle_on_enter(
@@ -614,7 +609,10 @@ pub fn handle_code_action(
614 let line_index = world.analysis().file_line_index(file_id); 609 let line_index = world.analysis().file_line_index(file_id);
615 let range = params.range.conv_with(&line_index); 610 let range = params.range.conv_with(&line_index);
616 611
617 let assists = world.analysis().assists(file_id, range)?.into_iter(); 612 let assists = world
613 .analysis()
614 .assists(FileRange { file_id, range })?
615 .into_iter();
618 let fixes = world 616 let fixes = world
619 .analysis() 617 .analysis()
620 .diagnostics(file_id)? 618 .diagnostics(file_id)?