]> git.lizzy.rs Git - rust.git/commitdiff
switch to FileRange
authorAleksey Kladov <aleksey.kladov@gmail.com>
Fri, 28 Dec 2018 15:15:19 +0000 (18:15 +0300)
committerAleksey Kladov <aleksey.kladov@gmail.com>
Fri, 28 Dec 2018 15:17:43 +0000 (18:17 +0300)
crates/ra_analysis/src/extend_selection.rs [new file with mode: 0644]
crates/ra_analysis/src/lib.rs
crates/ra_lsp_server/src/conv.rs
crates/ra_lsp_server/src/main_loop/handlers.rs

diff --git a/crates/ra_analysis/src/extend_selection.rs b/crates/ra_analysis/src/extend_selection.rs
new file mode 100644 (file)
index 0000000..5e1fbee
--- /dev/null
@@ -0,0 +1,11 @@
+use ra_db::SyntaxDatabase;
+
+use crate::{
+    TextRange, FileRange,
+    db::RootDatabase,
+};
+
+pub(crate) fn extend_selection(db: &RootDatabase, frange: FileRange) -> TextRange {
+    let file = db.source_file(frange.file_id);
+    ra_editor::extend_selection(&file, frange.range).unwrap_or(frange.range)
+}
index 3fa4189ce2b175940242cb59b548bffec98dcbe2..98abe85233f5621aed6d14aa9fd45697799271bf 100644 (file)
@@ -14,9 +14,11 @@ macro_rules! ctry {
 mod imp;
 mod completion;
 mod symbol_index;
-mod syntax_highlighting;
 pub mod mock_analysis;
 
+mod extend_selection;
+mod syntax_highlighting;
+
 use std::{fmt, sync::Arc};
 
 use rustc_hash::FxHashMap;
@@ -277,8 +279,8 @@ pub fn file_syntax(&self, file_id: FileId) -> SourceFileNode {
     pub fn file_line_index(&self, file_id: FileId) -> Arc<LineIndex> {
         self.imp.file_line_index(file_id)
     }
-    pub fn extend_selection(&self, file: &SourceFileNode, range: TextRange) -> TextRange {
-        ra_editor::extend_selection(file, range).unwrap_or(range)
+    pub fn extend_selection(&self, frange: FileRange) -> TextRange {
+        extend_selection::extend_selection(&self.imp.db, frange)
     }
     pub fn matching_brace(&self, file: &SourceFileNode, offset: TextUnit) -> Option<TextUnit> {
         ra_editor::matching_brace(file, offset)
index d3670104e4571ec09a31f31b2c4b0fe05e9c078e..3d56ccd9717a52f067469ab3caa6062dfa8a4c2f 100644 (file)
@@ -2,7 +2,7 @@
     self, Location, Position, Range, SymbolKind, TextDocumentEdit, TextDocumentIdentifier,
     TextDocumentItem, TextDocumentPositionParams, Url, VersionedTextDocumentIdentifier, InsertTextFormat,
 };
-use ra_analysis::{FileId, FileSystemEdit, SourceChange, SourceFileEdit, FilePosition, CompletionItem, CompletionItemKind, InsertText};
+use ra_analysis::{FileId, FileSystemEdit, SourceChange, SourceFileEdit, FilePosition,FileRange,  CompletionItem, CompletionItemKind, InsertText};
 use ra_editor::{LineCol, LineIndex, translate_offset_with_edit};
 use ra_text_edit::{AtomTextEdit, TextEdit};
 use ra_syntax::{SyntaxKind, TextRange, TextUnit};
@@ -218,6 +218,17 @@ fn try_conv_with(self, world: &ServerWorld) -> Result<FilePosition> {
     }
 }
 
+impl<'a> TryConvWith for (&'a TextDocumentIdentifier, Range) {
+    type Ctx = ServerWorld;
+    type Output = FileRange;
+    fn try_conv_with(self, world: &ServerWorld) -> Result<FileRange> {
+        let file_id = self.0.try_conv_with(world)?;
+        let line_index = world.analysis().file_line_index(file_id);
+        let range = self.1.conv_with(&line_index);
+        Ok(FileRange { file_id, range })
+    }
+}
+
 impl<T: TryConvWith> TryConvWith for Vec<T> {
     type Ctx = <T as TryConvWith>::Ctx;
     type Output = Vec<<T as TryConvWith>::Output>;
index 0e9a66a8a9bd6c79b4a1a965d9f3bb3f5fcbe9c6..d6f3dbe28da2e5e41ea1604eb22a1d8fd598cdae 100644 (file)
@@ -8,7 +8,7 @@
     PrepareRenameResponse, RenameParams, SymbolInformation, TextDocumentIdentifier, TextEdit,
     WorkspaceEdit, ParameterInformation, ParameterLabel, SignatureInformation, Hover, HoverContents,
 };
-use ra_analysis::{FileId, FoldKind, Query, RunnableKind, FilePosition, Severity};
+use ra_analysis::{FileId, FoldKind, Query, RunnableKind, FileRange, FilePosition, Severity};
 use ra_syntax::{TextUnit, text_utils::intersect};
 use ra_text_edit::text_utils::contains_offset_nonstrict;
 use rustc_hash::FxHashMap;
@@ -33,13 +33,13 @@ pub fn handle_extend_selection(
     params: req::ExtendSelectionParams,
 ) -> Result<req::ExtendSelectionResult> {
     let file_id = params.text_document.try_conv_with(&world)?;
-    let file = world.analysis().file_syntax(file_id);
     let line_index = world.analysis().file_line_index(file_id);
     let selections = params
         .selections
         .into_iter()
         .map_conv_with(&line_index)
-        .map(|r| world.analysis().extend_selection(&file, r))
+        .map(|range| FileRange { file_id, range })
+        .map(|frange| world.analysis().extend_selection(frange))
         .map_conv_with(&line_index)
         .collect();
     Ok(req::ExtendSelectionResult { selections })
@@ -71,13 +71,8 @@ pub fn handle_join_lines(
     world: ServerWorld,
     params: req::JoinLinesParams,
 ) -> Result<req::SourceChange> {
-    let file_id = params.text_document.try_conv_with(&world)?;
-    let line_index = world.analysis().file_line_index(file_id);
-    let range = params.range.conv_with(&line_index);
-    world
-        .analysis()
-        .join_lines(file_id, range)
-        .try_conv_with(&world)
+    let frange = (&params.text_document, params.range).try_conv_with(&world)?;
+    world.analysis().join_lines(frange).try_conv_with(&world)
 }
 
 pub fn handle_on_enter(
@@ -614,7 +609,10 @@ pub fn handle_code_action(
     let line_index = world.analysis().file_line_index(file_id);
     let range = params.range.conv_with(&line_index);
 
-    let assists = world.analysis().assists(file_id, range)?.into_iter();
+    let assists = world
+        .analysis()
+        .assists(FileRange { file_id, range })?
+        .into_iter();
     let fixes = world
         .analysis()
         .diagnostics(file_id)?