aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ra_analysis/src/extend_selection.rs11
-rw-r--r--crates/ra_analysis/src/lib.rs8
-rw-r--r--crates/ra_lsp_server/src/conv.rs13
-rw-r--r--crates/ra_lsp_server/src/main_loop/handlers.rs20
4 files changed, 37 insertions, 15 deletions
diff --git a/crates/ra_analysis/src/extend_selection.rs b/crates/ra_analysis/src/extend_selection.rs
new file mode 100644
index 000000000..5e1fbee18
--- /dev/null
+++ b/crates/ra_analysis/src/extend_selection.rs
@@ -0,0 +1,11 @@
1use ra_db::SyntaxDatabase;
2
3use crate::{
4 TextRange, FileRange,
5 db::RootDatabase,
6};
7
8pub(crate) fn extend_selection(db: &RootDatabase, frange: FileRange) -> TextRange {
9 let file = db.source_file(frange.file_id);
10 ra_editor::extend_selection(&file, frange.range).unwrap_or(frange.range)
11}
diff --git a/crates/ra_analysis/src/lib.rs b/crates/ra_analysis/src/lib.rs
index 3fa4189ce..98abe8523 100644
--- a/crates/ra_analysis/src/lib.rs
+++ b/crates/ra_analysis/src/lib.rs
@@ -14,9 +14,11 @@ mod db;
14mod imp; 14mod imp;
15mod completion; 15mod completion;
16mod symbol_index; 16mod symbol_index;
17mod syntax_highlighting;
18pub mod mock_analysis; 17pub mod mock_analysis;
19 18
19mod extend_selection;
20mod syntax_highlighting;
21
20use std::{fmt, sync::Arc}; 22use std::{fmt, sync::Arc};
21 23
22use rustc_hash::FxHashMap; 24use rustc_hash::FxHashMap;
@@ -277,8 +279,8 @@ impl Analysis {
277 pub fn file_line_index(&self, file_id: FileId) -> Arc<LineIndex> { 279 pub fn file_line_index(&self, file_id: FileId) -> Arc<LineIndex> {
278 self.imp.file_line_index(file_id) 280 self.imp.file_line_index(file_id)
279 } 281 }
280 pub fn extend_selection(&self, file: &SourceFileNode, range: TextRange) -> TextRange { 282 pub fn extend_selection(&self, frange: FileRange) -> TextRange {
281 ra_editor::extend_selection(file, range).unwrap_or(range) 283 extend_selection::extend_selection(&self.imp.db, frange)
282 } 284 }
283 pub fn matching_brace(&self, file: &SourceFileNode, offset: TextUnit) -> Option<TextUnit> { 285 pub fn matching_brace(&self, file: &SourceFileNode, offset: TextUnit) -> Option<TextUnit> {
284 ra_editor::matching_brace(file, offset) 286 ra_editor::matching_brace(file, offset)
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)?