aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide_api
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ide_api')
-rw-r--r--crates/ra_ide_api/src/change.rs1
-rw-r--r--crates/ra_ide_api/src/completion/complete_scope.rs7
-rw-r--r--crates/ra_ide_api/src/completion/completion_context.rs2
-rw-r--r--crates/ra_ide_api/src/completion/presentation.rs8
-rw-r--r--crates/ra_ide_api/src/diagnostics.rs2
-rw-r--r--crates/ra_ide_api/src/display/function_signature.rs8
-rw-r--r--crates/ra_ide_api/src/display/navigation_target.rs36
-rw-r--r--crates/ra_ide_api/src/expand.rs22
-rw-r--r--crates/ra_ide_api/src/expand_macro.rs16
-rw-r--r--crates/ra_ide_api/src/goto_definition.rs38
-rw-r--r--crates/ra_ide_api/src/goto_type_definition.rs4
-rw-r--r--crates/ra_ide_api/src/hover.rs24
-rw-r--r--crates/ra_ide_api/src/impls.rs8
-rw-r--r--crates/ra_ide_api/src/inlay_hints.rs74
-rw-r--r--crates/ra_ide_api/src/join_lines.rs28
-rw-r--r--crates/ra_ide_api/src/lib.rs10
-rw-r--r--crates/ra_ide_api/src/parent_module.rs5
-rw-r--r--crates/ra_ide_api/src/references/classify.rs40
-rw-r--r--crates/ra_ide_api/src/references/name_definition.rs30
-rw-r--r--crates/ra_ide_api/src/references/rename.rs136
-rw-r--r--crates/ra_ide_api/src/references/search_scope.rs10
21 files changed, 231 insertions, 278 deletions
diff --git a/crates/ra_ide_api/src/change.rs b/crates/ra_ide_api/src/change.rs
index 5c9dec13e..3c607d5b5 100644
--- a/crates/ra_ide_api/src/change.rs
+++ b/crates/ra_ide_api/src/change.rs
@@ -309,7 +309,6 @@ impl RootDatabase {
309 hir::db::StructDataQuery 309 hir::db::StructDataQuery
310 hir::db::EnumDataQuery 310 hir::db::EnumDataQuery
311 hir::db::TraitDataQuery 311 hir::db::TraitDataQuery
312 hir::db::TraitItemsIndexQuery
313 hir::db::RawItemsWithSourceMapQuery 312 hir::db::RawItemsWithSourceMapQuery
314 hir::db::RawItemsQuery 313 hir::db::RawItemsQuery
315 hir::db::CrateDefMapQuery 314 hir::db::CrateDefMapQuery
diff --git a/crates/ra_ide_api/src/completion/complete_scope.rs b/crates/ra_ide_api/src/completion/complete_scope.rs
index 8c57c907d..d5739b58a 100644
--- a/crates/ra_ide_api/src/completion/complete_scope.rs
+++ b/crates/ra_ide_api/src/completion/complete_scope.rs
@@ -305,6 +305,13 @@ mod tests {
305 @r###" 305 @r###"
306 [ 306 [
307 CompletionItem { 307 CompletionItem {
308 label: "Self",
309 source_range: [54; 54),
310 delete: [54; 54),
311 insert: "Self",
312 kind: TypeParam,
313 },
314 CompletionItem {
308 label: "T", 315 label: "T",
309 source_range: [54; 54), 316 source_range: [54; 54),
310 delete: [54; 54), 317 delete: [54; 54),
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..6ac60722b 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_value(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,9 +230,9 @@ 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_value(node.syntax()));
236 236
237 NavigationTarget::from_syntax( 237 NavigationTarget::from_syntax(
238 frange.file_id, 238 frange.file_id,
@@ -245,7 +245,7 @@ impl ToNav for hir::Module {
245 ) 245 )
246 } 246 }
247 ModuleSource::Module(node) => { 247 ModuleSource::Module(node) => {
248 let frange = original_range(db, src.with_ast(node.syntax())); 248 let frange = original_range(db, src.with_value(node.syntax()));
249 249
250 NavigationTarget::from_syntax( 250 NavigationTarget::from_syntax(
251 frange.file_id, 251 frange.file_id,
@@ -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,15 +282,15 @@ 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_value(it),
289 it.doc_comment_text(), 289 it.doc_comment_text(),
290 it.short_label(), 290 it.short_label(),
291 ), 291 ),
292 FieldSource::Pos(it) => { 292 FieldSource::Pos(it) => {
293 let frange = original_range(db, src.with_ast(it.syntax())); 293 let frange = original_range(db, src.with_value(it.syntax()));
294 NavigationTarget::from_syntax( 294 NavigationTarget::from_syntax(
295 frange.file_id, 295 frange.file_id,
296 "".into(), 296 "".into(),
@@ -308,11 +308,11 @@ impl ToNav for hir::StructField {
308impl ToNav for hir::MacroDef { 308impl 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 {
341impl ToNav for hir::Local { 341impl 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..2f1abf509 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_value(&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,14 +48,14 @@ 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_value(token.value.parent()).as_ref(), None);
54 let exp = source_analyzer.expand(db, &macro_call)?; 58 let exp = source_analyzer.expand(db, token.with_value(&macro_call))?;
55 exp.map_token_down(db, token.as_ref()) 59 exp.map_token_down(db, token.as_ref())
56 }) 60 })
57 .last() 61 .last()
diff --git a/crates/ra_ide_api/src/expand_macro.rs b/crates/ra_ide_api/src/expand_macro.rs
index e9eb2a7fb..7f39262dc 100644
--- a/crates/ra_ide_api/src/expand_macro.rs
+++ b/crates/ra_ide_api/src/expand_macro.rs
@@ -23,7 +23,7 @@ pub(crate) fn expand_macro(db: &RootDatabase, position: FilePosition) -> Option<
23 let mac = name_ref.syntax().ancestors().find_map(ast::MacroCall::cast)?; 23 let mac = name_ref.syntax().ancestors().find_map(ast::MacroCall::cast)?;
24 24
25 let source = hir::Source::new(position.file_id.into(), mac.syntax()); 25 let source = hir::Source::new(position.file_id.into(), mac.syntax());
26 let expanded = expand_macro_recur(db, source, &mac)?; 26 let expanded = expand_macro_recur(db, source, source.with_value(&mac))?;
27 27
28 // FIXME: 28 // FIXME:
29 // macro expansion may lose all white space information 29 // macro expansion may lose all white space information
@@ -35,10 +35,10 @@ pub(crate) fn expand_macro(db: &RootDatabase, position: FilePosition) -> Option<
35fn expand_macro_recur( 35fn expand_macro_recur(
36 db: &RootDatabase, 36 db: &RootDatabase,
37 source: hir::Source<&SyntaxNode>, 37 source: hir::Source<&SyntaxNode>,
38 macro_call: &ast::MacroCall, 38 macro_call: hir::Source<&ast::MacroCall>,
39) -> Option<SyntaxNode> { 39) -> Option<SyntaxNode> {
40 let analyzer = hir::SourceAnalyzer::new(db, source, None); 40 let analyzer = hir::SourceAnalyzer::new(db, source, None);
41 let expansion = analyzer.expand(db, &macro_call)?; 41 let expansion = analyzer.expand(db, macro_call)?;
42 let macro_file_id = expansion.file_id(); 42 let macro_file_id = expansion.file_id();
43 let expanded: SyntaxNode = db.parse_or_expand(macro_file_id)?; 43 let expanded: SyntaxNode = db.parse_or_expand(macro_file_id)?;
44 44
@@ -46,8 +46,8 @@ 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 node = hir::Source::new(macro_file_id, &child);
50 let new_node = expand_macro_recur(db, source, &child)?; 50 let new_node = expand_macro_recur(db, source, node)?;
51 51
52 replaces.insert(child.syntax().clone().into(), new_node.into()); 52 replaces.insert(child.syntax().clone().into(), new_node.into());
53 } 53 }
@@ -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(){}
172fn some_thing() -> u32 { 172fn 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..b6c72efdf 100644
--- a/crates/ra_ide_api/src/goto_definition.rs
+++ b/crates/ra_ide_api/src/goto_definition.rs
@@ -23,13 +23,13 @@ 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_value(&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())
30 }, 30 },
31 ast::Name(name) => { 31 ast::Name(name) => {
32 let navs = name_definition(db, token.with_ast(&name))?; 32 let navs = name_definition(db, token.with_value(&name))?;
33 RangeInfo::new(name.syntax().text_range(), navs) 33 RangeInfo::new(name.syntax().text_range(), navs)
34 34
35 }, 35 },
@@ -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,11 +95,11 @@ 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() {
102 let src = name.with_ast(module); 102 let src = name.with_value(module);
103 if let Some(child_module) = hir::Module::from_declaration(db, src) { 103 if let Some(child_module) = hir::Module::from_declaration(db, src) {
104 let nav = child_module.to_nav(db); 104 let nav = child_module.to_nav(db);
105 return Some(vec![nav]); 105 return Some(vec![nav]);
@@ -107,7 +107,7 @@ pub(crate) fn name_definition(
107 } 107 }
108 } 108 }
109 109
110 if let Some(nav) = named_target(db, name.with_ast(&parent)) { 110 if let Some(nav) = named_target(db, name.with_value(&parent)) {
111 return Some(vec![nav]); 111 return Some(vec![nav]);
112 } 112 }
113 113
@@ -116,11 +116,11 @@ pub(crate) fn name_definition(
116 116
117fn named_target(db: &RootDatabase, node: Source<&SyntaxNode>) -> Option<NavigationTarget> { 117fn 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,
123 node.with_ast(&it), 123 node.with_value(&it),
124 it.doc_comment_text(), 124 it.doc_comment_text(),
125 it.short_label(), 125 it.short_label(),
126 )) 126 ))
@@ -128,7 +128,7 @@ fn named_target(db: &RootDatabase, node: Source<&SyntaxNode>) -> Option<Navigati
128 ast::EnumDef(it) => { 128 ast::EnumDef(it) => {
129 Some(NavigationTarget::from_named( 129 Some(NavigationTarget::from_named(
130 db, 130 db,
131 node.with_ast(&it), 131 node.with_value(&it),
132 it.doc_comment_text(), 132 it.doc_comment_text(),
133 it.short_label(), 133 it.short_label(),
134 )) 134 ))
@@ -136,7 +136,7 @@ fn named_target(db: &RootDatabase, node: Source<&SyntaxNode>) -> Option<Navigati
136 ast::EnumVariant(it) => { 136 ast::EnumVariant(it) => {
137 Some(NavigationTarget::from_named( 137 Some(NavigationTarget::from_named(
138 db, 138 db,
139 node.with_ast(&it), 139 node.with_value(&it),
140 it.doc_comment_text(), 140 it.doc_comment_text(),
141 it.short_label(), 141 it.short_label(),
142 )) 142 ))
@@ -144,7 +144,7 @@ fn named_target(db: &RootDatabase, node: Source<&SyntaxNode>) -> Option<Navigati
144 ast::FnDef(it) => { 144 ast::FnDef(it) => {
145 Some(NavigationTarget::from_named( 145 Some(NavigationTarget::from_named(
146 db, 146 db,
147 node.with_ast(&it), 147 node.with_value(&it),
148 it.doc_comment_text(), 148 it.doc_comment_text(),
149 it.short_label(), 149 it.short_label(),
150 )) 150 ))
@@ -152,7 +152,7 @@ fn named_target(db: &RootDatabase, node: Source<&SyntaxNode>) -> Option<Navigati
152 ast::TypeAliasDef(it) => { 152 ast::TypeAliasDef(it) => {
153 Some(NavigationTarget::from_named( 153 Some(NavigationTarget::from_named(
154 db, 154 db,
155 node.with_ast(&it), 155 node.with_value(&it),
156 it.doc_comment_text(), 156 it.doc_comment_text(),
157 it.short_label(), 157 it.short_label(),
158 )) 158 ))
@@ -160,7 +160,7 @@ fn named_target(db: &RootDatabase, node: Source<&SyntaxNode>) -> Option<Navigati
160 ast::ConstDef(it) => { 160 ast::ConstDef(it) => {
161 Some(NavigationTarget::from_named( 161 Some(NavigationTarget::from_named(
162 db, 162 db,
163 node.with_ast(&it), 163 node.with_value(&it),
164 it.doc_comment_text(), 164 it.doc_comment_text(),
165 it.short_label(), 165 it.short_label(),
166 )) 166 ))
@@ -168,7 +168,7 @@ fn named_target(db: &RootDatabase, node: Source<&SyntaxNode>) -> Option<Navigati
168 ast::StaticDef(it) => { 168 ast::StaticDef(it) => {
169 Some(NavigationTarget::from_named( 169 Some(NavigationTarget::from_named(
170 db, 170 db,
171 node.with_ast(&it), 171 node.with_value(&it),
172 it.doc_comment_text(), 172 it.doc_comment_text(),
173 it.short_label(), 173 it.short_label(),
174 )) 174 ))
@@ -176,7 +176,7 @@ fn named_target(db: &RootDatabase, node: Source<&SyntaxNode>) -> Option<Navigati
176 ast::TraitDef(it) => { 176 ast::TraitDef(it) => {
177 Some(NavigationTarget::from_named( 177 Some(NavigationTarget::from_named(
178 db, 178 db,
179 node.with_ast(&it), 179 node.with_value(&it),
180 it.doc_comment_text(), 180 it.doc_comment_text(),
181 it.short_label(), 181 it.short_label(),
182 )) 182 ))
@@ -184,7 +184,7 @@ fn named_target(db: &RootDatabase, node: Source<&SyntaxNode>) -> Option<Navigati
184 ast::RecordFieldDef(it) => { 184 ast::RecordFieldDef(it) => {
185 Some(NavigationTarget::from_named( 185 Some(NavigationTarget::from_named(
186 db, 186 db,
187 node.with_ast(&it), 187 node.with_value(&it),
188 it.doc_comment_text(), 188 it.doc_comment_text(),
189 it.short_label(), 189 it.short_label(),
190 )) 190 ))
@@ -192,7 +192,7 @@ fn named_target(db: &RootDatabase, node: Source<&SyntaxNode>) -> Option<Navigati
192 ast::Module(it) => { 192 ast::Module(it) => {
193 Some(NavigationTarget::from_named( 193 Some(NavigationTarget::from_named(
194 db, 194 db,
195 node.with_ast(&it), 195 node.with_value(&it),
196 it.doc_comment_text(), 196 it.doc_comment_text(),
197 it.short_label(), 197 it.short_label(),
198 )) 198 ))
@@ -200,7 +200,7 @@ fn named_target(db: &RootDatabase, node: Source<&SyntaxNode>) -> Option<Navigati
200 ast::MacroCall(it) => { 200 ast::MacroCall(it) => {
201 Some(NavigationTarget::from_named( 201 Some(NavigationTarget::from_named(
202 db, 202 db,
203 node.with_ast(&it), 203 node.with_value(&it),
204 it.doc_comment_text(), 204 it.doc_comment_text(),
205 None, 205 None,
206 )) 206 ))
diff --git a/crates/ra_ide_api/src/goto_type_definition.rs b/crates/ra_ide_api/src/goto_type_definition.rs
index 7d694e1f6..28a83a3e2 100644
--- a/crates/ra_ide_api/src/goto_type_definition.rs
+++ b/crates/ra_ide_api/src/goto_type_definition.rs
@@ -16,13 +16,13 @@ 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())
23 })?; 23 })?;
24 24
25 let analyzer = hir::SourceAnalyzer::new(db, token.with_ast(&node), None); 25 let analyzer = hir::SourceAnalyzer::new(db, token.with_value(&node), None);
26 26
27 let ty: hir::Ty = if let Some(ty) = 27 let ty: hir::Ty = if let Some(ty) =
28 ast::Expr::cast(node.clone()).and_then(|e| analyzer.type_of(db, &e)) 28 ast::Expr::cast(node.clone()).and_then(|e| analyzer.type_of(db, &e))
diff --git a/crates/ra_ide_api/src/hover.rs b/crates/ra_ide_api/src/hover.rs
index 787b714b3..9839be985 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,11 +170,11 @@ 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) =
177 classify_name_ref(db, token.with_ast(&name_ref)).map(|d| d.kind) 177 classify_name_ref(db, token.with_value(&name_ref)).map(|d| d.kind)
178 { 178 {
179 res.extend(hover_text_from_name_kind(db, name_kind, &mut no_fallback)) 179 res.extend(hover_text_from_name_kind(db, name_kind, &mut no_fallback))
180 } 180 }
@@ -196,7 +196,7 @@ pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option<RangeIn
196 } 196 }
197 }, 197 },
198 ast::Name(name) => { 198 ast::Name(name) => {
199 if let Some(name_kind) = classify_name(db, token.with_ast(&name)).map(|d| d.kind) { 199 if let Some(name_kind) = classify_name(db, token.with_value(&name)).map(|d| d.kind) {
200 res.extend(hover_text_from_name_kind(db, name_kind, &mut true)); 200 res.extend(hover_text_from_name_kind(db, name_kind, &mut true));
201 } 201 }
202 202
@@ -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() };
@@ -404,9 +404,7 @@ mod tests {
404 check_hover_result( 404 check_hover_result(
405 r#" 405 r#"
406 //- /main.rs 406 //- /main.rs
407 fn main() { 407 const foo<|>: u32 = 0;
408 const foo<|>: u32 = 0;
409 }
410 "#, 408 "#,
411 &["const foo: u32"], 409 &["const foo: u32"],
412 ); 410 );
@@ -414,9 +412,7 @@ mod tests {
414 check_hover_result( 412 check_hover_result(
415 r#" 413 r#"
416 //- /main.rs 414 //- /main.rs
417 fn main() { 415 static foo<|>: u32 = 0;
418 static foo<|>: u32 = 0;
419 }
420 "#, 416 "#,
421 &["static foo: u32"], 417 &["static foo: u32"],
422 ); 418 );
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/inlay_hints.rs b/crates/ra_ide_api/src/inlay_hints.rs
index 0cd959848..24a7ca5e7 100644
--- a/crates/ra_ide_api/src/inlay_hints.rs
+++ b/crates/ra_ide_api/src/inlay_hints.rs
@@ -19,10 +19,15 @@ pub struct InlayHint {
19 pub label: SmolStr, 19 pub label: SmolStr,
20} 20}
21 21
22pub(crate) fn inlay_hints(db: &RootDatabase, file_id: FileId, file: &SourceFile) -> Vec<InlayHint> { 22pub(crate) fn inlay_hints(
23 db: &RootDatabase,
24 file_id: FileId,
25 file: &SourceFile,
26 max_inlay_hint_length: Option<usize>,
27) -> Vec<InlayHint> {
23 file.syntax() 28 file.syntax()
24 .descendants() 29 .descendants()
25 .map(|node| get_inlay_hints(db, file_id, &node).unwrap_or_default()) 30 .map(|node| get_inlay_hints(db, file_id, &node, max_inlay_hint_length).unwrap_or_default())
26 .flatten() 31 .flatten()
27 .collect() 32 .collect()
28} 33}
@@ -31,6 +36,7 @@ fn get_inlay_hints(
31 db: &RootDatabase, 36 db: &RootDatabase,
32 file_id: FileId, 37 file_id: FileId,
33 node: &SyntaxNode, 38 node: &SyntaxNode,
39 max_inlay_hint_length: Option<usize>,
34) -> Option<Vec<InlayHint>> { 40) -> Option<Vec<InlayHint>> {
35 let analyzer = SourceAnalyzer::new(db, hir::Source::new(file_id.into(), node), None); 41 let analyzer = SourceAnalyzer::new(db, hir::Source::new(file_id.into(), node), None);
36 match_ast! { 42 match_ast! {
@@ -40,7 +46,7 @@ fn get_inlay_hints(
40 return None; 46 return None;
41 } 47 }
42 let pat = it.pat()?; 48 let pat = it.pat()?;
43 Some(get_pat_type_hints(db, &analyzer, pat, false)) 49 Some(get_pat_type_hints(db, &analyzer, pat, false, max_inlay_hint_length))
44 }, 50 },
45 ast::LambdaExpr(it) => { 51 ast::LambdaExpr(it) => {
46 it.param_list().map(|param_list| { 52 it.param_list().map(|param_list| {
@@ -48,22 +54,22 @@ fn get_inlay_hints(
48 .params() 54 .params()
49 .filter(|closure_param| closure_param.ascribed_type().is_none()) 55 .filter(|closure_param| closure_param.ascribed_type().is_none())
50 .filter_map(|closure_param| closure_param.pat()) 56 .filter_map(|closure_param| closure_param.pat())
51 .map(|root_pat| get_pat_type_hints(db, &analyzer, root_pat, false)) 57 .map(|root_pat| get_pat_type_hints(db, &analyzer, root_pat, false, max_inlay_hint_length))
52 .flatten() 58 .flatten()
53 .collect() 59 .collect()
54 }) 60 })
55 }, 61 },
56 ast::ForExpr(it) => { 62 ast::ForExpr(it) => {
57 let pat = it.pat()?; 63 let pat = it.pat()?;
58 Some(get_pat_type_hints(db, &analyzer, pat, false)) 64 Some(get_pat_type_hints(db, &analyzer, pat, false, max_inlay_hint_length))
59 }, 65 },
60 ast::IfExpr(it) => { 66 ast::IfExpr(it) => {
61 let pat = it.condition()?.pat()?; 67 let pat = it.condition()?.pat()?;
62 Some(get_pat_type_hints(db, &analyzer, pat, true)) 68 Some(get_pat_type_hints(db, &analyzer, pat, true, max_inlay_hint_length))
63 }, 69 },
64 ast::WhileExpr(it) => { 70 ast::WhileExpr(it) => {
65 let pat = it.condition()?.pat()?; 71 let pat = it.condition()?.pat()?;
66 Some(get_pat_type_hints(db, &analyzer, pat, true)) 72 Some(get_pat_type_hints(db, &analyzer, pat, true, max_inlay_hint_length))
67 }, 73 },
68 ast::MatchArmList(it) => { 74 ast::MatchArmList(it) => {
69 Some( 75 Some(
@@ -71,7 +77,7 @@ fn get_inlay_hints(
71 .arms() 77 .arms()
72 .map(|match_arm| match_arm.pats()) 78 .map(|match_arm| match_arm.pats())
73 .flatten() 79 .flatten()
74 .map(|root_pat| get_pat_type_hints(db, &analyzer, root_pat, true)) 80 .map(|root_pat| get_pat_type_hints(db, &analyzer, root_pat, true, max_inlay_hint_length))
75 .flatten() 81 .flatten()
76 .collect(), 82 .collect(),
77 ) 83 )
@@ -86,6 +92,7 @@ fn get_pat_type_hints(
86 analyzer: &SourceAnalyzer, 92 analyzer: &SourceAnalyzer,
87 root_pat: ast::Pat, 93 root_pat: ast::Pat,
88 skip_root_pat_hint: bool, 94 skip_root_pat_hint: bool,
95 max_inlay_hint_length: Option<usize>,
89) -> Vec<InlayHint> { 96) -> Vec<InlayHint> {
90 let original_pat = &root_pat.clone(); 97 let original_pat = &root_pat.clone();
91 98
@@ -99,7 +106,7 @@ fn get_pat_type_hints(
99 .map(|(range, pat_type)| InlayHint { 106 .map(|(range, pat_type)| InlayHint {
100 range, 107 range,
101 kind: InlayKind::TypeHint, 108 kind: InlayKind::TypeHint,
102 label: pat_type.display(db).to_string().into(), 109 label: pat_type.display_truncated(db, max_inlay_hint_length).to_string().into(),
103 }) 110 })
104 .collect() 111 .collect()
105} 112}
@@ -209,7 +216,7 @@ fn main() {
209}"#, 216}"#,
210 ); 217 );
211 218
212 assert_debug_snapshot!(analysis.inlay_hints(file_id).unwrap(), @r###" 219 assert_debug_snapshot!(analysis.inlay_hints(file_id, None).unwrap(), @r###"
213 [ 220 [
214 InlayHint { 221 InlayHint {
215 range: [193; 197), 222 range: [193; 197),
@@ -278,7 +285,7 @@ fn main() {
278}"#, 285}"#,
279 ); 286 );
280 287
281 assert_debug_snapshot!(analysis.inlay_hints(file_id).unwrap(), @r###" 288 assert_debug_snapshot!(analysis.inlay_hints(file_id, None).unwrap(), @r###"
282 [ 289 [
283 InlayHint { 290 InlayHint {
284 range: [21; 30), 291 range: [21; 30),
@@ -307,7 +314,7 @@ fn main() {
307}"#, 314}"#,
308 ); 315 );
309 316
310 assert_debug_snapshot!(analysis.inlay_hints(file_id).unwrap(), @r###" 317 assert_debug_snapshot!(analysis.inlay_hints(file_id, None).unwrap(), @r###"
311 [ 318 [
312 InlayHint { 319 InlayHint {
313 range: [21; 30), 320 range: [21; 30),
@@ -355,7 +362,7 @@ fn main() {
355}"#, 362}"#,
356 ); 363 );
357 364
358 assert_debug_snapshot!(analysis.inlay_hints(file_id).unwrap(), @r###" 365 assert_debug_snapshot!(analysis.inlay_hints(file_id, None).unwrap(), @r###"
359 [ 366 [
360 InlayHint { 367 InlayHint {
361 range: [166; 170), 368 range: [166; 170),
@@ -418,7 +425,7 @@ fn main() {
418}"#, 425}"#,
419 ); 426 );
420 427
421 assert_debug_snapshot!(analysis.inlay_hints(file_id).unwrap(), @r###" 428 assert_debug_snapshot!(analysis.inlay_hints(file_id, None).unwrap(), @r###"
422 [ 429 [
423 InlayHint { 430 InlayHint {
424 range: [166; 170), 431 range: [166; 170),
@@ -481,7 +488,7 @@ fn main() {
481}"#, 488}"#,
482 ); 489 );
483 490
484 assert_debug_snapshot!(analysis.inlay_hints(file_id).unwrap(), @r###" 491 assert_debug_snapshot!(analysis.inlay_hints(file_id, None).unwrap(), @r###"
485 [ 492 [
486 InlayHint { 493 InlayHint {
487 range: [311; 315), 494 range: [311; 315),
@@ -507,4 +514,41 @@ fn main() {
507 "### 514 "###
508 ); 515 );
509 } 516 }
517
518 #[test]
519 fn hint_truncation() {
520 let (analysis, file_id) = single_file(
521 r#"
522struct Smol<T>(T);
523
524struct VeryLongOuterName<T>(T);
525
526fn main() {
527 let a = Smol(0u32);
528 let b = VeryLongOuterName(0usize);
529 let c = Smol(Smol(0u32))
530}"#,
531 );
532
533 assert_debug_snapshot!(analysis.inlay_hints(file_id, Some(8)).unwrap(), @r###"
534 [
535 InlayHint {
536 range: [74; 75),
537 kind: TypeHint,
538 label: "Smol<u32>",
539 },
540 InlayHint {
541 range: [98; 99),
542 kind: TypeHint,
543 label: "VeryLongOuterName<…>",
544 },
545 InlayHint {
546 range: [137; 138),
547 kind: TypeHint,
548 label: "Smol<Smol<…>>",
549 },
550 ]
551 "###
552 );
553 }
510} 554}
diff --git a/crates/ra_ide_api/src/join_lines.rs b/crates/ra_ide_api/src/join_lines.rs
index 6f71b27db..7deeb3494 100644
--- a/crates/ra_ide_api/src/join_lines.rs
+++ b/crates/ra_ide_api/src/join_lines.rs
@@ -244,6 +244,34 @@ fn foo(e: Result<U, V>) {
244 } 244 }
245 245
246 #[test] 246 #[test]
247 fn join_lines_multiline_in_block() {
248 check_join_lines(
249 r"
250fn foo() {
251 match ty {
252 <|> Some(ty) => {
253 match ty {
254 _ => false,
255 }
256 }
257 _ => true,
258 }
259}
260",
261 r"
262fn foo() {
263 match ty {
264 <|> Some(ty) => match ty {
265 _ => false,
266 },
267 _ => true,
268 }
269}
270",
271 );
272 }
273
274 #[test]
247 fn join_lines_keeps_comma_for_block_in_match_arm() { 275 fn join_lines_keeps_comma_for_block_in_match_arm() {
248 // We already have a comma 276 // We already have a comma
249 check_join_lines( 277 check_join_lines(
diff --git a/crates/ra_ide_api/src/lib.rs b/crates/ra_ide_api/src/lib.rs
index 57ed97147..62ad996bc 100644
--- a/crates/ra_ide_api/src/lib.rs
+++ b/crates/ra_ide_api/src/lib.rs
@@ -344,8 +344,14 @@ impl Analysis {
344 } 344 }
345 345
346 /// Returns a list of the places in the file where type hints can be displayed. 346 /// Returns a list of the places in the file where type hints can be displayed.
347 pub fn inlay_hints(&self, file_id: FileId) -> Cancelable<Vec<InlayHint>> { 347 pub fn inlay_hints(
348 self.with_db(|db| inlay_hints::inlay_hints(db, file_id, &db.parse(file_id).tree())) 348 &self,
349 file_id: FileId,
350 max_inlay_hint_length: Option<usize>,
351 ) -> Cancelable<Vec<InlayHint>> {
352 self.with_db(|db| {
353 inlay_hints::inlay_hints(db, file_id, &db.parse(file_id).tree(), max_inlay_hint_length)
354 })
349 } 355 }
350 356
351 /// Returns the set of folding ranges. 357 /// Returns the set of folding ranges.
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
23pub(crate) fn crate_for(db: &RootDatabase, file_id: FileId) -> Vec<CrateId> { 23pub(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..4a4b030f8 100644
--- a/crates/ra_ide_api/src/references/classify.rs
+++ b/crates/ra_ide_api/src/references/classify.rs
@@ -13,12 +13,12 @@ use crate::db::RootDatabase;
13 13
14pub(crate) fn classify_name(db: &RootDatabase, name: Source<&ast::Name>) -> Option<NameDefinition> { 14pub(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 {
20 ast::BindPat(it) => { 20 ast::BindPat(it) => {
21 let src = name.with_ast(it); 21 let src = name.with_value(it);
22 let local = hir::Local::from_source(db, src)?; 22 let local = hir::Local::from_source(db, src)?;
23 Some(NameDefinition { 23 Some(NameDefinition {
24 visibility: None, 24 visibility: None,
@@ -28,7 +28,7 @@ pub(crate) fn classify_name(db: &RootDatabase, name: Source<&ast::Name>) -> Opti
28 }, 28 },
29 ast::RecordFieldDef(it) => { 29 ast::RecordFieldDef(it) => {
30 let ast = hir::FieldSource::Named(it); 30 let ast = hir::FieldSource::Named(it);
31 let src = name.with_ast(ast); 31 let src = name.with_value(ast);
32 let field = hir::StructField::from_source(db, src)?; 32 let field = hir::StructField::from_source(db, src)?;
33 Some(from_struct_field(db, field)) 33 Some(from_struct_field(db, field))
34 }, 34 },
@@ -36,42 +36,42 @@ pub(crate) fn classify_name(db: &RootDatabase, name: Source<&ast::Name>) -> Opti
36 let def = { 36 let def = {
37 if !it.has_semi() { 37 if !it.has_semi() {
38 let ast = hir::ModuleSource::Module(it); 38 let ast = hir::ModuleSource::Module(it);
39 let src = name.with_ast(ast); 39 let src = name.with_value(ast);
40 hir::Module::from_definition(db, src) 40 hir::Module::from_definition(db, src)
41 } else { 41 } else {
42 let src = name.with_ast(it); 42 let src = name.with_value(it);
43 hir::Module::from_declaration(db, src) 43 hir::Module::from_declaration(db, src)
44 } 44 }
45 }?; 45 }?;
46 Some(from_module_def(db, def.into(), None)) 46 Some(from_module_def(db, def.into(), None))
47 }, 47 },
48 ast::StructDef(it) => { 48 ast::StructDef(it) => {
49 let src = name.with_ast(it); 49 let src = name.with_value(it);
50 let def = hir::Struct::from_source(db, src)?; 50 let def = hir::Struct::from_source(db, src)?;
51 Some(from_module_def(db, def.into(), None)) 51 Some(from_module_def(db, def.into(), None))
52 }, 52 },
53 ast::EnumDef(it) => { 53 ast::EnumDef(it) => {
54 let src = name.with_ast(it); 54 let src = name.with_value(it);
55 let def = hir::Enum::from_source(db, src)?; 55 let def = hir::Enum::from_source(db, src)?;
56 Some(from_module_def(db, def.into(), None)) 56 Some(from_module_def(db, def.into(), None))
57 }, 57 },
58 ast::TraitDef(it) => { 58 ast::TraitDef(it) => {
59 let src = name.with_ast(it); 59 let src = name.with_value(it);
60 let def = hir::Trait::from_source(db, src)?; 60 let def = hir::Trait::from_source(db, src)?;
61 Some(from_module_def(db, def.into(), None)) 61 Some(from_module_def(db, def.into(), None))
62 }, 62 },
63 ast::StaticDef(it) => { 63 ast::StaticDef(it) => {
64 let src = name.with_ast(it); 64 let src = name.with_value(it);
65 let def = hir::Static::from_source(db, src)?; 65 let def = hir::Static::from_source(db, src)?;
66 Some(from_module_def(db, def.into(), None)) 66 Some(from_module_def(db, def.into(), None))
67 }, 67 },
68 ast::EnumVariant(it) => { 68 ast::EnumVariant(it) => {
69 let src = name.with_ast(it); 69 let src = name.with_value(it);
70 let def = hir::EnumVariant::from_source(db, src)?; 70 let def = hir::EnumVariant::from_source(db, src)?;
71 Some(from_module_def(db, def.into(), None)) 71 Some(from_module_def(db, def.into(), None))
72 }, 72 },
73 ast::FnDef(it) => { 73 ast::FnDef(it) => {
74 let src = name.with_ast(it); 74 let src = name.with_value(it);
75 let def = hir::Function::from_source(db, src)?; 75 let def = hir::Function::from_source(db, src)?;
76 if parent.parent().and_then(ast::ItemList::cast).is_some() { 76 if parent.parent().and_then(ast::ItemList::cast).is_some() {
77 Some(from_assoc_item(db, def.into())) 77 Some(from_assoc_item(db, def.into()))
@@ -80,7 +80,7 @@ pub(crate) fn classify_name(db: &RootDatabase, name: Source<&ast::Name>) -> Opti
80 } 80 }
81 }, 81 },
82 ast::ConstDef(it) => { 82 ast::ConstDef(it) => {
83 let src = name.with_ast(it); 83 let src = name.with_value(it);
84 let def = hir::Const::from_source(db, src)?; 84 let def = hir::Const::from_source(db, src)?;
85 if parent.parent().and_then(ast::ItemList::cast).is_some() { 85 if parent.parent().and_then(ast::ItemList::cast).is_some() {
86 Some(from_assoc_item(db, def.into())) 86 Some(from_assoc_item(db, def.into()))
@@ -89,7 +89,7 @@ pub(crate) fn classify_name(db: &RootDatabase, name: Source<&ast::Name>) -> Opti
89 } 89 }
90 }, 90 },
91 ast::TypeAliasDef(it) => { 91 ast::TypeAliasDef(it) => {
92 let src = name.with_ast(it); 92 let src = name.with_value(it);
93 let def = hir::TypeAlias::from_source(db, src)?; 93 let def = hir::TypeAlias::from_source(db, src)?;
94 if parent.parent().and_then(ast::ItemList::cast).is_some() { 94 if parent.parent().and_then(ast::ItemList::cast).is_some() {
95 Some(from_assoc_item(db, def.into())) 95 Some(from_assoc_item(db, def.into()))
@@ -98,11 +98,11 @@ pub(crate) fn classify_name(db: &RootDatabase, name: Source<&ast::Name>) -> Opti
98 } 98 }
99 }, 99 },
100 ast::MacroCall(it) => { 100 ast::MacroCall(it) => {
101 let src = name.with_ast(it); 101 let src = name.with_value(it);
102 let def = hir::MacroDef::from_source(db, src.clone())?; 102 let def = hir::MacroDef::from_source(db, src.clone())?;
103 103
104 let module_src = ModuleSource::from_child_node(db, src.as_ref().map(|it| it.syntax())); 104 let module_src = ModuleSource::from_child_node(db, src.as_ref().map(|it| it.syntax()));
105 let module = Module::from_definition(db, src.with_ast(module_src))?; 105 let module = Module::from_definition(db, src.with_value(module_src))?;
106 106
107 Some(NameDefinition { 107 Some(NameDefinition {
108 visibility: None, 108 visibility: None,
@@ -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,16 +142,16 @@ 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));
149 } 149 }
150 } 150 }
151 151
152 let ast = ModuleSource::from_child_node(db, name_ref.with_ast(&parent)); 152 let ast = ModuleSource::from_child_node(db, name_ref.with_value(&parent));
153 // FIXME: find correct container and visibility for each case 153 // FIXME: find correct container and visibility for each case
154 let container = Module::from_definition(db, name_ref.with_ast(ast))?; 154 let container = Module::from_definition(db, name_ref.with_value(ast))?;
155 let visibility = None; 155 let visibility = None;
156 156
157 if let Some(macro_call) = parent.ancestors().find_map(ast::MacroCall::cast) { 157 if let Some(macro_call) = parent.ancestors().find_map(ast::MacroCall::cast) {
@@ -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 {
32pub(super) fn from_assoc_item(db: &RootDatabase, item: AssocItem) -> NameDefinition { 32pub(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..d58496049 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
@@ -121,141 +121,9 @@ mod tests {
121 121
122 use crate::{ 122 use crate::{
123 mock_analysis::analysis_and_position, mock_analysis::single_file_with_position, FileId, 123 mock_analysis::analysis_and_position, mock_analysis::single_file_with_position, FileId,
124 ReferenceSearchResult,
125 }; 124 };
126 125
127 #[test] 126 #[test]
128 fn test_find_all_refs_for_local() {
129 let code = r#"
130 fn main() {
131 let mut i = 1;
132 let j = 1;
133 i = i<|> + j;
134
135 {
136 i = 0;
137 }
138
139 i = 5;
140 }"#;
141
142 let refs = get_all_refs(code);
143 assert_eq!(refs.len(), 5);
144 }
145
146 #[test]
147 fn test_find_all_refs_for_param_inside() {
148 let code = r#"
149 fn foo(i : u32) -> u32 {
150 i<|>
151 }"#;
152
153 let refs = get_all_refs(code);
154 assert_eq!(refs.len(), 2);
155 }
156
157 #[test]
158 fn test_find_all_refs_for_fn_param() {
159 let code = r#"
160 fn foo(i<|> : u32) -> u32 {
161 i
162 }"#;
163
164 let refs = get_all_refs(code);
165 assert_eq!(refs.len(), 2);
166 }
167
168 #[test]
169 fn test_find_all_refs_field_name() {
170 let code = r#"
171 //- /lib.rs
172 struct Foo {
173 pub spam<|>: u32,
174 }
175
176 fn main(s: Foo) {
177 let f = s.spam;
178 }
179 "#;
180
181 let refs = get_all_refs(code);
182 assert_eq!(refs.len(), 2);
183 }
184
185 #[test]
186 fn test_find_all_refs_impl_item_name() {
187 let code = r#"
188 //- /lib.rs
189 struct Foo;
190 impl Foo {
191 fn f<|>(&self) { }
192 }
193 "#;
194
195 let refs = get_all_refs(code);
196 assert_eq!(refs.len(), 1);
197 }
198
199 #[test]
200 fn test_find_all_refs_enum_var_name() {
201 let code = r#"
202 //- /lib.rs
203 enum Foo {
204 A,
205 B<|>,
206 C,
207 }
208 "#;
209
210 let refs = get_all_refs(code);
211 assert_eq!(refs.len(), 1);
212 }
213
214 #[test]
215 fn test_find_all_refs_modules() {
216 let code = r#"
217 //- /lib.rs
218 pub mod foo;
219 pub mod bar;
220
221 fn f() {
222 let i = foo::Foo { n: 5 };
223 }
224
225 //- /foo.rs
226 use crate::bar;
227
228 pub struct Foo {
229 pub n: u32,
230 }
231
232 fn f() {
233 let i = bar::Bar { n: 5 };
234 }
235
236 //- /bar.rs
237 use crate::foo;
238
239 pub struct Bar {
240 pub n: u32,
241 }
242
243 fn f() {
244 let i = foo::Foo<|> { n: 5 };
245 }
246 "#;
247
248 let (analysis, pos) = analysis_and_position(code);
249 let refs = analysis.find_all_refs(pos, None).unwrap().unwrap();
250 assert_eq!(refs.len(), 3);
251 }
252
253 fn get_all_refs(text: &str) -> ReferenceSearchResult {
254 let (analysis, position) = single_file_with_position(text);
255 analysis.find_all_refs(position, None).unwrap().unwrap()
256 }
257
258 #[test]
259 fn test_rename_for_local() { 127 fn test_rename_for_local() {
260 test_rename( 128 test_rename(
261 r#" 129 r#"
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 };