]> git.lizzy.rs Git - rust.git/commitdiff
extend selection expands macros and can totally panic
authorAleksey Kladov <aleksey.kladov@gmail.com>
Sun, 20 Jan 2019 18:05:01 +0000 (21:05 +0300)
committerAleksey Kladov <aleksey.kladov@gmail.com>
Sun, 20 Jan 2019 18:05:01 +0000 (21:05 +0300)
crates/ra_ide_api/src/extend_selection.rs
crates/ra_ide_api/src/lib.rs
crates/ra_lsp_server/src/main_loop/handlers.rs

index 9f0ab2f1c815f5118170c13d2de7ad21ee8d8c86..718b4def557c542f327cf2996a066fa303f670ca 100644 (file)
@@ -51,7 +51,7 @@ fn main() {
             }
         ",
         );
-        let r = analysis.extend_selection(frange);
+        let r = analysis.extend_selection(frange).unwrap();
         assert_eq!(r, TextRange::from_to(51.into(), 56.into()));
     }
 }
index e41d85e7098e182a4cc2fa5338aa76db1f57ab07..919d248e2cd03ff7db87b566925390633d7a9107 100644 (file)
@@ -310,8 +310,8 @@ pub fn file_line_index(&self, file_id: FileId) -> Arc<LineIndex> {
     }
 
     /// Selects the next syntactic nodes encopasing the range.
-    pub fn extend_selection(&self, frange: FileRange) -> TextRange {
-        extend_selection::extend_selection(&self.db, frange)
+    pub fn extend_selection(&self, frange: FileRange) -> Cancelable<TextRange> {
+        self.with_db(|db| extend_selection::extend_selection(db, frange))
     }
 
     /// Returns position of the mathcing brace (all types of braces are
index 5cd8abbb9b553c590b0a4cb76f869a0f94a7c756..02393f728b1444ab259465b334bb641edacd4b4c 100644 (file)
@@ -8,7 +8,7 @@
     WorkspaceEdit
 };
 use ra_ide_api::{
-    FileId, FilePosition, FileRange, FoldKind, Query, RangeInfo, RunnableKind, Severity,
+    FileId, FilePosition, FileRange, FoldKind, Query, RangeInfo, RunnableKind, Severity, Cancelable,
 };
 use ra_syntax::{AstNode, TextUnit};
 use rustc_hash::FxHashMap;
@@ -40,9 +40,13 @@ pub fn handle_extend_selection(
         .into_iter()
         .map_conv_with(&line_index)
         .map(|range| FileRange { file_id, range })
-        .map(|frange| world.analysis().extend_selection(frange))
-        .map_conv_with(&line_index)
-        .collect();
+        .map(|frange| {
+            world
+                .analysis()
+                .extend_selection(frange)
+                .map(|it| it.conv_with(&line_index))
+        })
+        .collect::<Cancelable<Vec<_>>>()?;
     Ok(req::ExtendSelectionResult { selections })
 }