From 73836cdbbc928f3512156f0bc0166e5a39ad9864 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 20 Jan 2019 21:05:01 +0300 Subject: [PATCH] extend selection expands macros and can totally panic --- crates/ra_ide_api/src/extend_selection.rs | 2 +- crates/ra_ide_api/src/lib.rs | 4 ++-- crates/ra_lsp_server/src/main_loop/handlers.rs | 12 ++++++++---- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/crates/ra_ide_api/src/extend_selection.rs b/crates/ra_ide_api/src/extend_selection.rs index 9f0ab2f1c81..718b4def557 100644 --- a/crates/ra_ide_api/src/extend_selection.rs +++ b/crates/ra_ide_api/src/extend_selection.rs @@ -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())); } } diff --git a/crates/ra_ide_api/src/lib.rs b/crates/ra_ide_api/src/lib.rs index e41d85e7098..919d248e2cd 100644 --- a/crates/ra_ide_api/src/lib.rs +++ b/crates/ra_ide_api/src/lib.rs @@ -310,8 +310,8 @@ pub fn file_line_index(&self, file_id: FileId) -> Arc { } /// 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 { + self.with_db(|db| extend_selection::extend_selection(db, frange)) } /// Returns position of the mathcing brace (all types of braces are diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs index 5cd8abbb9b5..02393f728b1 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 @@ 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::>>()?; Ok(req::ExtendSelectionResult { selections }) }