From c517696fab33c7829b429f2eed7289c8b785d6be Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 20 Jan 2019 20:55:08 +0300 Subject: use with_db consistently --- crates/ra_ide_api/src/lib.rs | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/crates/ra_ide_api/src/lib.rs b/crates/ra_ide_api/src/lib.rs index 33bef178a..ca6b25516 100644 --- a/crates/ra_ide_api/src/lib.rs +++ b/crates/ra_ide_api/src/lib.rs @@ -388,8 +388,7 @@ impl Analysis { &self, position: FilePosition, ) -> Cancelable>>> { - self.db - .catch_canceled(|db| goto_definition::goto_definition(db, position)) + self.with_db(|db| goto_definition::goto_definition(db, position)) } /// Finds all usages of the reference at point. @@ -404,8 +403,7 @@ impl Analysis { /// Computes parameter information for the given call expression. pub fn call_info(&self, position: FilePosition) -> Cancelable> { - self.db - .catch_canceled(|db| call_info::call_info(db, position)) + self.with_db(|db| call_info::call_info(db, position)) } /// Returns a `mod name;` declaration which created the current module. @@ -420,33 +418,28 @@ impl Analysis { /// Returns the root file of the given crate. pub fn crate_root(&self, crate_id: CrateId) -> Cancelable { - Ok(self.db.crate_graph().crate_root(crate_id)) + self.with_db(|db| db.crate_graph().crate_root(crate_id)) } /// Returns the set of possible targets to run for the current file. pub fn runnables(&self, file_id: FileId) -> Cancelable> { - self.db - .catch_canceled(|db| runnables::runnables(db, file_id)) + self.with_db(|db| runnables::runnables(db, file_id)) } /// Computes syntax highlighting for the given file. pub fn highlight(&self, file_id: FileId) -> Cancelable> { - self.db - .catch_canceled(|db| syntax_highlighting::highlight(db, file_id)) + self.with_db(|db| syntax_highlighting::highlight(db, file_id)) } /// Computes completions at the given position. pub fn completions(&self, position: FilePosition) -> Cancelable>> { - let completions = self - .db - .catch_canceled(|db| completion::completions(db, position))?; - Ok(completions.map(|it| it.into())) + self.with_db(|db| completion::completions(db, position).map(Into::into)) } /// Computes assists (aks code actons aka intentions) for the given /// position. pub fn assists(&self, frange: FileRange) -> Cancelable> { - Ok(self.db.assists(frange)) + self.with_db(|db| db.assists(frange)) } /// Computes the set of diagnostics for the given file. -- cgit v1.2.3 From 1ec1bd8139251092e567d0b6034f96e3fdf33afb Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 20 Jan 2019 20:59:46 +0300 Subject: make matching brace consistent --- crates/ra_ide_api/src/lib.rs | 5 +++-- crates/ra_lsp_server/src/main_loop/handlers.rs | 3 +-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/ra_ide_api/src/lib.rs b/crates/ra_ide_api/src/lib.rs index ca6b25516..9ee5467ed 100644 --- a/crates/ra_ide_api/src/lib.rs +++ b/crates/ra_ide_api/src/lib.rs @@ -316,8 +316,9 @@ impl Analysis { /// Returns position of the mathcing brace (all types of braces are /// supported). - pub fn matching_brace(&self, file: &SourceFile, offset: TextUnit) -> Option { - ra_ide_api_light::matching_brace(file, offset) + pub fn matching_brace(&self, position: FilePosition) -> Option { + let file = self.db.source_file(position.file_id); + ra_ide_api_light::matching_brace(&file, position.offset) } /// Returns a syntax tree represented as `String`, for debug purposes. diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs index 8f9db68a2..b70d67b4d 100644 --- a/crates/ra_lsp_server/src/main_loop/handlers.rs +++ b/crates/ra_lsp_server/src/main_loop/handlers.rs @@ -51,7 +51,6 @@ pub fn handle_find_matching_brace( params: req::FindMatchingBraceParams, ) -> Result> { 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 res = params .offsets @@ -60,7 +59,7 @@ pub fn handle_find_matching_brace( .map(|offset| { world .analysis() - .matching_brace(&file, offset) + .matching_brace(FilePosition { file_id, offset }) .unwrap_or(offset) }) .map_conv_with(&line_index) -- cgit v1.2.3 From 171f6e6d00d1fc99395b7b92c8a40b47d6bd6962 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 20 Jan 2019 21:01:11 +0300 Subject: somewhat better name --- crates/ra_ide_api/src/lib.rs | 2 +- crates/ra_lsp_server/src/main_loop/handlers.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/ra_ide_api/src/lib.rs b/crates/ra_ide_api/src/lib.rs index 9ee5467ed..e41d85e70 100644 --- a/crates/ra_ide_api/src/lib.rs +++ b/crates/ra_ide_api/src/lib.rs @@ -299,7 +299,7 @@ impl Analysis { } /// Gets the syntax tree of the file. - pub fn file_syntax(&self, file_id: FileId) -> TreeArc { + pub fn parse(&self, file_id: FileId) -> TreeArc { self.db.source_file(file_id).clone() } diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs index b70d67b4d..5cd8abbb9 100644 --- a/crates/ra_lsp_server/src/main_loop/handlers.rs +++ b/crates/ra_lsp_server/src/main_loop/handlers.rs @@ -314,7 +314,7 @@ pub fn handle_completion( let mut res = false; if let Some(ctx) = params.context { if ctx.trigger_character.unwrap_or_default() == ":" { - let source_file = world.analysis().file_syntax(position.file_id); + let source_file = world.analysis().parse(position.file_id); let syntax = source_file.syntax(); let text = syntax.text(); if let Some(next_char) = text.char_at(position.offset) { -- cgit v1.2.3 From 73836cdbbc928f3512156f0bc0166e5a39ad9864 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 20 Jan 2019 21:05:01 +0300 Subject: 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 9f0ab2f1c..718b4def5 100644 --- a/crates/ra_ide_api/src/extend_selection.rs +++ b/crates/ra_ide_api/src/extend_selection.rs @@ -51,7 +51,7 @@ mod tests { } ", ); - 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 e41d85e70..919d248e2 100644 --- a/crates/ra_ide_api/src/lib.rs +++ b/crates/ra_ide_api/src/lib.rs @@ -310,8 +310,8 @@ impl Analysis { } /// 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 5cd8abbb9..02393f728 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 lsp_types::{ 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 }) } -- cgit v1.2.3