diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2019-11-20 06:44:37 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2019-11-20 06:44:37 +0000 |
commit | 4dae39a609fb58b42cbe152e66d30fe6471a34d7 (patch) | |
tree | 166ee3c45f99611f7c20740c2a246f5b3bed41a3 /crates/ra_ide_api | |
parent | eec68e6f451ee7675ce2cb29b696df091e6aed13 (diff) | |
parent | 36e3fc9d5413f7e6e17e82867aae1318645880a3 (diff) |
Merge #2319
2319: Rename Source::ast -> Source::value r=matklad a=matklad
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_ide_api')
-rw-r--r-- | crates/ra_ide_api/src/completion/completion_context.rs | 2 | ||||
-rw-r--r-- | crates/ra_ide_api/src/completion/presentation.rs | 8 | ||||
-rw-r--r-- | crates/ra_ide_api/src/diagnostics.rs | 2 | ||||
-rw-r--r-- | crates/ra_ide_api/src/display/function_signature.rs | 8 | ||||
-rw-r--r-- | crates/ra_ide_api/src/display/navigation_target.rs | 28 | ||||
-rw-r--r-- | crates/ra_ide_api/src/expand.rs | 18 | ||||
-rw-r--r-- | crates/ra_ide_api/src/expand_macro.rs | 8 | ||||
-rw-r--r-- | crates/ra_ide_api/src/goto_definition.rs | 8 | ||||
-rw-r--r-- | crates/ra_ide_api/src/goto_type_definition.rs | 2 | ||||
-rw-r--r-- | crates/ra_ide_api/src/hover.rs | 12 | ||||
-rw-r--r-- | crates/ra_ide_api/src/impls.rs | 8 | ||||
-rw-r--r-- | crates/ra_ide_api/src/parent_module.rs | 5 | ||||
-rw-r--r-- | crates/ra_ide_api/src/references/classify.rs | 8 | ||||
-rw-r--r-- | crates/ra_ide_api/src/references/name_definition.rs | 30 | ||||
-rw-r--r-- | crates/ra_ide_api/src/references/rename.rs | 4 | ||||
-rw-r--r-- | crates/ra_ide_api/src/references/search_scope.rs | 10 |
16 files changed, 83 insertions, 78 deletions
diff --git a/crates/ra_ide_api/src/completion/completion_context.rs b/crates/ra_ide_api/src/completion/completion_context.rs index 0906a4e1b..b8345c91d 100644 --- a/crates/ra_ide_api/src/completion/completion_context.rs +++ b/crates/ra_ide_api/src/completion/completion_context.rs | |||
@@ -54,7 +54,7 @@ impl<'a> CompletionContext<'a> { | |||
54 | let src = hir::ModuleSource::from_position(db, position); | 54 | let src = hir::ModuleSource::from_position(db, position); |
55 | let module = hir::Module::from_definition( | 55 | let module = hir::Module::from_definition( |
56 | db, | 56 | db, |
57 | hir::Source { file_id: position.file_id.into(), ast: src }, | 57 | hir::Source { file_id: position.file_id.into(), value: src }, |
58 | ); | 58 | ); |
59 | let token = | 59 | let token = |
60 | original_parse.tree().syntax().token_at_offset(position.offset).left_biased()?; | 60 | original_parse.tree().syntax().token_at_offset(position.offset).left_biased()?; |
diff --git a/crates/ra_ide_api/src/completion/presentation.rs b/crates/ra_ide_api/src/completion/presentation.rs index 501b7da4e..b20329459 100644 --- a/crates/ra_ide_api/src/completion/presentation.rs +++ b/crates/ra_ide_api/src/completion/presentation.rs | |||
@@ -169,7 +169,7 @@ impl Completions { | |||
169 | None => return, | 169 | None => return, |
170 | }; | 170 | }; |
171 | 171 | ||
172 | let ast_node = macro_.source(ctx.db).ast; | 172 | let ast_node = macro_.source(ctx.db).value; |
173 | let detail = macro_label(&ast_node); | 173 | let detail = macro_label(&ast_node); |
174 | 174 | ||
175 | let docs = macro_.docs(ctx.db); | 175 | let docs = macro_.docs(ctx.db); |
@@ -201,7 +201,7 @@ impl Completions { | |||
201 | ) { | 201 | ) { |
202 | let data = func.data(ctx.db); | 202 | let data = func.data(ctx.db); |
203 | let name = name.unwrap_or_else(|| data.name().to_string()); | 203 | let name = name.unwrap_or_else(|| data.name().to_string()); |
204 | let ast_node = func.source(ctx.db).ast; | 204 | let ast_node = func.source(ctx.db).value; |
205 | let detail = function_label(&ast_node); | 205 | let detail = function_label(&ast_node); |
206 | 206 | ||
207 | let mut builder = | 207 | let mut builder = |
@@ -234,7 +234,7 @@ impl Completions { | |||
234 | } | 234 | } |
235 | 235 | ||
236 | pub(crate) fn add_const(&mut self, ctx: &CompletionContext, constant: hir::Const) { | 236 | pub(crate) fn add_const(&mut self, ctx: &CompletionContext, constant: hir::Const) { |
237 | let ast_node = constant.source(ctx.db).ast; | 237 | let ast_node = constant.source(ctx.db).value; |
238 | let name = match ast_node.name() { | 238 | let name = match ast_node.name() { |
239 | Some(name) => name, | 239 | Some(name) => name, |
240 | _ => return, | 240 | _ => return, |
@@ -250,7 +250,7 @@ impl Completions { | |||
250 | } | 250 | } |
251 | 251 | ||
252 | pub(crate) fn add_type_alias(&mut self, ctx: &CompletionContext, type_alias: hir::TypeAlias) { | 252 | pub(crate) fn add_type_alias(&mut self, ctx: &CompletionContext, type_alias: hir::TypeAlias) { |
253 | let type_def = type_alias.source(ctx.db).ast; | 253 | let type_def = type_alias.source(ctx.db).value; |
254 | let name = match type_def.name() { | 254 | let name = match type_def.name() { |
255 | Some(name) => name, | 255 | Some(name) => name, |
256 | _ => return, | 256 | _ => return, |
diff --git a/crates/ra_ide_api/src/diagnostics.rs b/crates/ra_ide_api/src/diagnostics.rs index e52ffefb3..cc1ccab4b 100644 --- a/crates/ra_ide_api/src/diagnostics.rs +++ b/crates/ra_ide_api/src/diagnostics.rs | |||
@@ -96,7 +96,7 @@ pub(crate) fn diagnostics(db: &RootDatabase, file_id: FileId) -> Vec<Diagnostic> | |||
96 | }); | 96 | }); |
97 | let source_file = db.parse(file_id).tree(); | 97 | let source_file = db.parse(file_id).tree(); |
98 | let src = | 98 | let src = |
99 | hir::Source { file_id: file_id.into(), ast: hir::ModuleSource::SourceFile(source_file) }; | 99 | hir::Source { file_id: file_id.into(), value: hir::ModuleSource::SourceFile(source_file) }; |
100 | if let Some(m) = hir::Module::from_definition(db, src) { | 100 | if let Some(m) = hir::Module::from_definition(db, src) { |
101 | m.diagnostics(db, &mut sink); | 101 | m.diagnostics(db, &mut sink); |
102 | }; | 102 | }; |
diff --git a/crates/ra_ide_api/src/display/function_signature.rs b/crates/ra_ide_api/src/display/function_signature.rs index 9075ca443..f42dffc87 100644 --- a/crates/ra_ide_api/src/display/function_signature.rs +++ b/crates/ra_ide_api/src/display/function_signature.rs | |||
@@ -48,12 +48,12 @@ impl FunctionSignature { | |||
48 | 48 | ||
49 | pub(crate) fn from_hir(db: &db::RootDatabase, function: hir::Function) -> Self { | 49 | pub(crate) fn from_hir(db: &db::RootDatabase, function: hir::Function) -> Self { |
50 | let doc = function.docs(db); | 50 | let doc = function.docs(db); |
51 | let ast_node = function.source(db).ast; | 51 | let ast_node = function.source(db).value; |
52 | FunctionSignature::from(&ast_node).with_doc_opt(doc) | 52 | FunctionSignature::from(&ast_node).with_doc_opt(doc) |
53 | } | 53 | } |
54 | 54 | ||
55 | pub(crate) fn from_struct(db: &db::RootDatabase, st: hir::Struct) -> Option<Self> { | 55 | pub(crate) fn from_struct(db: &db::RootDatabase, st: hir::Struct) -> Option<Self> { |
56 | let node: ast::StructDef = st.source(db).ast; | 56 | let node: ast::StructDef = st.source(db).value; |
57 | match node.kind() { | 57 | match node.kind() { |
58 | ast::StructKind::Named(_) => return None, | 58 | ast::StructKind::Named(_) => return None, |
59 | _ => (), | 59 | _ => (), |
@@ -87,7 +87,7 @@ impl FunctionSignature { | |||
87 | db: &db::RootDatabase, | 87 | db: &db::RootDatabase, |
88 | variant: hir::EnumVariant, | 88 | variant: hir::EnumVariant, |
89 | ) -> Option<Self> { | 89 | ) -> Option<Self> { |
90 | let node: ast::EnumVariant = variant.source(db).ast; | 90 | let node: ast::EnumVariant = variant.source(db).value; |
91 | match node.kind() { | 91 | match node.kind() { |
92 | ast::StructKind::Named(_) | ast::StructKind::Unit => return None, | 92 | ast::StructKind::Named(_) | ast::StructKind::Unit => return None, |
93 | _ => (), | 93 | _ => (), |
@@ -126,7 +126,7 @@ impl FunctionSignature { | |||
126 | } | 126 | } |
127 | 127 | ||
128 | pub(crate) fn from_macro(db: &db::RootDatabase, macro_def: hir::MacroDef) -> Option<Self> { | 128 | pub(crate) fn from_macro(db: &db::RootDatabase, macro_def: hir::MacroDef) -> Option<Self> { |
129 | let node: ast::MacroCall = macro_def.source(db).ast; | 129 | let node: ast::MacroCall = macro_def.source(db).value; |
130 | 130 | ||
131 | let params = vec![]; | 131 | let params = vec![]; |
132 | 132 | ||
diff --git a/crates/ra_ide_api/src/display/navigation_target.rs b/crates/ra_ide_api/src/display/navigation_target.rs index b30ef8e05..50accafd0 100644 --- a/crates/ra_ide_api/src/display/navigation_target.rs +++ b/crates/ra_ide_api/src/display/navigation_target.rs | |||
@@ -86,9 +86,9 @@ impl NavigationTarget { | |||
86 | name, | 86 | name, |
87 | None, | 87 | None, |
88 | frange.range, | 88 | frange.range, |
89 | src.ast.syntax().kind(), | 89 | src.value.syntax().kind(), |
90 | src.ast.doc_comment_text(), | 90 | src.value.doc_comment_text(), |
91 | src.ast.short_label(), | 91 | src.value.short_label(), |
92 | ); | 92 | ); |
93 | } | 93 | } |
94 | module.to_nav(db) | 94 | module.to_nav(db) |
@@ -146,9 +146,9 @@ impl NavigationTarget { | |||
146 | description: Option<String>, | 146 | description: Option<String>, |
147 | ) -> NavigationTarget { | 147 | ) -> NavigationTarget { |
148 | //FIXME: use `_` instead of empty string | 148 | //FIXME: use `_` instead of empty string |
149 | let name = node.ast.name().map(|it| it.text().clone()).unwrap_or_default(); | 149 | let name = node.value.name().map(|it| it.text().clone()).unwrap_or_default(); |
150 | let focus_range = | 150 | let focus_range = |
151 | node.ast.name().map(|it| original_range(db, node.with_ast(it.syntax())).range); | 151 | node.value.name().map(|it| original_range(db, node.with_ast(it.syntax())).range); |
152 | let frange = original_range(db, node.map(|it| it.syntax())); | 152 | let frange = original_range(db, node.map(|it| it.syntax())); |
153 | 153 | ||
154 | NavigationTarget::from_syntax( | 154 | NavigationTarget::from_syntax( |
@@ -156,7 +156,7 @@ impl NavigationTarget { | |||
156 | name, | 156 | name, |
157 | focus_range, | 157 | focus_range, |
158 | frange.range, | 158 | frange.range, |
159 | node.ast.syntax().kind(), | 159 | node.value.syntax().kind(), |
160 | docs, | 160 | docs, |
161 | description, | 161 | description, |
162 | ) | 162 | ) |
@@ -220,8 +220,8 @@ where | |||
220 | NavigationTarget::from_named( | 220 | NavigationTarget::from_named( |
221 | db, | 221 | db, |
222 | src.as_ref().map(|it| it as &dyn ast::NameOwner), | 222 | src.as_ref().map(|it| it as &dyn ast::NameOwner), |
223 | src.ast.doc_comment_text(), | 223 | src.value.doc_comment_text(), |
224 | src.ast.short_label(), | 224 | src.value.short_label(), |
225 | ) | 225 | ) |
226 | } | 226 | } |
227 | } | 227 | } |
@@ -230,7 +230,7 @@ impl ToNav for hir::Module { | |||
230 | fn to_nav(&self, db: &RootDatabase) -> NavigationTarget { | 230 | fn to_nav(&self, db: &RootDatabase) -> NavigationTarget { |
231 | let src = self.definition_source(db); | 231 | let src = self.definition_source(db); |
232 | let name = self.name(db).map(|it| it.to_string().into()).unwrap_or_default(); | 232 | let name = self.name(db).map(|it| it.to_string().into()).unwrap_or_default(); |
233 | match &src.ast { | 233 | match &src.value { |
234 | ModuleSource::SourceFile(node) => { | 234 | ModuleSource::SourceFile(node) => { |
235 | let frange = original_range(db, src.with_ast(node.syntax())); | 235 | let frange = original_range(db, src.with_ast(node.syntax())); |
236 | 236 | ||
@@ -271,7 +271,7 @@ impl ToNav for hir::ImplBlock { | |||
271 | "impl".into(), | 271 | "impl".into(), |
272 | None, | 272 | None, |
273 | frange.range, | 273 | frange.range, |
274 | src.ast.syntax().kind(), | 274 | src.value.syntax().kind(), |
275 | None, | 275 | None, |
276 | None, | 276 | None, |
277 | ) | 277 | ) |
@@ -282,7 +282,7 @@ impl ToNav for hir::StructField { | |||
282 | fn to_nav(&self, db: &RootDatabase) -> NavigationTarget { | 282 | fn to_nav(&self, db: &RootDatabase) -> NavigationTarget { |
283 | let src = self.source(db); | 283 | let src = self.source(db); |
284 | 284 | ||
285 | match &src.ast { | 285 | match &src.value { |
286 | FieldSource::Named(it) => NavigationTarget::from_named( | 286 | FieldSource::Named(it) => NavigationTarget::from_named( |
287 | db, | 287 | db, |
288 | src.with_ast(it), | 288 | src.with_ast(it), |
@@ -308,11 +308,11 @@ impl ToNav for hir::StructField { | |||
308 | impl ToNav for hir::MacroDef { | 308 | impl ToNav for hir::MacroDef { |
309 | fn to_nav(&self, db: &RootDatabase) -> NavigationTarget { | 309 | fn to_nav(&self, db: &RootDatabase) -> NavigationTarget { |
310 | let src = self.source(db); | 310 | let src = self.source(db); |
311 | log::debug!("nav target {:#?}", src.ast.syntax()); | 311 | log::debug!("nav target {:#?}", src.value.syntax()); |
312 | NavigationTarget::from_named( | 312 | NavigationTarget::from_named( |
313 | db, | 313 | db, |
314 | src.as_ref().map(|it| it as &dyn ast::NameOwner), | 314 | src.as_ref().map(|it| it as &dyn ast::NameOwner), |
315 | src.ast.doc_comment_text(), | 315 | src.value.doc_comment_text(), |
316 | None, | 316 | None, |
317 | ) | 317 | ) |
318 | } | 318 | } |
@@ -341,7 +341,7 @@ impl ToNav for hir::AssocItem { | |||
341 | impl ToNav for hir::Local { | 341 | impl ToNav for hir::Local { |
342 | fn to_nav(&self, db: &RootDatabase) -> NavigationTarget { | 342 | fn to_nav(&self, db: &RootDatabase) -> NavigationTarget { |
343 | let src = self.source(db); | 343 | let src = self.source(db); |
344 | let (full_range, focus_range) = match src.ast { | 344 | let (full_range, focus_range) = match src.value { |
345 | Either::A(it) => { | 345 | Either::A(it) => { |
346 | (it.syntax().text_range(), it.name().map(|it| it.syntax().text_range())) | 346 | (it.syntax().text_range(), it.name().map(|it| it.syntax().text_range())) |
347 | } | 347 | } |
diff --git a/crates/ra_ide_api/src/expand.rs b/crates/ra_ide_api/src/expand.rs index 7f59e46d2..0228bced9 100644 --- a/crates/ra_ide_api/src/expand.rs +++ b/crates/ra_ide_api/src/expand.rs | |||
@@ -12,7 +12,7 @@ pub(crate) fn original_range(db: &RootDatabase, node: Source<&SyntaxNode>) -> Fi | |||
12 | None => { | 12 | None => { |
13 | return FileRange { | 13 | return FileRange { |
14 | file_id: node.file_id.original_file(db), | 14 | file_id: node.file_id.original_file(db), |
15 | range: node.ast.text_range(), | 15 | range: node.value.text_range(), |
16 | } | 16 | } |
17 | } | 17 | } |
18 | Some(it) => it, | 18 | Some(it) => it, |
@@ -25,14 +25,18 @@ pub(crate) fn original_range(db: &RootDatabase, node: Source<&SyntaxNode>) -> Fi | |||
25 | // *Second*, we should handle recurside macro expansions | 25 | // *Second*, we should handle recurside macro expansions |
26 | 26 | ||
27 | let token = node | 27 | let token = node |
28 | .ast | 28 | .value |
29 | .descendants_with_tokens() | 29 | .descendants_with_tokens() |
30 | .filter_map(|it| it.into_token()) | 30 | .filter_map(|it| it.into_token()) |
31 | .find_map(|it| expansion.map_token_up(node.with_ast(&it))); | 31 | .find_map(|it| expansion.map_token_up(node.with_ast(&it))); |
32 | 32 | ||
33 | match token { | 33 | match token { |
34 | Some(it) => FileRange { file_id: it.file_id.original_file(db), range: it.ast.text_range() }, | 34 | Some(it) => { |
35 | None => FileRange { file_id: node.file_id.original_file(db), range: node.ast.text_range() }, | 35 | FileRange { file_id: it.file_id.original_file(db), range: it.value.text_range() } |
36 | } | ||
37 | None => { | ||
38 | FileRange { file_id: node.file_id.original_file(db), range: node.value.text_range() } | ||
39 | } | ||
36 | } | 40 | } |
37 | } | 41 | } |
38 | 42 | ||
@@ -44,13 +48,13 @@ pub(crate) fn descend_into_macros( | |||
44 | let src = Source::new(file_id.into(), token); | 48 | let src = Source::new(file_id.into(), token); |
45 | 49 | ||
46 | successors(Some(src), |token| { | 50 | successors(Some(src), |token| { |
47 | let macro_call = token.ast.ancestors().find_map(ast::MacroCall::cast)?; | 51 | let macro_call = token.value.ancestors().find_map(ast::MacroCall::cast)?; |
48 | let tt = macro_call.token_tree()?; | 52 | let tt = macro_call.token_tree()?; |
49 | if !token.ast.text_range().is_subrange(&tt.syntax().text_range()) { | 53 | if !token.value.text_range().is_subrange(&tt.syntax().text_range()) { |
50 | return None; | 54 | return None; |
51 | } | 55 | } |
52 | let source_analyzer = | 56 | let source_analyzer = |
53 | hir::SourceAnalyzer::new(db, token.with_ast(token.ast.parent()).as_ref(), None); | 57 | hir::SourceAnalyzer::new(db, token.with_ast(token.value.parent()).as_ref(), None); |
54 | let exp = source_analyzer.expand(db, ¯o_call)?; | 58 | let exp = source_analyzer.expand(db, ¯o_call)?; |
55 | exp.map_token_down(db, token.as_ref()) | 59 | exp.map_token_down(db, token.as_ref()) |
56 | }) | 60 | }) |
diff --git a/crates/ra_ide_api/src/expand_macro.rs b/crates/ra_ide_api/src/expand_macro.rs index e9eb2a7fb..2d478ec09 100644 --- a/crates/ra_ide_api/src/expand_macro.rs +++ b/crates/ra_ide_api/src/expand_macro.rs | |||
@@ -46,7 +46,7 @@ fn expand_macro_recur( | |||
46 | let mut replaces = FxHashMap::default(); | 46 | let mut replaces = FxHashMap::default(); |
47 | 47 | ||
48 | for child in children.into_iter() { | 48 | for child in children.into_iter() { |
49 | let source = hir::Source::new(macro_file_id, source.ast); | 49 | let source = hir::Source::new(macro_file_id, source.value); |
50 | let new_node = expand_macro_recur(db, source, &child)?; | 50 | let new_node = expand_macro_recur(db, source, &child)?; |
51 | 51 | ||
52 | replaces.insert(child.syntax().clone().into(), new_node.into()); | 52 | replaces.insert(child.syntax().clone().into(), new_node.into()); |
@@ -139,7 +139,7 @@ mod tests { | |||
139 | } | 139 | } |
140 | macro_rules! baz { | 140 | macro_rules! baz { |
141 | () => { foo!(); } | 141 | () => { foo!(); } |
142 | } | 142 | } |
143 | f<|>oo!(); | 143 | f<|>oo!(); |
144 | "#, | 144 | "#, |
145 | ); | 145 | ); |
@@ -156,7 +156,7 @@ fn b(){} | |||
156 | r#" | 156 | r#" |
157 | //- /lib.rs | 157 | //- /lib.rs |
158 | macro_rules! foo { | 158 | macro_rules! foo { |
159 | () => { | 159 | () => { |
160 | fn some_thing() -> u32 { | 160 | fn some_thing() -> u32 { |
161 | let a = 0; | 161 | let a = 0; |
162 | a + 10 | 162 | a + 10 |
@@ -172,7 +172,7 @@ fn b(){} | |||
172 | fn some_thing() -> u32 { | 172 | fn some_thing() -> u32 { |
173 | let a = 0; | 173 | let a = 0; |
174 | a+10 | 174 | a+10 |
175 | } | 175 | } |
176 | "###); | 176 | "###); |
177 | } | 177 | } |
178 | } | 178 | } |
diff --git a/crates/ra_ide_api/src/goto_definition.rs b/crates/ra_ide_api/src/goto_definition.rs index 3f16e9566..ed9d99a7f 100644 --- a/crates/ra_ide_api/src/goto_definition.rs +++ b/crates/ra_ide_api/src/goto_definition.rs | |||
@@ -23,7 +23,7 @@ pub(crate) fn goto_definition( | |||
23 | let token = descend_into_macros(db, position.file_id, token); | 23 | let token = descend_into_macros(db, position.file_id, token); |
24 | 24 | ||
25 | let res = match_ast! { | 25 | let res = match_ast! { |
26 | match (token.ast.parent()) { | 26 | match (token.value.parent()) { |
27 | ast::NameRef(name_ref) => { | 27 | ast::NameRef(name_ref) => { |
28 | let navs = reference_definition(db, token.with_ast(&name_ref)).to_vec(); | 28 | let navs = reference_definition(db, token.with_ast(&name_ref)).to_vec(); |
29 | RangeInfo::new(name_ref.syntax().text_range(), navs.to_vec()) | 29 | RangeInfo::new(name_ref.syntax().text_range(), navs.to_vec()) |
@@ -84,7 +84,7 @@ pub(crate) fn reference_definition( | |||
84 | }; | 84 | }; |
85 | 85 | ||
86 | // Fallback index based approach: | 86 | // Fallback index based approach: |
87 | let navs = crate::symbol_index::index_resolve(db, name_ref.ast) | 87 | let navs = crate::symbol_index::index_resolve(db, name_ref.value) |
88 | .into_iter() | 88 | .into_iter() |
89 | .map(|s| s.to_nav(db)) | 89 | .map(|s| s.to_nav(db)) |
90 | .collect(); | 90 | .collect(); |
@@ -95,7 +95,7 @@ pub(crate) fn name_definition( | |||
95 | db: &RootDatabase, | 95 | db: &RootDatabase, |
96 | name: Source<&ast::Name>, | 96 | name: Source<&ast::Name>, |
97 | ) -> Option<Vec<NavigationTarget>> { | 97 | ) -> Option<Vec<NavigationTarget>> { |
98 | let parent = name.ast.syntax().parent()?; | 98 | let parent = name.value.syntax().parent()?; |
99 | 99 | ||
100 | if let Some(module) = ast::Module::cast(parent.clone()) { | 100 | if let Some(module) = ast::Module::cast(parent.clone()) { |
101 | if module.has_semi() { | 101 | if module.has_semi() { |
@@ -116,7 +116,7 @@ pub(crate) fn name_definition( | |||
116 | 116 | ||
117 | fn named_target(db: &RootDatabase, node: Source<&SyntaxNode>) -> Option<NavigationTarget> { | 117 | fn named_target(db: &RootDatabase, node: Source<&SyntaxNode>) -> Option<NavigationTarget> { |
118 | match_ast! { | 118 | match_ast! { |
119 | match (node.ast) { | 119 | match (node.value) { |
120 | ast::StructDef(it) => { | 120 | ast::StructDef(it) => { |
121 | Some(NavigationTarget::from_named( | 121 | Some(NavigationTarget::from_named( |
122 | db, | 122 | db, |
diff --git a/crates/ra_ide_api/src/goto_type_definition.rs b/crates/ra_ide_api/src/goto_type_definition.rs index 7d694e1f6..6aeeefa1f 100644 --- a/crates/ra_ide_api/src/goto_type_definition.rs +++ b/crates/ra_ide_api/src/goto_type_definition.rs | |||
@@ -16,7 +16,7 @@ pub(crate) fn goto_type_definition( | |||
16 | let token = file.token_at_offset(position.offset).filter(|it| !it.kind().is_trivia()).next()?; | 16 | let token = file.token_at_offset(position.offset).filter(|it| !it.kind().is_trivia()).next()?; |
17 | let token = descend_into_macros(db, position.file_id, token); | 17 | let token = descend_into_macros(db, position.file_id, token); |
18 | 18 | ||
19 | let node = token.ast.ancestors().find_map(|token| { | 19 | let node = token.value.ancestors().find_map(|token| { |
20 | token | 20 | token |
21 | .ancestors() | 21 | .ancestors() |
22 | .find(|n| ast::Expr::cast(n.clone()).is_some() || ast::Pat::cast(n.clone()).is_some()) | 22 | .find(|n| ast::Expr::cast(n.clone()).is_some() || ast::Pat::cast(n.clone()).is_some()) |
diff --git a/crates/ra_ide_api/src/hover.rs b/crates/ra_ide_api/src/hover.rs index 787b714b3..e8a340ba4 100644 --- a/crates/ra_ide_api/src/hover.rs +++ b/crates/ra_ide_api/src/hover.rs | |||
@@ -101,11 +101,11 @@ fn hover_text_from_name_kind( | |||
101 | return match name_kind { | 101 | return match name_kind { |
102 | Macro(it) => { | 102 | Macro(it) => { |
103 | let src = it.source(db); | 103 | let src = it.source(db); |
104 | hover_text(src.ast.doc_comment_text(), Some(macro_label(&src.ast))) | 104 | hover_text(src.value.doc_comment_text(), Some(macro_label(&src.value))) |
105 | } | 105 | } |
106 | Field(it) => { | 106 | Field(it) => { |
107 | let src = it.source(db); | 107 | let src = it.source(db); |
108 | match src.ast { | 108 | match src.value { |
109 | hir::FieldSource::Named(it) => hover_text(it.doc_comment_text(), it.short_label()), | 109 | hir::FieldSource::Named(it) => hover_text(it.doc_comment_text(), it.short_label()), |
110 | _ => None, | 110 | _ => None, |
111 | } | 111 | } |
@@ -116,7 +116,7 @@ fn hover_text_from_name_kind( | |||
116 | hir::AssocItem::TypeAlias(it) => from_def_source(db, it), | 116 | hir::AssocItem::TypeAlias(it) => from_def_source(db, it), |
117 | }, | 117 | }, |
118 | Def(it) => match it { | 118 | Def(it) => match it { |
119 | hir::ModuleDef::Module(it) => match it.definition_source(db).ast { | 119 | hir::ModuleDef::Module(it) => match it.definition_source(db).value { |
120 | hir::ModuleSource::Module(it) => { | 120 | hir::ModuleSource::Module(it) => { |
121 | hover_text(it.doc_comment_text(), it.short_label()) | 121 | hover_text(it.doc_comment_text(), it.short_label()) |
122 | } | 122 | } |
@@ -158,7 +158,7 @@ fn hover_text_from_name_kind( | |||
158 | A: ast::DocCommentsOwner + ast::NameOwner + ShortLabel, | 158 | A: ast::DocCommentsOwner + ast::NameOwner + ShortLabel, |
159 | { | 159 | { |
160 | let src = def.source(db); | 160 | let src = def.source(db); |
161 | hover_text(src.ast.doc_comment_text(), src.ast.short_label()) | 161 | hover_text(src.value.doc_comment_text(), src.value.short_label()) |
162 | } | 162 | } |
163 | } | 163 | } |
164 | 164 | ||
@@ -170,7 +170,7 @@ pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option<RangeIn | |||
170 | let mut res = HoverResult::new(); | 170 | let mut res = HoverResult::new(); |
171 | 171 | ||
172 | let mut range = match_ast! { | 172 | let mut range = match_ast! { |
173 | match (token.ast.parent()) { | 173 | match (token.value.parent()) { |
174 | ast::NameRef(name_ref) => { | 174 | ast::NameRef(name_ref) => { |
175 | let mut no_fallback = false; | 175 | let mut no_fallback = false; |
176 | if let Some(name_kind) = | 176 | if let Some(name_kind) = |
@@ -211,7 +211,7 @@ pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option<RangeIn | |||
211 | }; | 211 | }; |
212 | 212 | ||
213 | if range.is_none() { | 213 | if range.is_none() { |
214 | let node = token.ast.ancestors().find(|n| { | 214 | let node = token.value.ancestors().find(|n| { |
215 | ast::Expr::cast(n.clone()).is_some() || ast::Pat::cast(n.clone()).is_some() | 215 | ast::Expr::cast(n.clone()).is_some() || ast::Pat::cast(n.clone()).is_some() |
216 | })?; | 216 | })?; |
217 | let frange = FileRange { file_id: position.file_id, range: node.text_range() }; | 217 | let frange = FileRange { file_id: position.file_id, range: node.text_range() }; |
diff --git a/crates/ra_ide_api/src/impls.rs b/crates/ra_ide_api/src/impls.rs index bc9b66550..3e3012559 100644 --- a/crates/ra_ide_api/src/impls.rs +++ b/crates/ra_ide_api/src/impls.rs | |||
@@ -16,7 +16,7 @@ pub(crate) fn goto_implementation( | |||
16 | let src = hir::ModuleSource::from_position(db, position); | 16 | let src = hir::ModuleSource::from_position(db, position); |
17 | let module = hir::Module::from_definition( | 17 | let module = hir::Module::from_definition( |
18 | db, | 18 | db, |
19 | hir::Source { file_id: position.file_id.into(), ast: src }, | 19 | hir::Source { file_id: position.file_id.into(), value: src }, |
20 | )?; | 20 | )?; |
21 | 21 | ||
22 | if let Some(nominal_def) = find_node_at_offset::<ast::NominalDef>(&syntax, position.offset) { | 22 | if let Some(nominal_def) = find_node_at_offset::<ast::NominalDef>(&syntax, position.offset) { |
@@ -42,11 +42,11 @@ fn impls_for_def( | |||
42 | ) -> Option<Vec<NavigationTarget>> { | 42 | ) -> Option<Vec<NavigationTarget>> { |
43 | let ty = match node { | 43 | let ty = match node { |
44 | ast::NominalDef::StructDef(def) => { | 44 | ast::NominalDef::StructDef(def) => { |
45 | let src = hir::Source { file_id: position.file_id.into(), ast: def.clone() }; | 45 | let src = hir::Source { file_id: position.file_id.into(), value: def.clone() }; |
46 | hir::Struct::from_source(db, src)?.ty(db) | 46 | hir::Struct::from_source(db, src)?.ty(db) |
47 | } | 47 | } |
48 | ast::NominalDef::EnumDef(def) => { | 48 | ast::NominalDef::EnumDef(def) => { |
49 | let src = hir::Source { file_id: position.file_id.into(), ast: def.clone() }; | 49 | let src = hir::Source { file_id: position.file_id.into(), value: def.clone() }; |
50 | hir::Enum::from_source(db, src)?.ty(db) | 50 | hir::Enum::from_source(db, src)?.ty(db) |
51 | } | 51 | } |
52 | }; | 52 | }; |
@@ -69,7 +69,7 @@ fn impls_for_trait( | |||
69 | node: &ast::TraitDef, | 69 | node: &ast::TraitDef, |
70 | module: hir::Module, | 70 | module: hir::Module, |
71 | ) -> Option<Vec<NavigationTarget>> { | 71 | ) -> Option<Vec<NavigationTarget>> { |
72 | let src = hir::Source { file_id: position.file_id.into(), ast: node.clone() }; | 72 | let src = hir::Source { file_id: position.file_id.into(), value: node.clone() }; |
73 | let tr = hir::Trait::from_source(db, src)?; | 73 | let tr = hir::Trait::from_source(db, src)?; |
74 | 74 | ||
75 | let krate = module.krate(); | 75 | let krate = module.krate(); |
diff --git a/crates/ra_ide_api/src/parent_module.rs b/crates/ra_ide_api/src/parent_module.rs index 4c57566e2..fa232a379 100644 --- a/crates/ra_ide_api/src/parent_module.rs +++ b/crates/ra_ide_api/src/parent_module.rs | |||
@@ -10,7 +10,7 @@ pub(crate) fn parent_module(db: &RootDatabase, position: FilePosition) -> Vec<Na | |||
10 | let src = hir::ModuleSource::from_position(db, position); | 10 | let src = hir::ModuleSource::from_position(db, position); |
11 | let module = match hir::Module::from_definition( | 11 | let module = match hir::Module::from_definition( |
12 | db, | 12 | db, |
13 | hir::Source { file_id: position.file_id.into(), ast: src }, | 13 | hir::Source { file_id: position.file_id.into(), value: src }, |
14 | ) { | 14 | ) { |
15 | None => return Vec::new(), | 15 | None => return Vec::new(), |
16 | Some(it) => it, | 16 | Some(it) => it, |
@@ -23,7 +23,8 @@ pub(crate) fn parent_module(db: &RootDatabase, position: FilePosition) -> Vec<Na | |||
23 | pub(crate) fn crate_for(db: &RootDatabase, file_id: FileId) -> Vec<CrateId> { | 23 | pub(crate) fn crate_for(db: &RootDatabase, file_id: FileId) -> Vec<CrateId> { |
24 | let src = hir::ModuleSource::from_file_id(db, file_id); | 24 | let src = hir::ModuleSource::from_file_id(db, file_id); |
25 | let module = | 25 | let module = |
26 | match hir::Module::from_definition(db, hir::Source { file_id: file_id.into(), ast: src }) { | 26 | match hir::Module::from_definition(db, hir::Source { file_id: file_id.into(), value: src }) |
27 | { | ||
27 | Some(it) => it, | 28 | Some(it) => it, |
28 | None => return Vec::new(), | 29 | None => return Vec::new(), |
29 | }; | 30 | }; |
diff --git a/crates/ra_ide_api/src/references/classify.rs b/crates/ra_ide_api/src/references/classify.rs index ea9d20e71..333264540 100644 --- a/crates/ra_ide_api/src/references/classify.rs +++ b/crates/ra_ide_api/src/references/classify.rs | |||
@@ -13,7 +13,7 @@ use crate::db::RootDatabase; | |||
13 | 13 | ||
14 | pub(crate) fn classify_name(db: &RootDatabase, name: Source<&ast::Name>) -> Option<NameDefinition> { | 14 | pub(crate) fn classify_name(db: &RootDatabase, name: Source<&ast::Name>) -> Option<NameDefinition> { |
15 | let _p = profile("classify_name"); | 15 | let _p = profile("classify_name"); |
16 | let parent = name.ast.syntax().parent()?; | 16 | let parent = name.value.syntax().parent()?; |
17 | 17 | ||
18 | match_ast! { | 18 | match_ast! { |
19 | match parent { | 19 | match parent { |
@@ -121,7 +121,7 @@ pub(crate) fn classify_name_ref( | |||
121 | ) -> Option<NameDefinition> { | 121 | ) -> Option<NameDefinition> { |
122 | let _p = profile("classify_name_ref"); | 122 | let _p = profile("classify_name_ref"); |
123 | 123 | ||
124 | let parent = name_ref.ast.syntax().parent()?; | 124 | let parent = name_ref.value.syntax().parent()?; |
125 | let analyzer = SourceAnalyzer::new(db, name_ref.map(|it| it.syntax()), None); | 125 | let analyzer = SourceAnalyzer::new(db, name_ref.map(|it| it.syntax()), None); |
126 | 126 | ||
127 | if let Some(method_call) = ast::MethodCallExpr::cast(parent.clone()) { | 127 | if let Some(method_call) = ast::MethodCallExpr::cast(parent.clone()) { |
@@ -142,7 +142,7 @@ pub(crate) fn classify_name_ref( | |||
142 | tested_by!(goto_definition_works_for_record_fields); | 142 | tested_by!(goto_definition_works_for_record_fields); |
143 | if let Some(record_lit) = record_field.syntax().ancestors().find_map(ast::RecordLit::cast) { | 143 | if let Some(record_lit) = record_field.syntax().ancestors().find_map(ast::RecordLit::cast) { |
144 | let variant_def = analyzer.resolve_record_literal(&record_lit)?; | 144 | let variant_def = analyzer.resolve_record_literal(&record_lit)?; |
145 | let hir_path = Path::from_name_ref(name_ref.ast); | 145 | let hir_path = Path::from_name_ref(name_ref.value); |
146 | let hir_name = hir_path.as_ident()?; | 146 | let hir_name = hir_path.as_ident()?; |
147 | let field = variant_def.field(db, hir_name)?; | 147 | let field = variant_def.field(db, hir_name)?; |
148 | return Some(from_struct_field(db, field)); | 148 | return Some(from_struct_field(db, field)); |
@@ -162,7 +162,7 @@ pub(crate) fn classify_name_ref( | |||
162 | } | 162 | } |
163 | } | 163 | } |
164 | 164 | ||
165 | let path = name_ref.ast.syntax().ancestors().find_map(ast::Path::cast)?; | 165 | let path = name_ref.value.syntax().ancestors().find_map(ast::Path::cast)?; |
166 | let resolved = analyzer.resolve_path(db, &path)?; | 166 | let resolved = analyzer.resolve_path(db, &path)?; |
167 | match resolved { | 167 | match resolved { |
168 | PathResolution::Def(def) => Some(from_module_def(db, def, Some(container))), | 168 | PathResolution::Def(def) => Some(from_module_def(db, def, Some(container))), |
diff --git a/crates/ra_ide_api/src/references/name_definition.rs b/crates/ra_ide_api/src/references/name_definition.rs index ccd75278a..aca23f79e 100644 --- a/crates/ra_ide_api/src/references/name_definition.rs +++ b/crates/ra_ide_api/src/references/name_definition.rs | |||
@@ -32,9 +32,9 @@ pub(crate) struct NameDefinition { | |||
32 | pub(super) fn from_assoc_item(db: &RootDatabase, item: AssocItem) -> NameDefinition { | 32 | pub(super) fn from_assoc_item(db: &RootDatabase, item: AssocItem) -> NameDefinition { |
33 | let container = item.module(db); | 33 | let container = item.module(db); |
34 | let visibility = match item { | 34 | let visibility = match item { |
35 | AssocItem::Function(f) => f.source(db).ast.visibility(), | 35 | AssocItem::Function(f) => f.source(db).value.visibility(), |
36 | AssocItem::Const(c) => c.source(db).ast.visibility(), | 36 | AssocItem::Const(c) => c.source(db).value.visibility(), |
37 | AssocItem::TypeAlias(a) => a.source(db).ast.visibility(), | 37 | AssocItem::TypeAlias(a) => a.source(db).value.visibility(), |
38 | }; | 38 | }; |
39 | let kind = NameKind::AssocItem(item); | 39 | let kind = NameKind::AssocItem(item); |
40 | NameDefinition { kind, container, visibility } | 40 | NameDefinition { kind, container, visibility } |
@@ -45,8 +45,8 @@ pub(super) fn from_struct_field(db: &RootDatabase, field: StructField) -> NameDe | |||
45 | let parent = field.parent_def(db); | 45 | let parent = field.parent_def(db); |
46 | let container = parent.module(db); | 46 | let container = parent.module(db); |
47 | let visibility = match parent { | 47 | let visibility = match parent { |
48 | VariantDef::Struct(s) => s.source(db).ast.visibility(), | 48 | VariantDef::Struct(s) => s.source(db).value.visibility(), |
49 | VariantDef::EnumVariant(e) => e.source(db).ast.parent_enum().visibility(), | 49 | VariantDef::EnumVariant(e) => e.source(db).value.parent_enum().visibility(), |
50 | }; | 50 | }; |
51 | NameDefinition { kind, container, visibility } | 51 | NameDefinition { kind, container, visibility } |
52 | } | 52 | } |
@@ -60,22 +60,22 @@ pub(super) fn from_module_def( | |||
60 | let (container, visibility) = match def { | 60 | let (container, visibility) = match def { |
61 | ModuleDef::Module(it) => { | 61 | ModuleDef::Module(it) => { |
62 | let container = it.parent(db).or_else(|| Some(it)).unwrap(); | 62 | let container = it.parent(db).or_else(|| Some(it)).unwrap(); |
63 | let visibility = it.declaration_source(db).and_then(|s| s.ast.visibility()); | 63 | let visibility = it.declaration_source(db).and_then(|s| s.value.visibility()); |
64 | (container, visibility) | 64 | (container, visibility) |
65 | } | 65 | } |
66 | ModuleDef::EnumVariant(it) => { | 66 | ModuleDef::EnumVariant(it) => { |
67 | let container = it.module(db); | 67 | let container = it.module(db); |
68 | let visibility = it.source(db).ast.parent_enum().visibility(); | 68 | let visibility = it.source(db).value.parent_enum().visibility(); |
69 | (container, visibility) | 69 | (container, visibility) |
70 | } | 70 | } |
71 | ModuleDef::Function(it) => (it.module(db), it.source(db).ast.visibility()), | 71 | ModuleDef::Function(it) => (it.module(db), it.source(db).value.visibility()), |
72 | ModuleDef::Const(it) => (it.module(db), it.source(db).ast.visibility()), | 72 | ModuleDef::Const(it) => (it.module(db), it.source(db).value.visibility()), |
73 | ModuleDef::Static(it) => (it.module(db), it.source(db).ast.visibility()), | 73 | ModuleDef::Static(it) => (it.module(db), it.source(db).value.visibility()), |
74 | ModuleDef::Trait(it) => (it.module(db), it.source(db).ast.visibility()), | 74 | ModuleDef::Trait(it) => (it.module(db), it.source(db).value.visibility()), |
75 | ModuleDef::TypeAlias(it) => (it.module(db), it.source(db).ast.visibility()), | 75 | ModuleDef::TypeAlias(it) => (it.module(db), it.source(db).value.visibility()), |
76 | ModuleDef::Adt(Adt::Struct(it)) => (it.module(db), it.source(db).ast.visibility()), | 76 | ModuleDef::Adt(Adt::Struct(it)) => (it.module(db), it.source(db).value.visibility()), |
77 | ModuleDef::Adt(Adt::Union(it)) => (it.module(db), it.source(db).ast.visibility()), | 77 | ModuleDef::Adt(Adt::Union(it)) => (it.module(db), it.source(db).value.visibility()), |
78 | ModuleDef::Adt(Adt::Enum(it)) => (it.module(db), it.source(db).ast.visibility()), | 78 | ModuleDef::Adt(Adt::Enum(it)) => (it.module(db), it.source(db).value.visibility()), |
79 | ModuleDef::BuiltinType(..) => (module.unwrap(), None), | 79 | ModuleDef::BuiltinType(..) => (module.unwrap(), None), |
80 | }; | 80 | }; |
81 | NameDefinition { kind, container, visibility } | 81 | NameDefinition { kind, container, visibility } |
diff --git a/crates/ra_ide_api/src/references/rename.rs b/crates/ra_ide_api/src/references/rename.rs index 11f81cbb3..4ea372e6f 100644 --- a/crates/ra_ide_api/src/references/rename.rs +++ b/crates/ra_ide_api/src/references/rename.rs | |||
@@ -55,11 +55,11 @@ fn rename_mod( | |||
55 | ) -> Option<SourceChange> { | 55 | ) -> Option<SourceChange> { |
56 | let mut source_file_edits = Vec::new(); | 56 | let mut source_file_edits = Vec::new(); |
57 | let mut file_system_edits = Vec::new(); | 57 | let mut file_system_edits = Vec::new(); |
58 | let module_src = hir::Source { file_id: position.file_id.into(), ast: ast_module.clone() }; | 58 | let module_src = hir::Source { file_id: position.file_id.into(), value: ast_module.clone() }; |
59 | if let Some(module) = hir::Module::from_declaration(db, module_src) { | 59 | if let Some(module) = hir::Module::from_declaration(db, module_src) { |
60 | let src = module.definition_source(db); | 60 | let src = module.definition_source(db); |
61 | let file_id = src.file_id.original_file(db); | 61 | let file_id = src.file_id.original_file(db); |
62 | match src.ast { | 62 | match src.value { |
63 | ModuleSource::SourceFile(..) => { | 63 | ModuleSource::SourceFile(..) => { |
64 | let mod_path: RelativePathBuf = db.file_relative_path(file_id); | 64 | let mod_path: RelativePathBuf = db.file_relative_path(file_id); |
65 | // mod is defined in path/to/dir/mod.rs | 65 | // mod is defined in path/to/dir/mod.rs |
diff --git a/crates/ra_ide_api/src/references/search_scope.rs b/crates/ra_ide_api/src/references/search_scope.rs index 2907787c2..f5c9589f4 100644 --- a/crates/ra_ide_api/src/references/search_scope.rs +++ b/crates/ra_ide_api/src/references/search_scope.rs | |||
@@ -73,9 +73,9 @@ impl NameDefinition { | |||
73 | 73 | ||
74 | if let NameKind::Local(var) = self.kind { | 74 | if let NameKind::Local(var) = self.kind { |
75 | let range = match var.parent(db) { | 75 | let range = match var.parent(db) { |
76 | DefWithBody::Function(f) => f.source(db).ast.syntax().text_range(), | 76 | DefWithBody::Function(f) => f.source(db).value.syntax().text_range(), |
77 | DefWithBody::Const(c) => c.source(db).ast.syntax().text_range(), | 77 | DefWithBody::Const(c) => c.source(db).value.syntax().text_range(), |
78 | DefWithBody::Static(s) => s.source(db).ast.syntax().text_range(), | 78 | DefWithBody::Static(s) => s.source(db).value.syntax().text_range(), |
79 | }; | 79 | }; |
80 | let mut res = FxHashMap::default(); | 80 | let mut res = FxHashMap::default(); |
81 | res.insert(file_id, Some(range)); | 81 | res.insert(file_id, Some(range)); |
@@ -91,7 +91,7 @@ impl NameDefinition { | |||
91 | let parent_src = parent_module.definition_source(db); | 91 | let parent_src = parent_module.definition_source(db); |
92 | let file_id = parent_src.file_id.original_file(db); | 92 | let file_id = parent_src.file_id.original_file(db); |
93 | 93 | ||
94 | match parent_src.ast { | 94 | match parent_src.value { |
95 | ModuleSource::Module(m) => { | 95 | ModuleSource::Module(m) => { |
96 | let range = Some(m.syntax().text_range()); | 96 | let range = Some(m.syntax().text_range()); |
97 | res.insert(file_id, range); | 97 | res.insert(file_id, range); |
@@ -135,7 +135,7 @@ impl NameDefinition { | |||
135 | } | 135 | } |
136 | 136 | ||
137 | let mut res = FxHashMap::default(); | 137 | let mut res = FxHashMap::default(); |
138 | let range = match module_src.ast { | 138 | let range = match module_src.value { |
139 | ModuleSource::Module(m) => Some(m.syntax().text_range()), | 139 | ModuleSource::Module(m) => Some(m.syntax().text_range()), |
140 | ModuleSource::SourceFile(_) => None, | 140 | ModuleSource::SourceFile(_) => None, |
141 | }; | 141 | }; |