From dc6e1e0dac318b36ec43ffced3d4059a9b8652e5 Mon Sep 17 00:00:00 2001 From: JmPotato Date: Tue, 11 Aug 2020 10:55:26 +0800 Subject: Address some FIXMEs Signed-off-by: JmPotato --- crates/ra_assists/Cargo.toml | 1 + crates/ra_assists/src/ast_transform.rs | 13 +++++-------- crates/ra_assists/src/lib.rs | 25 ++++++++++++++++++++----- 3 files changed, 26 insertions(+), 13 deletions(-) (limited to 'crates/ra_assists') diff --git a/crates/ra_assists/Cargo.toml b/crates/ra_assists/Cargo.toml index bd2905f08..a436e861d 100644 --- a/crates/ra_assists/Cargo.toml +++ b/crates/ra_assists/Cargo.toml @@ -22,4 +22,5 @@ ra_prof = { path = "../ra_prof" } ra_db = { path = "../ra_db" } ra_ide_db = { path = "../ra_ide_db" } hir = { path = "../ra_hir", package = "ra_hir" } +hir_expand = { path = "../ra_hir_expand", package = "ra_hir_expand" } test_utils = { path = "../test_utils" } diff --git a/crates/ra_assists/src/ast_transform.rs b/crates/ra_assists/src/ast_transform.rs index 15ec75c95..02c4a4bae 100644 --- a/crates/ra_assists/src/ast_transform.rs +++ b/crates/ra_assists/src/ast_transform.rs @@ -2,6 +2,7 @@ use rustc_hash::FxHashMap; use hir::{HirDisplay, PathResolution, SemanticsScope}; +use hir_expand::hygiene::Hygiene; use ra_syntax::{ algo::SyntaxRewriter, ast::{self, AstNode}, @@ -51,7 +52,7 @@ impl<'a> SubstituteTypeParams<'a> { // this is a trait impl, so we need to skip the first type parameter -- this is a bit hacky .skip(1) // The actual list of trait type parameters may be longer than the one - // used in the `impl` block due to trailing default type parametrs. + // used in the `impl` block due to trailing default type parameters. // For that case we extend the `substs` with an empty iterator so we // can still hit those trailing values and check if they actually have // a default type. If they do, go for that type from `hir` to `ast` so @@ -110,9 +111,7 @@ impl<'a> SubstituteTypeParams<'a> { ast::Type::PathType(path_type) => path_type.path()?, _ => return None, }; - // FIXME: use `hir::Path::from_src` instead. - #[allow(deprecated)] - let path = hir::Path::from_ast(path)?; + let path = hir::Path::from_src(path, &Hygiene::new_unhygienic())?; let resolution = self.source_scope.resolve_hir_path(&path)?; match resolution { hir::PathResolution::TypeParam(tp) => Some(self.substs.get(&tp)?.syntax().clone()), @@ -152,10 +151,8 @@ impl<'a> QualifyPaths<'a> { // don't try to qualify `Fn(Foo) -> Bar` paths, they are in prelude anyway return None; } - // FIXME: use `hir::Path::from_src` instead. - #[allow(deprecated)] - let hir_path = hir::Path::from_ast(p.clone()); - let resolution = self.source_scope.resolve_hir_path(&hir_path?)?; + let hir_path = hir::Path::from_src(p.clone(), &Hygiene::new_unhygienic())?; + let resolution = self.source_scope.resolve_hir_path(&hir_path)?; match resolution { PathResolution::Def(def) => { let found_path = from.find_use_path(self.source_scope.db.upcast(), def)?; diff --git a/crates/ra_assists/src/lib.rs b/crates/ra_assists/src/lib.rs index 507646cc8..890996a68 100644 --- a/crates/ra_assists/src/lib.rs +++ b/crates/ra_assists/src/lib.rs @@ -66,13 +66,13 @@ pub struct GroupLabel(pub String); #[derive(Debug, Clone)] pub struct Assist { - pub id: AssistId, + id: AssistId, /// Short description of the assist, as shown in the UI. - pub label: String, - pub group: Option, + label: String, + group: Option, /// Target ranges are used to sort assists: the smaller the target range, /// the more specific assist is, and so it should be sorted first. - pub target: TextRange, + target: TextRange, } #[derive(Debug, Clone)] @@ -120,10 +120,25 @@ impl Assist { group: Option, target: TextRange, ) -> Assist { - // FIXME: make fields private, so that this invariant can't be broken assert!(label.starts_with(|c: char| c.is_uppercase())); Assist { id, label, group, target } } + + pub fn id(&self) -> AssistId { + self.id + } + + pub fn label(&self) -> String { + self.label.clone() + } + + pub fn group(&self) -> Option { + self.group.clone() + } + + pub fn target(&self) -> TextRange { + self.target + } } mod handlers { -- cgit v1.2.3 From ace75f95905564a34f46be57ead51828844da745 Mon Sep 17 00:00:00 2001 From: JmPotato Date: Tue, 11 Aug 2020 12:09:11 +0800 Subject: Typo fix Signed-off-by: JmPotato --- crates/ra_assists/src/tests.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'crates/ra_assists') diff --git a/crates/ra_assists/src/tests.rs b/crates/ra_assists/src/tests.rs index 18fcb9049..e73836422 100644 --- a/crates/ra_assists/src/tests.rs +++ b/crates/ra_assists/src/tests.rs @@ -20,7 +20,7 @@ pub(crate) fn check_assist(assist: Handler, ra_fixture_before: &str, ra_fixture_ // FIXME: instead of having a separate function here, maybe use // `extract_ranges` and mark the target as ` ` in the -// fixuture? +// fixture? pub(crate) fn check_assist_target(assist: Handler, ra_fixture: &str, target: &str) { check(assist, ra_fixture, ExpectedResult::Target(target)); } -- cgit v1.2.3 From b69dfddb572b9182f4880065ca5034aba8b15ce3 Mon Sep 17 00:00:00 2001 From: JmPotato Date: Tue, 11 Aug 2020 14:35:15 +0800 Subject: Remove redundant dependencies Signed-off-by: JmPotato --- crates/ra_assists/Cargo.toml | 1 - crates/ra_assists/src/ast_transform.rs | 5 ++--- 2 files changed, 2 insertions(+), 4 deletions(-) (limited to 'crates/ra_assists') diff --git a/crates/ra_assists/Cargo.toml b/crates/ra_assists/Cargo.toml index a436e861d..bd2905f08 100644 --- a/crates/ra_assists/Cargo.toml +++ b/crates/ra_assists/Cargo.toml @@ -22,5 +22,4 @@ ra_prof = { path = "../ra_prof" } ra_db = { path = "../ra_db" } ra_ide_db = { path = "../ra_ide_db" } hir = { path = "../ra_hir", package = "ra_hir" } -hir_expand = { path = "../ra_hir_expand", package = "ra_hir_expand" } test_utils = { path = "../test_utils" } diff --git a/crates/ra_assists/src/ast_transform.rs b/crates/ra_assists/src/ast_transform.rs index 02c4a4bae..6c92124ed 100644 --- a/crates/ra_assists/src/ast_transform.rs +++ b/crates/ra_assists/src/ast_transform.rs @@ -2,7 +2,6 @@ use rustc_hash::FxHashMap; use hir::{HirDisplay, PathResolution, SemanticsScope}; -use hir_expand::hygiene::Hygiene; use ra_syntax::{ algo::SyntaxRewriter, ast::{self, AstNode}, @@ -111,7 +110,7 @@ impl<'a> SubstituteTypeParams<'a> { ast::Type::PathType(path_type) => path_type.path()?, _ => return None, }; - let path = hir::Path::from_src(path, &Hygiene::new_unhygienic())?; + let path = hir::Path::from_src(path, &hir::Hygiene::new_unhygienic())?; let resolution = self.source_scope.resolve_hir_path(&path)?; match resolution { hir::PathResolution::TypeParam(tp) => Some(self.substs.get(&tp)?.syntax().clone()), @@ -151,7 +150,7 @@ impl<'a> QualifyPaths<'a> { // don't try to qualify `Fn(Foo) -> Bar` paths, they are in prelude anyway return None; } - let hir_path = hir::Path::from_src(p.clone(), &Hygiene::new_unhygienic())?; + let hir_path = hir::Path::from_src(p.clone(), &hir::Hygiene::new_unhygienic())?; let resolution = self.source_scope.resolve_hir_path(&hir_path)?; match resolution { PathResolution::Def(def) => { -- cgit v1.2.3 From 6ef019bd4601b9dc36325e096d066a4ddbda1bdf Mon Sep 17 00:00:00 2001 From: JmPotato Date: Tue, 11 Aug 2020 17:19:02 +0800 Subject: Revert some FIXMEs Signed-off-by: JmPotato --- crates/ra_assists/src/ast_transform.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'crates/ra_assists') diff --git a/crates/ra_assists/src/ast_transform.rs b/crates/ra_assists/src/ast_transform.rs index 6c92124ed..07c978378 100644 --- a/crates/ra_assists/src/ast_transform.rs +++ b/crates/ra_assists/src/ast_transform.rs @@ -110,7 +110,9 @@ impl<'a> SubstituteTypeParams<'a> { ast::Type::PathType(path_type) => path_type.path()?, _ => return None, }; - let path = hir::Path::from_src(path, &hir::Hygiene::new_unhygienic())?; + // FIXME: use `hir::Path::from_src` instead. + #[allow(deprecated)] + let path = hir::Path::from_ast(path)?; let resolution = self.source_scope.resolve_hir_path(&path)?; match resolution { hir::PathResolution::TypeParam(tp) => Some(self.substs.get(&tp)?.syntax().clone()), @@ -150,8 +152,10 @@ impl<'a> QualifyPaths<'a> { // don't try to qualify `Fn(Foo) -> Bar` paths, they are in prelude anyway return None; } - let hir_path = hir::Path::from_src(p.clone(), &hir::Hygiene::new_unhygienic())?; - let resolution = self.source_scope.resolve_hir_path(&hir_path)?; + // FIXME: use `hir::Path::from_src` instead. + #[allow(deprecated)] + let hir_path = hir::Path::from_ast(p.clone()); + let resolution = self.source_scope.resolve_hir_path(&hir_path?)?; match resolution { PathResolution::Def(def) => { let found_path = from.find_use_path(self.source_scope.db.upcast(), def)?; -- cgit v1.2.3