diff options
Diffstat (limited to 'crates/ra_ide_api/src')
21 files changed, 82 insertions, 82 deletions
diff --git a/crates/ra_ide_api/src/call_info.rs b/crates/ra_ide_api/src/call_info.rs index 368fdcaa1..11dea7c14 100644 --- a/crates/ra_ide_api/src/call_info.rs +++ b/crates/ra_ide_api/src/call_info.rs | |||
@@ -10,8 +10,8 @@ use crate::{db::RootDatabase, CallInfo, FilePosition, FunctionSignature}; | |||
10 | 10 | ||
11 | /// Computes parameter information for the given call expression. | 11 | /// Computes parameter information for the given call expression. |
12 | pub(crate) fn call_info(db: &RootDatabase, position: FilePosition) -> Option<CallInfo> { | 12 | pub(crate) fn call_info(db: &RootDatabase, position: FilePosition) -> Option<CallInfo> { |
13 | let file = db.parse(position.file_id).tree; | 13 | let parse = db.parse(position.file_id); |
14 | let syntax = file.syntax(); | 14 | let syntax = parse.tree().syntax(); |
15 | 15 | ||
16 | // Find the calling expression and it's NameRef | 16 | // Find the calling expression and it's NameRef |
17 | let calling_node = FnCallNode::with_node(syntax, position.offset)?; | 17 | let calling_node = FnCallNode::with_node(syntax, position.offset)?; |
diff --git a/crates/ra_ide_api/src/change.rs b/crates/ra_ide_api/src/change.rs index 179f17ca4..1ba818197 100644 --- a/crates/ra_ide_api/src/change.rs +++ b/crates/ra_ide_api/src/change.rs | |||
@@ -135,8 +135,8 @@ impl LibraryData { | |||
135 | files: Vec<(FileId, RelativePathBuf, Arc<String>)>, | 135 | files: Vec<(FileId, RelativePathBuf, Arc<String>)>, |
136 | ) -> LibraryData { | 136 | ) -> LibraryData { |
137 | let symbol_index = SymbolIndex::for_files(files.par_iter().map(|(file_id, _, text)| { | 137 | let symbol_index = SymbolIndex::for_files(files.par_iter().map(|(file_id, _, text)| { |
138 | let file = SourceFile::parse(text).tree; | 138 | let parse = SourceFile::parse(text); |
139 | (*file_id, file) | 139 | (*file_id, parse) |
140 | })); | 140 | })); |
141 | let mut root_change = RootChange::default(); | 141 | let mut root_change = RootChange::default(); |
142 | root_change.added = files | 142 | root_change.added = files |
diff --git a/crates/ra_ide_api/src/completion/completion_context.rs b/crates/ra_ide_api/src/completion/completion_context.rs index 55fdba50d..f6584cdd6 100644 --- a/crates/ra_ide_api/src/completion/completion_context.rs +++ b/crates/ra_ide_api/src/completion/completion_context.rs | |||
@@ -48,7 +48,7 @@ impl<'a> CompletionContext<'a> { | |||
48 | ) -> Option<CompletionContext<'a>> { | 48 | ) -> Option<CompletionContext<'a>> { |
49 | let module = source_binder::module_from_position(db, position); | 49 | let module = source_binder::module_from_position(db, position); |
50 | let token = | 50 | let token = |
51 | find_token_at_offset(original_parse.tree.syntax(), position.offset).left_biased()?; | 51 | find_token_at_offset(original_parse.tree().syntax(), position.offset).left_biased()?; |
52 | let analyzer = | 52 | let analyzer = |
53 | hir::SourceAnalyzer::new(db, position.file_id, token.parent(), Some(position.offset)); | 53 | hir::SourceAnalyzer::new(db, position.file_id, token.parent(), Some(position.offset)); |
54 | let mut ctx = CompletionContext { | 54 | let mut ctx = CompletionContext { |
@@ -89,7 +89,7 @@ impl<'a> CompletionContext<'a> { | |||
89 | // actual completion. | 89 | // actual completion. |
90 | let file = { | 90 | let file = { |
91 | let edit = AtomTextEdit::insert(offset, "intellijRulezz".to_string()); | 91 | let edit = AtomTextEdit::insert(offset, "intellijRulezz".to_string()); |
92 | original_parse.reparse(&edit).tree | 92 | original_parse.reparse(&edit).tree().to_owned() |
93 | }; | 93 | }; |
94 | 94 | ||
95 | // First, let's try to complete a reference to some declaration. | 95 | // First, let's try to complete a reference to some declaration. |
@@ -100,7 +100,7 @@ impl<'a> CompletionContext<'a> { | |||
100 | self.is_param = true; | 100 | self.is_param = true; |
101 | return; | 101 | return; |
102 | } | 102 | } |
103 | self.classify_name_ref(&original_parse.tree, name_ref); | 103 | self.classify_name_ref(original_parse.tree(), name_ref); |
104 | } | 104 | } |
105 | 105 | ||
106 | // Otherwise, see if this is a declaration. We can use heuristics to | 106 | // Otherwise, see if this is a declaration. We can use heuristics to |
diff --git a/crates/ra_ide_api/src/diagnostics.rs b/crates/ra_ide_api/src/diagnostics.rs index a46289cba..3f5b9e0a0 100644 --- a/crates/ra_ide_api/src/diagnostics.rs +++ b/crates/ra_ide_api/src/diagnostics.rs | |||
@@ -27,14 +27,14 @@ pub(crate) fn diagnostics(db: &RootDatabase, file_id: FileId) -> Vec<Diagnostic> | |||
27 | let parse = db.parse(file_id); | 27 | let parse = db.parse(file_id); |
28 | let mut res = Vec::new(); | 28 | let mut res = Vec::new(); |
29 | 29 | ||
30 | res.extend(parse.errors.iter().map(|err| Diagnostic { | 30 | res.extend(parse.errors().iter().map(|err| Diagnostic { |
31 | range: location_to_range(err.location()), | 31 | range: location_to_range(err.location()), |
32 | message: format!("Syntax Error: {}", err), | 32 | message: format!("Syntax Error: {}", err), |
33 | severity: Severity::Error, | 33 | severity: Severity::Error, |
34 | fix: None, | 34 | fix: None, |
35 | })); | 35 | })); |
36 | 36 | ||
37 | for node in parse.tree.syntax().descendants() { | 37 | for node in parse.tree().syntax().descendants() { |
38 | check_unnecessary_braces_in_use_statement(&mut res, file_id, node); | 38 | check_unnecessary_braces_in_use_statement(&mut res, file_id, node); |
39 | check_struct_shorthand_initialization(&mut res, file_id, node); | 39 | check_struct_shorthand_initialization(&mut res, file_id, node); |
40 | } | 40 | } |
@@ -181,18 +181,18 @@ mod tests { | |||
181 | type DiagnosticChecker = fn(&mut Vec<Diagnostic>, FileId, &SyntaxNode) -> Option<()>; | 181 | type DiagnosticChecker = fn(&mut Vec<Diagnostic>, FileId, &SyntaxNode) -> Option<()>; |
182 | 182 | ||
183 | fn check_not_applicable(code: &str, func: DiagnosticChecker) { | 183 | fn check_not_applicable(code: &str, func: DiagnosticChecker) { |
184 | let file = SourceFile::parse(code).tree; | 184 | let parse = SourceFile::parse(code); |
185 | let mut diagnostics = Vec::new(); | 185 | let mut diagnostics = Vec::new(); |
186 | for node in file.syntax().descendants() { | 186 | for node in parse.tree().syntax().descendants() { |
187 | func(&mut diagnostics, FileId(0), node); | 187 | func(&mut diagnostics, FileId(0), node); |
188 | } | 188 | } |
189 | assert!(diagnostics.is_empty()); | 189 | assert!(diagnostics.is_empty()); |
190 | } | 190 | } |
191 | 191 | ||
192 | fn check_apply(before: &str, after: &str, func: DiagnosticChecker) { | 192 | fn check_apply(before: &str, after: &str, func: DiagnosticChecker) { |
193 | let file = SourceFile::parse(before).tree; | 193 | let parse = SourceFile::parse(before); |
194 | let mut diagnostics = Vec::new(); | 194 | let mut diagnostics = Vec::new(); |
195 | for node in file.syntax().descendants() { | 195 | for node in parse.tree().syntax().descendants() { |
196 | func(&mut diagnostics, FileId(0), node); | 196 | func(&mut diagnostics, FileId(0), node); |
197 | } | 197 | } |
198 | let diagnostic = | 198 | let diagnostic = |
diff --git a/crates/ra_ide_api/src/display/navigation_target.rs b/crates/ra_ide_api/src/display/navigation_target.rs index 1edb64e3d..20a8d418e 100644 --- a/crates/ra_ide_api/src/display/navigation_target.rs +++ b/crates/ra_ide_api/src/display/navigation_target.rs | |||
@@ -93,8 +93,8 @@ impl NavigationTarget { | |||
93 | file_id: FileId, | 93 | file_id: FileId, |
94 | pat: AstPtr<ast::Pat>, | 94 | pat: AstPtr<ast::Pat>, |
95 | ) -> NavigationTarget { | 95 | ) -> NavigationTarget { |
96 | let file = db.parse(file_id).tree; | 96 | let parse = db.parse(file_id); |
97 | let (name, full_range) = match pat.to_node(file.syntax()).kind() { | 97 | let (name, full_range) = match pat.to_node(parse.tree().syntax()).kind() { |
98 | ast::PatKind::BindPat(pat) => return NavigationTarget::from_bind_pat(file_id, &pat), | 98 | ast::PatKind::BindPat(pat) => return NavigationTarget::from_bind_pat(file_id, &pat), |
99 | _ => ("_".into(), pat.syntax_node_ptr().range()), | 99 | _ => ("_".into(), pat.syntax_node_ptr().range()), |
100 | }; | 100 | }; |
@@ -315,8 +315,8 @@ impl NavigationTarget { | |||
315 | } | 315 | } |
316 | 316 | ||
317 | pub(crate) fn docs_from_symbol(db: &RootDatabase, symbol: &FileSymbol) -> Option<String> { | 317 | pub(crate) fn docs_from_symbol(db: &RootDatabase, symbol: &FileSymbol) -> Option<String> { |
318 | let file = db.parse(symbol.file_id).tree; | 318 | let parse = db.parse(symbol.file_id); |
319 | let node = symbol.ptr.to_node(file.syntax()).to_owned(); | 319 | let node = symbol.ptr.to_node(parse.tree().syntax()).to_owned(); |
320 | 320 | ||
321 | fn doc_comments<N: ast::DocCommentsOwner>(node: &N) -> Option<String> { | 321 | fn doc_comments<N: ast::DocCommentsOwner>(node: &N) -> Option<String> { |
322 | node.doc_comment_text() | 322 | node.doc_comment_text() |
@@ -341,8 +341,8 @@ pub(crate) fn docs_from_symbol(db: &RootDatabase, symbol: &FileSymbol) -> Option | |||
341 | /// | 341 | /// |
342 | /// e.g. `struct Name`, `enum Name`, `fn Name` | 342 | /// e.g. `struct Name`, `enum Name`, `fn Name` |
343 | pub(crate) fn description_from_symbol(db: &RootDatabase, symbol: &FileSymbol) -> Option<String> { | 343 | pub(crate) fn description_from_symbol(db: &RootDatabase, symbol: &FileSymbol) -> Option<String> { |
344 | let file = db.parse(symbol.file_id).tree; | 344 | let parse = db.parse(symbol.file_id); |
345 | let node = symbol.ptr.to_node(file.syntax()).to_owned(); | 345 | let node = symbol.ptr.to_node(parse.tree().syntax()).to_owned(); |
346 | 346 | ||
347 | visitor() | 347 | visitor() |
348 | .visit(|node: &ast::FnDef| node.short_label()) | 348 | .visit(|node: &ast::FnDef| node.short_label()) |
diff --git a/crates/ra_ide_api/src/extend_selection.rs b/crates/ra_ide_api/src/extend_selection.rs index 655852514..491b15702 100644 --- a/crates/ra_ide_api/src/extend_selection.rs +++ b/crates/ra_ide_api/src/extend_selection.rs | |||
@@ -11,8 +11,8 @@ use crate::{db::RootDatabase, FileRange}; | |||
11 | 11 | ||
12 | // FIXME: restore macro support | 12 | // FIXME: restore macro support |
13 | pub(crate) fn extend_selection(db: &RootDatabase, frange: FileRange) -> TextRange { | 13 | pub(crate) fn extend_selection(db: &RootDatabase, frange: FileRange) -> TextRange { |
14 | let source_file = db.parse(frange.file_id).tree; | 14 | let parse = db.parse(frange.file_id); |
15 | try_extend_selection(source_file.syntax(), frange.range).unwrap_or(frange.range) | 15 | try_extend_selection(parse.tree().syntax(), frange.range).unwrap_or(frange.range) |
16 | } | 16 | } |
17 | 17 | ||
18 | fn try_extend_selection(root: &SyntaxNode, range: TextRange) -> Option<TextRange> { | 18 | fn try_extend_selection(root: &SyntaxNode, range: TextRange) -> Option<TextRange> { |
@@ -212,10 +212,10 @@ mod tests { | |||
212 | 212 | ||
213 | fn do_check(before: &str, afters: &[&str]) { | 213 | fn do_check(before: &str, afters: &[&str]) { |
214 | let (cursor, before) = extract_offset(before); | 214 | let (cursor, before) = extract_offset(before); |
215 | let file = SourceFile::parse(&before).tree; | 215 | let parse = SourceFile::parse(&before); |
216 | let mut range = TextRange::offset_len(cursor, 0.into()); | 216 | let mut range = TextRange::offset_len(cursor, 0.into()); |
217 | for &after in afters { | 217 | for &after in afters { |
218 | range = try_extend_selection(file.syntax(), range).unwrap(); | 218 | range = try_extend_selection(parse.tree().syntax(), range).unwrap(); |
219 | let actual = &before[range]; | 219 | let actual = &before[range]; |
220 | assert_eq!(after, actual); | 220 | assert_eq!(after, actual); |
221 | } | 221 | } |
diff --git a/crates/ra_ide_api/src/folding_ranges.rs b/crates/ra_ide_api/src/folding_ranges.rs index a1e6f94e0..9d4855a64 100644 --- a/crates/ra_ide_api/src/folding_ranges.rs +++ b/crates/ra_ide_api/src/folding_ranges.rs | |||
@@ -192,8 +192,8 @@ mod tests { | |||
192 | 192 | ||
193 | fn do_check(text: &str, fold_kinds: &[FoldKind]) { | 193 | fn do_check(text: &str, fold_kinds: &[FoldKind]) { |
194 | let (ranges, text) = extract_ranges(text, "fold"); | 194 | let (ranges, text) = extract_ranges(text, "fold"); |
195 | let file = SourceFile::parse(&text).tree; | 195 | let parse = SourceFile::parse(&text); |
196 | let folds = folding_ranges(&file); | 196 | let folds = folding_ranges(parse.tree()); |
197 | 197 | ||
198 | assert_eq!( | 198 | assert_eq!( |
199 | folds.len(), | 199 | folds.len(), |
diff --git a/crates/ra_ide_api/src/goto_definition.rs b/crates/ra_ide_api/src/goto_definition.rs index 08feed7dc..1066bf155 100644 --- a/crates/ra_ide_api/src/goto_definition.rs +++ b/crates/ra_ide_api/src/goto_definition.rs | |||
@@ -19,8 +19,8 @@ pub(crate) fn goto_definition( | |||
19 | db: &RootDatabase, | 19 | db: &RootDatabase, |
20 | position: FilePosition, | 20 | position: FilePosition, |
21 | ) -> Option<RangeInfo<Vec<NavigationTarget>>> { | 21 | ) -> Option<RangeInfo<Vec<NavigationTarget>>> { |
22 | let file = db.parse(position.file_id).tree; | 22 | let parse = db.parse(position.file_id); |
23 | let syntax = file.syntax(); | 23 | let syntax = parse.tree().syntax(); |
24 | if let Some(name_ref) = find_node_at_offset::<ast::NameRef>(syntax, position.offset) { | 24 | if let Some(name_ref) = find_node_at_offset::<ast::NameRef>(syntax, position.offset) { |
25 | let navs = reference_definition(db, position.file_id, name_ref).to_vec(); | 25 | let navs = reference_definition(db, position.file_id, name_ref).to_vec(); |
26 | return Some(RangeInfo::new(name_ref.syntax().range(), navs.to_vec())); | 26 | return Some(RangeInfo::new(name_ref.syntax().range(), navs.to_vec())); |
diff --git a/crates/ra_ide_api/src/goto_type_definition.rs b/crates/ra_ide_api/src/goto_type_definition.rs index d2d5eae9a..6ce5e214f 100644 --- a/crates/ra_ide_api/src/goto_type_definition.rs +++ b/crates/ra_ide_api/src/goto_type_definition.rs | |||
@@ -7,9 +7,9 @@ pub(crate) fn goto_type_definition( | |||
7 | db: &RootDatabase, | 7 | db: &RootDatabase, |
8 | position: FilePosition, | 8 | position: FilePosition, |
9 | ) -> Option<RangeInfo<Vec<NavigationTarget>>> { | 9 | ) -> Option<RangeInfo<Vec<NavigationTarget>>> { |
10 | let file = db.parse(position.file_id).tree; | 10 | let parse = db.parse(position.file_id); |
11 | 11 | ||
12 | let node = find_token_at_offset(file.syntax(), position.offset).find_map(|token| { | 12 | let node = find_token_at_offset(parse.tree().syntax(), position.offset).find_map(|token| { |
13 | token | 13 | token |
14 | .parent() | 14 | .parent() |
15 | .ancestors() | 15 | .ancestors() |
diff --git a/crates/ra_ide_api/src/hover.rs b/crates/ra_ide_api/src/hover.rs index 48f1f49c9..253d21f48 100644 --- a/crates/ra_ide_api/src/hover.rs +++ b/crates/ra_ide_api/src/hover.rs | |||
@@ -94,7 +94,8 @@ fn hover_text(docs: Option<String>, desc: Option<String>) -> Option<String> { | |||
94 | } | 94 | } |
95 | 95 | ||
96 | pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option<RangeInfo<HoverResult>> { | 96 | pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option<RangeInfo<HoverResult>> { |
97 | let file = db.parse(position.file_id).tree; | 97 | let parse = db.parse(position.file_id); |
98 | let file = parse.tree(); | ||
98 | let mut res = HoverResult::new(); | 99 | let mut res = HoverResult::new(); |
99 | 100 | ||
100 | let mut range = None; | 101 | let mut range = None; |
@@ -241,8 +242,8 @@ pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option<RangeIn | |||
241 | } | 242 | } |
242 | 243 | ||
243 | pub(crate) fn type_of(db: &RootDatabase, frange: FileRange) -> Option<String> { | 244 | pub(crate) fn type_of(db: &RootDatabase, frange: FileRange) -> Option<String> { |
244 | let file = db.parse(frange.file_id).tree; | 245 | let parse = db.parse(frange.file_id); |
245 | let syntax = file.syntax(); | 246 | let syntax = parse.tree().syntax(); |
246 | let leaf_node = find_covering_element(syntax, frange.range); | 247 | let leaf_node = find_covering_element(syntax, frange.range); |
247 | // if we picked identifier, expand to pattern/expression | 248 | // if we picked identifier, expand to pattern/expression |
248 | let node = leaf_node | 249 | let node = leaf_node |
diff --git a/crates/ra_ide_api/src/impls.rs b/crates/ra_ide_api/src/impls.rs index 97615b01f..6d69f36aa 100644 --- a/crates/ra_ide_api/src/impls.rs +++ b/crates/ra_ide_api/src/impls.rs | |||
@@ -8,8 +8,8 @@ pub(crate) fn goto_implementation( | |||
8 | db: &RootDatabase, | 8 | db: &RootDatabase, |
9 | position: FilePosition, | 9 | position: FilePosition, |
10 | ) -> Option<RangeInfo<Vec<NavigationTarget>>> { | 10 | ) -> Option<RangeInfo<Vec<NavigationTarget>>> { |
11 | let file = db.parse(position.file_id).tree; | 11 | let parse = db.parse(position.file_id); |
12 | let syntax = file.syntax(); | 12 | let syntax = parse.tree().syntax(); |
13 | 13 | ||
14 | let module = source_binder::module_from_position(db, position)?; | 14 | let module = source_binder::module_from_position(db, position)?; |
15 | 15 | ||
diff --git a/crates/ra_ide_api/src/join_lines.rs b/crates/ra_ide_api/src/join_lines.rs index 8ab485adb..e20cb1370 100644 --- a/crates/ra_ide_api/src/join_lines.rs +++ b/crates/ra_ide_api/src/join_lines.rs | |||
@@ -503,8 +503,8 @@ fn foo() { | |||
503 | 503 | ||
504 | fn check_join_lines_sel(before: &str, after: &str) { | 504 | fn check_join_lines_sel(before: &str, after: &str) { |
505 | let (sel, before) = extract_range(before); | 505 | let (sel, before) = extract_range(before); |
506 | let file = SourceFile::parse(&before).tree; | 506 | let parse = SourceFile::parse(&before); |
507 | let result = join_lines(&file, sel); | 507 | let result = join_lines(parse.tree(), sel); |
508 | let actual = result.apply(&before); | 508 | let actual = result.apply(&before); |
509 | assert_eq_text!(after, &actual); | 509 | assert_eq_text!(after, &actual); |
510 | } | 510 | } |
diff --git a/crates/ra_ide_api/src/lib.rs b/crates/ra_ide_api/src/lib.rs index 95de9bcb8..9f3b18d9d 100644 --- a/crates/ra_ide_api/src/lib.rs +++ b/crates/ra_ide_api/src/lib.rs | |||
@@ -326,7 +326,7 @@ impl Analysis { | |||
326 | 326 | ||
327 | /// Gets the syntax tree of the file. | 327 | /// Gets the syntax tree of the file. |
328 | pub fn parse(&self, file_id: FileId) -> TreeArc<SourceFile> { | 328 | pub fn parse(&self, file_id: FileId) -> TreeArc<SourceFile> { |
329 | self.db.parse(file_id).tree | 329 | self.db.parse(file_id).tree().to_owned() |
330 | } | 330 | } |
331 | 331 | ||
332 | /// Gets the file's `LineIndex`: data structure to convert between absolute | 332 | /// Gets the file's `LineIndex`: data structure to convert between absolute |
@@ -343,7 +343,8 @@ impl Analysis { | |||
343 | /// Returns position of the matching brace (all types of braces are | 343 | /// Returns position of the matching brace (all types of braces are |
344 | /// supported). | 344 | /// supported). |
345 | pub fn matching_brace(&self, position: FilePosition) -> Option<TextUnit> { | 345 | pub fn matching_brace(&self, position: FilePosition) -> Option<TextUnit> { |
346 | let file = self.db.parse(position.file_id).tree; | 346 | let parse = self.db.parse(position.file_id); |
347 | let file = parse.tree(); | ||
347 | matching_brace::matching_brace(&file, position.offset) | 348 | matching_brace::matching_brace(&file, position.offset) |
348 | } | 349 | } |
349 | 350 | ||
@@ -356,10 +357,10 @@ impl Analysis { | |||
356 | /// Returns an edit to remove all newlines in the range, cleaning up minor | 357 | /// Returns an edit to remove all newlines in the range, cleaning up minor |
357 | /// stuff like trailing commas. | 358 | /// stuff like trailing commas. |
358 | pub fn join_lines(&self, frange: FileRange) -> SourceChange { | 359 | pub fn join_lines(&self, frange: FileRange) -> SourceChange { |
359 | let file = self.db.parse(frange.file_id).tree; | 360 | let parse = self.db.parse(frange.file_id); |
360 | let file_edit = SourceFileEdit { | 361 | let file_edit = SourceFileEdit { |
361 | file_id: frange.file_id, | 362 | file_id: frange.file_id, |
362 | edit: join_lines::join_lines(&file, frange.range), | 363 | edit: join_lines::join_lines(parse.tree(), frange.range), |
363 | }; | 364 | }; |
364 | SourceChange::source_file_edit("join lines", file_edit) | 365 | SourceChange::source_file_edit("join lines", file_edit) |
365 | } | 366 | } |
@@ -374,7 +375,8 @@ impl Analysis { | |||
374 | /// this works when adding `let =`. | 375 | /// this works when adding `let =`. |
375 | // FIXME: use a snippet completion instead of this hack here. | 376 | // FIXME: use a snippet completion instead of this hack here. |
376 | pub fn on_eq_typed(&self, position: FilePosition) -> Option<SourceChange> { | 377 | pub fn on_eq_typed(&self, position: FilePosition) -> Option<SourceChange> { |
377 | let file = self.db.parse(position.file_id).tree; | 378 | let parse = self.db.parse(position.file_id); |
379 | let file = parse.tree(); | ||
378 | let edit = typing::on_eq_typed(&file, position.offset)?; | 380 | let edit = typing::on_eq_typed(&file, position.offset)?; |
379 | Some(SourceChange::source_file_edit( | 381 | Some(SourceChange::source_file_edit( |
380 | "add semicolon", | 382 | "add semicolon", |
@@ -390,14 +392,14 @@ impl Analysis { | |||
390 | /// Returns a tree representation of symbols in the file. Useful to draw a | 392 | /// Returns a tree representation of symbols in the file. Useful to draw a |
391 | /// file outline. | 393 | /// file outline. |
392 | pub fn file_structure(&self, file_id: FileId) -> Vec<StructureNode> { | 394 | pub fn file_structure(&self, file_id: FileId) -> Vec<StructureNode> { |
393 | let file = self.db.parse(file_id).tree; | 395 | let parse = self.db.parse(file_id); |
394 | file_structure(&file) | 396 | file_structure(parse.tree()) |
395 | } | 397 | } |
396 | 398 | ||
397 | /// Returns the set of folding ranges. | 399 | /// Returns the set of folding ranges. |
398 | pub fn folding_ranges(&self, file_id: FileId) -> Vec<Fold> { | 400 | pub fn folding_ranges(&self, file_id: FileId) -> Vec<Fold> { |
399 | let file = self.db.parse(file_id).tree; | 401 | let parse = self.db.parse(file_id); |
400 | folding_ranges::folding_ranges(&file) | 402 | folding_ranges::folding_ranges(parse.tree()) |
401 | } | 403 | } |
402 | 404 | ||
403 | /// Fuzzy searches for a symbol. | 405 | /// Fuzzy searches for a symbol. |
diff --git a/crates/ra_ide_api/src/matching_brace.rs b/crates/ra_ide_api/src/matching_brace.rs index 438b07896..455a5c891 100644 --- a/crates/ra_ide_api/src/matching_brace.rs +++ b/crates/ra_ide_api/src/matching_brace.rs | |||
@@ -25,8 +25,8 @@ mod tests { | |||
25 | fn test_matching_brace() { | 25 | fn test_matching_brace() { |
26 | fn do_check(before: &str, after: &str) { | 26 | fn do_check(before: &str, after: &str) { |
27 | let (pos, before) = extract_offset(before); | 27 | let (pos, before) = extract_offset(before); |
28 | let file = SourceFile::parse(&before).tree; | 28 | let parse = SourceFile::parse(&before); |
29 | let new_pos = match matching_brace(&file, pos) { | 29 | let new_pos = match matching_brace(parse.tree(), pos) { |
30 | None => pos, | 30 | None => pos, |
31 | Some(pos) => pos, | 31 | Some(pos) => pos, |
32 | }; | 32 | }; |
diff --git a/crates/ra_ide_api/src/references.rs b/crates/ra_ide_api/src/references.rs index 766c0ad74..0af1ae811 100644 --- a/crates/ra_ide_api/src/references.rs +++ b/crates/ra_ide_api/src/references.rs | |||
@@ -49,8 +49,8 @@ pub(crate) fn find_all_refs( | |||
49 | db: &RootDatabase, | 49 | db: &RootDatabase, |
50 | position: FilePosition, | 50 | position: FilePosition, |
51 | ) -> Option<ReferenceSearchResult> { | 51 | ) -> Option<ReferenceSearchResult> { |
52 | let file = db.parse(position.file_id).tree; | 52 | let parse = db.parse(position.file_id); |
53 | let (binding, analyzer) = find_binding(db, &file, position)?; | 53 | let (binding, analyzer) = find_binding(db, parse.tree(), position)?; |
54 | let declaration = NavigationTarget::from_bind_pat(position.file_id, binding); | 54 | let declaration = NavigationTarget::from_bind_pat(position.file_id, binding); |
55 | 55 | ||
56 | let references = analyzer | 56 | let references = analyzer |
@@ -88,8 +88,8 @@ pub(crate) fn rename( | |||
88 | position: FilePosition, | 88 | position: FilePosition, |
89 | new_name: &str, | 89 | new_name: &str, |
90 | ) -> Option<SourceChange> { | 90 | ) -> Option<SourceChange> { |
91 | let source_file = db.parse(position.file_id).tree; | 91 | let parse = db.parse(position.file_id); |
92 | let syntax = source_file.syntax(); | 92 | let syntax = parse.tree().syntax(); |
93 | 93 | ||
94 | if let Some((ast_name, ast_module)) = find_name_and_module_at_offset(syntax, position) { | 94 | if let Some((ast_name, ast_module)) = find_name_and_module_at_offset(syntax, position) { |
95 | rename_mod(db, ast_name, ast_module, position, new_name) | 95 | rename_mod(db, ast_name, ast_module, position, new_name) |
diff --git a/crates/ra_ide_api/src/runnables.rs b/crates/ra_ide_api/src/runnables.rs index 2d2d0b40e..8cb859b37 100644 --- a/crates/ra_ide_api/src/runnables.rs +++ b/crates/ra_ide_api/src/runnables.rs | |||
@@ -22,8 +22,8 @@ pub enum RunnableKind { | |||
22 | } | 22 | } |
23 | 23 | ||
24 | pub(crate) fn runnables(db: &RootDatabase, file_id: FileId) -> Vec<Runnable> { | 24 | pub(crate) fn runnables(db: &RootDatabase, file_id: FileId) -> Vec<Runnable> { |
25 | let source_file = db.parse(file_id).tree; | 25 | let parse = db.parse(file_id); |
26 | source_file.syntax().descendants().filter_map(|i| runnable(db, file_id, i)).collect() | 26 | parse.tree().syntax().descendants().filter_map(|i| runnable(db, file_id, i)).collect() |
27 | } | 27 | } |
28 | 28 | ||
29 | fn runnable(db: &RootDatabase, file_id: FileId, item: &SyntaxNode) -> Option<Runnable> { | 29 | fn runnable(db: &RootDatabase, file_id: FileId, item: &SyntaxNode) -> Option<Runnable> { |
diff --git a/crates/ra_ide_api/src/status.rs b/crates/ra_ide_api/src/status.rs index 1bcba0b8b..ce27f5ae2 100644 --- a/crates/ra_ide_api/src/status.rs +++ b/crates/ra_ide_api/src/status.rs | |||
@@ -87,7 +87,7 @@ impl FromIterator<TableEntry<FileId, Parse>> for SyntaxTreeStats { | |||
87 | let mut res = SyntaxTreeStats::default(); | 87 | let mut res = SyntaxTreeStats::default(); |
88 | for entry in iter { | 88 | for entry in iter { |
89 | res.total += 1; | 89 | res.total += 1; |
90 | if let Some(tree) = entry.value.as_ref().map(|it| &it.tree) { | 90 | if let Some(tree) = entry.value.as_ref().map(|it| it.tree()) { |
91 | res.retained += 1; | 91 | res.retained += 1; |
92 | res.retained_size += tree.syntax().memory_size_of_subtree(); | 92 | res.retained_size += tree.syntax().memory_size_of_subtree(); |
93 | } | 93 | } |
diff --git a/crates/ra_ide_api/src/symbol_index.rs b/crates/ra_ide_api/src/symbol_index.rs index f4a0c6ac7..1f2ba954e 100644 --- a/crates/ra_ide_api/src/symbol_index.rs +++ b/crates/ra_ide_api/src/symbol_index.rs | |||
@@ -34,9 +34,9 @@ use ra_db::{ | |||
34 | use ra_syntax::{ | 34 | use ra_syntax::{ |
35 | algo::visit::{visitor, Visitor}, | 35 | algo::visit::{visitor, Visitor}, |
36 | ast::{self, NameOwner}, | 36 | ast::{self, NameOwner}, |
37 | AstNode, SmolStr, SourceFile, | 37 | AstNode, Parse, SmolStr, SourceFile, |
38 | SyntaxKind::{self, *}, | 38 | SyntaxKind::{self, *}, |
39 | SyntaxNode, SyntaxNodePtr, TextRange, TreeArc, WalkEvent, | 39 | SyntaxNode, SyntaxNodePtr, TextRange, WalkEvent, |
40 | }; | 40 | }; |
41 | use rayon::prelude::*; | 41 | use rayon::prelude::*; |
42 | 42 | ||
@@ -59,9 +59,9 @@ pub(crate) trait SymbolsDatabase: hir::db::HirDatabase { | |||
59 | 59 | ||
60 | fn file_symbols(db: &impl SymbolsDatabase, file_id: FileId) -> Arc<SymbolIndex> { | 60 | fn file_symbols(db: &impl SymbolsDatabase, file_id: FileId) -> Arc<SymbolIndex> { |
61 | db.check_canceled(); | 61 | db.check_canceled(); |
62 | let source_file = db.parse(file_id).tree; | 62 | let parse = db.parse(file_id); |
63 | 63 | ||
64 | let symbols = source_file_to_file_symbols(&source_file, file_id); | 64 | let symbols = source_file_to_file_symbols(parse.tree(), file_id); |
65 | 65 | ||
66 | // FIXME: add macros here | 66 | // FIXME: add macros here |
67 | 67 | ||
@@ -169,11 +169,9 @@ impl SymbolIndex { | |||
169 | self.map.as_fst().size() + self.symbols.len() * mem::size_of::<FileSymbol>() | 169 | self.map.as_fst().size() + self.symbols.len() * mem::size_of::<FileSymbol>() |
170 | } | 170 | } |
171 | 171 | ||
172 | pub(crate) fn for_files( | 172 | pub(crate) fn for_files(files: impl ParallelIterator<Item = (FileId, Parse)>) -> SymbolIndex { |
173 | files: impl ParallelIterator<Item = (FileId, TreeArc<SourceFile>)>, | ||
174 | ) -> SymbolIndex { | ||
175 | let symbols = files | 173 | let symbols = files |
176 | .flat_map(|(file_id, file)| source_file_to_file_symbols(&file, file_id)) | 174 | .flat_map(|(file_id, file)| source_file_to_file_symbols(file.tree(), file_id)) |
177 | .collect::<Vec<_>>(); | 175 | .collect::<Vec<_>>(); |
178 | SymbolIndex::new(symbols) | 176 | SymbolIndex::new(symbols) |
179 | } | 177 | } |
diff --git a/crates/ra_ide_api/src/syntax_highlighting.rs b/crates/ra_ide_api/src/syntax_highlighting.rs index 7c4285b02..d70ceb7d1 100644 --- a/crates/ra_ide_api/src/syntax_highlighting.rs +++ b/crates/ra_ide_api/src/syntax_highlighting.rs | |||
@@ -32,7 +32,8 @@ fn is_control_keyword(kind: SyntaxKind) -> bool { | |||
32 | 32 | ||
33 | pub(crate) fn highlight(db: &RootDatabase, file_id: FileId) -> Vec<HighlightedRange> { | 33 | pub(crate) fn highlight(db: &RootDatabase, file_id: FileId) -> Vec<HighlightedRange> { |
34 | let _p = profile("highlight"); | 34 | let _p = profile("highlight"); |
35 | let source_file = db.parse(file_id).tree; | 35 | let parse = db.parse(file_id); |
36 | let root = parse.tree().syntax(); | ||
36 | 37 | ||
37 | fn calc_binding_hash(file_id: FileId, text: &SmolStr, shadow_count: u32) -> u64 { | 38 | fn calc_binding_hash(file_id: FileId, text: &SmolStr, shadow_count: u32) -> u64 { |
38 | fn hash<T: std::hash::Hash + std::fmt::Debug>(x: T) -> u64 { | 39 | fn hash<T: std::hash::Hash + std::fmt::Debug>(x: T) -> u64 { |
@@ -51,7 +52,7 @@ pub(crate) fn highlight(db: &RootDatabase, file_id: FileId) -> Vec<HighlightedRa | |||
51 | let mut bindings_shadow_count: FxHashMap<SmolStr, u32> = FxHashMap::default(); | 52 | let mut bindings_shadow_count: FxHashMap<SmolStr, u32> = FxHashMap::default(); |
52 | 53 | ||
53 | let mut res = Vec::new(); | 54 | let mut res = Vec::new(); |
54 | for node in source_file.syntax().descendants_with_tokens() { | 55 | for node in root.descendants_with_tokens() { |
55 | if highlighted.contains(&node) { | 56 | if highlighted.contains(&node) { |
56 | continue; | 57 | continue; |
57 | } | 58 | } |
@@ -89,11 +90,8 @@ pub(crate) fn highlight(db: &RootDatabase, file_id: FileId) -> Vec<HighlightedRa | |||
89 | Some(SelfType(_)) => "type", | 90 | Some(SelfType(_)) => "type", |
90 | Some(Pat(ptr)) => { | 91 | Some(Pat(ptr)) => { |
91 | binding_hash = Some({ | 92 | binding_hash = Some({ |
92 | let text = ptr | 93 | let text = |
93 | .syntax_node_ptr() | 94 | ptr.syntax_node_ptr().to_node(root).text().to_smol_string(); |
94 | .to_node(&source_file.syntax()) | ||
95 | .text() | ||
96 | .to_smol_string(); | ||
97 | let shadow_count = | 95 | let shadow_count = |
98 | bindings_shadow_count.entry(text.clone()).or_default(); | 96 | bindings_shadow_count.entry(text.clone()).or_default(); |
99 | calc_binding_hash(file_id, &text, *shadow_count) | 97 | calc_binding_hash(file_id, &text, *shadow_count) |
@@ -178,7 +176,7 @@ pub(crate) fn highlight(db: &RootDatabase, file_id: FileId) -> Vec<HighlightedRa | |||
178 | } | 176 | } |
179 | 177 | ||
180 | pub(crate) fn highlight_as_html(db: &RootDatabase, file_id: FileId, rainbow: bool) -> String { | 178 | pub(crate) fn highlight_as_html(db: &RootDatabase, file_id: FileId, rainbow: bool) -> String { |
181 | let source_file = db.parse(file_id).tree; | 179 | let parse = db.parse(file_id); |
182 | 180 | ||
183 | fn rainbowify(seed: u64) -> String { | 181 | fn rainbowify(seed: u64) -> String { |
184 | use rand::prelude::*; | 182 | use rand::prelude::*; |
@@ -200,7 +198,7 @@ pub(crate) fn highlight_as_html(db: &RootDatabase, file_id: FileId, rainbow: boo | |||
200 | let mut buf = String::new(); | 198 | let mut buf = String::new(); |
201 | buf.push_str(&STYLE); | 199 | buf.push_str(&STYLE); |
202 | buf.push_str("<pre><code>"); | 200 | buf.push_str("<pre><code>"); |
203 | let tokens = source_file.syntax().descendants_with_tokens().filter_map(|it| it.as_token()); | 201 | let tokens = parse.tree().syntax().descendants_with_tokens().filter_map(|it| it.as_token()); |
204 | for token in tokens { | 202 | for token in tokens { |
205 | could_intersect.retain(|it| token.range().start() <= it.range.end()); | 203 | could_intersect.retain(|it| token.range().start() <= it.range.end()); |
206 | while let Some(r) = ranges.get(frontier) { | 204 | while let Some(r) = ranges.get(frontier) { |
diff --git a/crates/ra_ide_api/src/syntax_tree.rs b/crates/ra_ide_api/src/syntax_tree.rs index 8bdd08d58..b3e08c041 100644 --- a/crates/ra_ide_api/src/syntax_tree.rs +++ b/crates/ra_ide_api/src/syntax_tree.rs | |||
@@ -13,9 +13,9 @@ pub(crate) fn syntax_tree( | |||
13 | file_id: FileId, | 13 | file_id: FileId, |
14 | text_range: Option<TextRange>, | 14 | text_range: Option<TextRange>, |
15 | ) -> String { | 15 | ) -> String { |
16 | let parse = db.parse(file_id); | ||
16 | if let Some(text_range) = text_range { | 17 | if let Some(text_range) = text_range { |
17 | let file = db.parse(file_id).tree; | 18 | let node = match algo::find_covering_element(parse.tree().syntax(), text_range) { |
18 | let node = match algo::find_covering_element(file.syntax(), text_range) { | ||
19 | SyntaxElement::Node(node) => node, | 19 | SyntaxElement::Node(node) => node, |
20 | SyntaxElement::Token(token) => { | 20 | SyntaxElement::Token(token) => { |
21 | if let Some(tree) = syntax_tree_for_string(token, text_range) { | 21 | if let Some(tree) = syntax_tree_for_string(token, text_range) { |
@@ -27,7 +27,7 @@ pub(crate) fn syntax_tree( | |||
27 | 27 | ||
28 | node.debug_dump() | 28 | node.debug_dump() |
29 | } else { | 29 | } else { |
30 | db.parse(file_id).tree.syntax().debug_dump() | 30 | parse.tree().syntax().debug_dump() |
31 | } | 31 | } |
32 | } | 32 | } |
33 | 33 | ||
@@ -84,8 +84,8 @@ fn syntax_tree_for_token(node: SyntaxToken, text_range: TextRange) -> Option<Str | |||
84 | 84 | ||
85 | // If the "file" parsed without errors, | 85 | // If the "file" parsed without errors, |
86 | // return its syntax | 86 | // return its syntax |
87 | if parsed.errors.is_empty() { | 87 | if parsed.errors().is_empty() { |
88 | return Some(parsed.tree.syntax().debug_dump()); | 88 | return Some(parsed.tree().syntax().debug_dump()); |
89 | } | 89 | } |
90 | 90 | ||
91 | None | 91 | None |
diff --git a/crates/ra_ide_api/src/typing.rs b/crates/ra_ide_api/src/typing.rs index d3cb71ddb..01eb32b2f 100644 --- a/crates/ra_ide_api/src/typing.rs +++ b/crates/ra_ide_api/src/typing.rs | |||
@@ -11,7 +11,8 @@ use ra_syntax::{ | |||
11 | use ra_text_edit::{TextEdit, TextEditBuilder}; | 11 | use ra_text_edit::{TextEdit, TextEditBuilder}; |
12 | 12 | ||
13 | pub(crate) fn on_enter(db: &RootDatabase, position: FilePosition) -> Option<SourceChange> { | 13 | pub(crate) fn on_enter(db: &RootDatabase, position: FilePosition) -> Option<SourceChange> { |
14 | let file = db.parse(position.file_id).tree; | 14 | let parse = db.parse(position.file_id); |
15 | let file = parse.tree(); | ||
15 | let comment = find_token_at_offset(file.syntax(), position.offset) | 16 | let comment = find_token_at_offset(file.syntax(), position.offset) |
16 | .left_biased() | 17 | .left_biased() |
17 | .and_then(ast::Comment::cast)?; | 18 | .and_then(ast::Comment::cast)?; |
@@ -86,10 +87,10 @@ pub fn on_eq_typed(file: &SourceFile, eq_offset: TextUnit) -> Option<TextEdit> { | |||
86 | } | 87 | } |
87 | 88 | ||
88 | pub(crate) fn on_dot_typed(db: &RootDatabase, position: FilePosition) -> Option<SourceChange> { | 89 | pub(crate) fn on_dot_typed(db: &RootDatabase, position: FilePosition) -> Option<SourceChange> { |
89 | let file = db.parse(position.file_id).tree; | 90 | let parse = db.parse(position.file_id); |
90 | assert_eq!(file.syntax().text().char_at(position.offset), Some('.')); | 91 | assert_eq!(parse.tree().syntax().text().char_at(position.offset), Some('.')); |
91 | 92 | ||
92 | let whitespace = find_token_at_offset(file.syntax(), position.offset) | 93 | let whitespace = find_token_at_offset(parse.tree().syntax(), position.offset) |
93 | .left_biased() | 94 | .left_biased() |
94 | .and_then(ast::Whitespace::cast)?; | 95 | .and_then(ast::Whitespace::cast)?; |
95 | 96 | ||
@@ -139,8 +140,8 @@ mod tests { | |||
139 | let mut edit = TextEditBuilder::default(); | 140 | let mut edit = TextEditBuilder::default(); |
140 | edit.insert(offset, "=".to_string()); | 141 | edit.insert(offset, "=".to_string()); |
141 | let before = edit.finish().apply(&before); | 142 | let before = edit.finish().apply(&before); |
142 | let file = SourceFile::parse(&before).tree; | 143 | let parse = SourceFile::parse(&before); |
143 | if let Some(result) = on_eq_typed(&file, offset) { | 144 | if let Some(result) = on_eq_typed(parse.tree(), offset) { |
144 | let actual = result.apply(&before); | 145 | let actual = result.apply(&before); |
145 | assert_eq_text!(after, &actual); | 146 | assert_eq_text!(after, &actual); |
146 | } else { | 147 | } else { |