Skip to content

Commit 8bb81d7

Browse files
bors[bot]matklad
andcommitted
Merge #1524
1524: make Parse fields private r=matklad a=matklad Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2 parents 2e466bb + deab4ca commit 8bb81d7

31 files changed

+109
-99
lines changed

crates/ra_assists/src/assist_ctx.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,11 @@ impl<'a, DB: HirDatabase> AssistCtx<'a, DB> {
7171
where
7272
F: FnOnce(AssistCtx<DB>) -> T,
7373
{
74-
let source_file = &db.parse(frange.file_id).tree;
74+
let parse = db.parse(frange.file_id);
7575
let assist =
7676
if should_compute_edit { Assist::Resolved(vec![]) } else { Assist::Unresolved(vec![]) };
7777

78-
let ctx = AssistCtx { db, frange, source_file, should_compute_edit, assist };
78+
let ctx = AssistCtx { db, frange, source_file: parse.tree(), should_compute_edit, assist };
7979
f(ctx)
8080
}
8181

crates/ra_assists/src/ast_editor.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -278,16 +278,17 @@ impl AstBuilder<ast::NameRef> {
278278
}
279279

280280
fn ast_node_from_file_text<N: AstNode>(text: &str) -> TreeArc<N> {
281-
let file = SourceFile::parse(text).tree;
282-
let res = file.syntax().descendants().find_map(N::cast).unwrap().to_owned();
281+
let parse = SourceFile::parse(text);
282+
let res = parse.tree().syntax().descendants().find_map(N::cast).unwrap().to_owned();
283283
res
284284
}
285285

286286
mod tokens {
287287
use once_cell::sync::Lazy;
288288
use ra_syntax::{AstNode, SourceFile, SyntaxKind::*, SyntaxToken, TreeArc, T};
289289

290-
static SOURCE_FILE: Lazy<TreeArc<SourceFile>> = Lazy::new(|| SourceFile::parse(",\n; ;").tree);
290+
static SOURCE_FILE: Lazy<TreeArc<SourceFile>> =
291+
Lazy::new(|| SourceFile::parse(",\n; ;").tree().to_owned());
291292

292293
pub(crate) fn comma() -> SyntaxToken<'static> {
293294
SOURCE_FILE

crates/ra_cli/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ fn main() -> Result<()> {
102102

103103
fn file() -> Result<TreeArc<SourceFile>> {
104104
let text = read_stdin()?;
105-
Ok(SourceFile::parse(&text).tree)
105+
Ok(SourceFile::parse(&text).tree().to_owned())
106106
}
107107

108108
fn read_stdin() -> Result<String> {

crates/ra_hir/src/code_model.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ impl ModuleSource {
167167
) -> ModuleSource {
168168
match (file_id, decl_id) {
169169
(Some(file_id), _) => {
170-
let source_file = db.parse(file_id).tree;
170+
let source_file = db.parse(file_id).tree().to_owned();
171171
ModuleSource::SourceFile(source_file)
172172
}
173173
(None, Some(item_id)) => {

crates/ra_hir/src/expr/validation.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ impl<'a, 'b> ExprValidator<'a, 'b> {
7171
}
7272
let source_map = self.func.body_source_map(db);
7373
let file_id = self.func.source(db).file_id;
74-
let source_file = db.parse(file_id.original_file(db)).tree;
74+
let parse = db.parse(file_id.original_file(db));
75+
let source_file = parse.tree();
7576
if let Some(field_list_node) = source_map
7677
.expr_syntax(id)
7778
.map(|ptr| ptr.to_node(source_file.syntax()))

crates/ra_hir/src/ids.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ impl HirFileId {
6060
file_id: HirFileId,
6161
) -> Option<TreeArc<SyntaxNode>> {
6262
match file_id.0 {
63-
HirFileIdRepr::File(file_id) => Some(db.parse(file_id).tree.syntax().to_owned()),
63+
HirFileIdRepr::File(file_id) => Some(db.parse(file_id).tree().syntax().to_owned()),
6464
HirFileIdRepr::Macro(macro_file) => db.parse_macro(macro_file),
6565
}
6666
}

crates/ra_hir/src/source_binder.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ pub fn module_from_declaration(
4949

5050
/// Locates the module by position in the source code.
5151
pub fn module_from_position(db: &impl HirDatabase, position: FilePosition) -> Option<Module> {
52-
let file = db.parse(position.file_id).tree;
53-
match find_node_at_offset::<ast::Module>(file.syntax(), position.offset) {
52+
let parse = db.parse(position.file_id);
53+
match find_node_at_offset::<ast::Module>(parse.tree().syntax(), position.offset) {
5454
Some(m) if !m.has_semi() => module_from_inline(db, position.file_id, m),
5555
_ => module_from_file_id(db, position.file_id),
5656
}

crates/ra_ide_api/src/call_info.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ use crate::{db::RootDatabase, CallInfo, FilePosition, FunctionSignature};
1010

1111
/// Computes parameter information for the given call expression.
1212
pub(crate) fn call_info(db: &RootDatabase, position: FilePosition) -> Option<CallInfo> {
13-
let file = db.parse(position.file_id).tree;
14-
let syntax = file.syntax();
13+
let parse = db.parse(position.file_id);
14+
let syntax = parse.tree().syntax();
1515

1616
// Find the calling expression and it's NameRef
1717
let calling_node = FnCallNode::with_node(syntax, position.offset)?;

crates/ra_ide_api/src/change.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,8 @@ impl LibraryData {
135135
files: Vec<(FileId, RelativePathBuf, Arc<String>)>,
136136
) -> LibraryData {
137137
let symbol_index = SymbolIndex::for_files(files.par_iter().map(|(file_id, _, text)| {
138-
let file = SourceFile::parse(text).tree;
139-
(*file_id, file)
138+
let parse = SourceFile::parse(text);
139+
(*file_id, parse)
140140
}));
141141
let mut root_change = RootChange::default();
142142
root_change.added = files

crates/ra_ide_api/src/completion/completion_context.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ impl<'a> CompletionContext<'a> {
4848
) -> Option<CompletionContext<'a>> {
4949
let module = source_binder::module_from_position(db, position);
5050
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()?;
5252
let analyzer =
5353
hir::SourceAnalyzer::new(db, position.file_id, token.parent(), Some(position.offset));
5454
let mut ctx = CompletionContext {
@@ -89,7 +89,7 @@ impl<'a> CompletionContext<'a> {
8989
// actual completion.
9090
let file = {
9191
let edit = AtomTextEdit::insert(offset, "intellijRulezz".to_string());
92-
original_parse.reparse(&edit).tree
92+
original_parse.reparse(&edit).tree().to_owned()
9393
};
9494

9595
// First, let's try to complete a reference to some declaration.
@@ -100,7 +100,7 @@ impl<'a> CompletionContext<'a> {
100100
self.is_param = true;
101101
return;
102102
}
103-
self.classify_name_ref(&original_parse.tree, name_ref);
103+
self.classify_name_ref(original_parse.tree(), name_ref);
104104
}
105105

106106
// Otherwise, see if this is a declaration. We can use heuristics to

0 commit comments

Comments
 (0)