diff options
author | JmPotato <[email protected]> | 2020-08-11 03:55:26 +0100 |
---|---|---|
committer | JmPotato <[email protected]> | 2020-08-11 03:55:26 +0100 |
commit | dc6e1e0dac318b36ec43ffced3d4059a9b8652e5 (patch) | |
tree | 40fb2c25df0596b2fed4167458fe848132df1410 /crates/ra_assists/src | |
parent | b050937c1071e68a4ade69375f1f17b703cafb02 (diff) |
Address some FIXMEs
Signed-off-by: JmPotato <[email protected]>
Diffstat (limited to 'crates/ra_assists/src')
-rw-r--r-- | crates/ra_assists/src/ast_transform.rs | 13 | ||||
-rw-r--r-- | crates/ra_assists/src/lib.rs | 25 |
2 files changed, 25 insertions, 13 deletions
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 @@ | |||
2 | use rustc_hash::FxHashMap; | 2 | use rustc_hash::FxHashMap; |
3 | 3 | ||
4 | use hir::{HirDisplay, PathResolution, SemanticsScope}; | 4 | use hir::{HirDisplay, PathResolution, SemanticsScope}; |
5 | use hir_expand::hygiene::Hygiene; | ||
5 | use ra_syntax::{ | 6 | use ra_syntax::{ |
6 | algo::SyntaxRewriter, | 7 | algo::SyntaxRewriter, |
7 | ast::{self, AstNode}, | 8 | ast::{self, AstNode}, |
@@ -51,7 +52,7 @@ impl<'a> SubstituteTypeParams<'a> { | |||
51 | // this is a trait impl, so we need to skip the first type parameter -- this is a bit hacky | 52 | // this is a trait impl, so we need to skip the first type parameter -- this is a bit hacky |
52 | .skip(1) | 53 | .skip(1) |
53 | // The actual list of trait type parameters may be longer than the one | 54 | // The actual list of trait type parameters may be longer than the one |
54 | // used in the `impl` block due to trailing default type parametrs. | 55 | // used in the `impl` block due to trailing default type parameters. |
55 | // For that case we extend the `substs` with an empty iterator so we | 56 | // For that case we extend the `substs` with an empty iterator so we |
56 | // can still hit those trailing values and check if they actually have | 57 | // can still hit those trailing values and check if they actually have |
57 | // a default type. If they do, go for that type from `hir` to `ast` so | 58 | // a default type. If they do, go for that type from `hir` to `ast` so |
@@ -110,9 +111,7 @@ impl<'a> SubstituteTypeParams<'a> { | |||
110 | ast::Type::PathType(path_type) => path_type.path()?, | 111 | ast::Type::PathType(path_type) => path_type.path()?, |
111 | _ => return None, | 112 | _ => return None, |
112 | }; | 113 | }; |
113 | // FIXME: use `hir::Path::from_src` instead. | 114 | let path = hir::Path::from_src(path, &Hygiene::new_unhygienic())?; |
114 | #[allow(deprecated)] | ||
115 | let path = hir::Path::from_ast(path)?; | ||
116 | let resolution = self.source_scope.resolve_hir_path(&path)?; | 115 | let resolution = self.source_scope.resolve_hir_path(&path)?; |
117 | match resolution { | 116 | match resolution { |
118 | hir::PathResolution::TypeParam(tp) => Some(self.substs.get(&tp)?.syntax().clone()), | 117 | hir::PathResolution::TypeParam(tp) => Some(self.substs.get(&tp)?.syntax().clone()), |
@@ -152,10 +151,8 @@ impl<'a> QualifyPaths<'a> { | |||
152 | // don't try to qualify `Fn(Foo) -> Bar` paths, they are in prelude anyway | 151 | // don't try to qualify `Fn(Foo) -> Bar` paths, they are in prelude anyway |
153 | return None; | 152 | return None; |
154 | } | 153 | } |
155 | // FIXME: use `hir::Path::from_src` instead. | 154 | let hir_path = hir::Path::from_src(p.clone(), &Hygiene::new_unhygienic())?; |
156 | #[allow(deprecated)] | 155 | let resolution = self.source_scope.resolve_hir_path(&hir_path)?; |
157 | let hir_path = hir::Path::from_ast(p.clone()); | ||
158 | let resolution = self.source_scope.resolve_hir_path(&hir_path?)?; | ||
159 | match resolution { | 156 | match resolution { |
160 | PathResolution::Def(def) => { | 157 | PathResolution::Def(def) => { |
161 | let found_path = from.find_use_path(self.source_scope.db.upcast(), def)?; | 158 | 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); | |||
66 | 66 | ||
67 | #[derive(Debug, Clone)] | 67 | #[derive(Debug, Clone)] |
68 | pub struct Assist { | 68 | pub struct Assist { |
69 | pub id: AssistId, | 69 | id: AssistId, |
70 | /// Short description of the assist, as shown in the UI. | 70 | /// Short description of the assist, as shown in the UI. |
71 | pub label: String, | 71 | label: String, |
72 | pub group: Option<GroupLabel>, | 72 | group: Option<GroupLabel>, |
73 | /// Target ranges are used to sort assists: the smaller the target range, | 73 | /// Target ranges are used to sort assists: the smaller the target range, |
74 | /// the more specific assist is, and so it should be sorted first. | 74 | /// the more specific assist is, and so it should be sorted first. |
75 | pub target: TextRange, | 75 | target: TextRange, |
76 | } | 76 | } |
77 | 77 | ||
78 | #[derive(Debug, Clone)] | 78 | #[derive(Debug, Clone)] |
@@ -120,10 +120,25 @@ impl Assist { | |||
120 | group: Option<GroupLabel>, | 120 | group: Option<GroupLabel>, |
121 | target: TextRange, | 121 | target: TextRange, |
122 | ) -> Assist { | 122 | ) -> Assist { |
123 | // FIXME: make fields private, so that this invariant can't be broken | ||
124 | assert!(label.starts_with(|c: char| c.is_uppercase())); | 123 | assert!(label.starts_with(|c: char| c.is_uppercase())); |
125 | Assist { id, label, group, target } | 124 | Assist { id, label, group, target } |
126 | } | 125 | } |
126 | |||
127 | pub fn id(&self) -> AssistId { | ||
128 | self.id | ||
129 | } | ||
130 | |||
131 | pub fn label(&self) -> String { | ||
132 | self.label.clone() | ||
133 | } | ||
134 | |||
135 | pub fn group(&self) -> Option<GroupLabel> { | ||
136 | self.group.clone() | ||
137 | } | ||
138 | |||
139 | pub fn target(&self) -> TextRange { | ||
140 | self.target | ||
141 | } | ||
127 | } | 142 | } |
128 | 143 | ||
129 | mod handlers { | 144 | mod handlers { |