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(-) (limited to 'crates/ra_ide_api') 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 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'crates/ra_ide_api') 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. -- 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 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'crates/ra_ide_api') 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() } -- 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 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'crates/ra_ide_api') 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 -- cgit v1.2.3