aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_analysis/src/completion.rs10
-rw-r--r--crates/ra_analysis/src/db.rs8
-rw-r--r--crates/ra_analysis/src/descriptors/function/scope.rs6
-rw-r--r--crates/ra_analysis/src/descriptors/module/scope.rs4
-rw-r--r--crates/ra_analysis/src/imp.rs8
-rw-r--r--crates/ra_analysis/src/lib.rs14
-rw-r--r--crates/ra_analysis/src/symbol_index.rs8
-rw-r--r--crates/ra_analysis/src/syntax_ptr.rs6
-rw-r--r--crates/ra_cli/src/main.rs10
-rw-r--r--crates/ra_editor/src/code_actions.rs19
-rw-r--r--crates/ra_editor/src/extend_selection.rs6
-rw-r--r--crates/ra_editor/src/folding_ranges.rs6
-rw-r--r--crates/ra_editor/src/lib.rs18
-rw-r--r--crates/ra_editor/src/symbols.rs10
-rw-r--r--crates/ra_editor/src/test_utils.rs14
-rw-r--r--crates/ra_editor/src/typing.rs16
-rw-r--r--crates/ra_lsp_server/src/conv.rs4
-rw-r--r--crates/ra_syntax/src/lib.rs22
-rw-r--r--crates/ra_syntax/src/reparsing.rs8
-rw-r--r--crates/ra_syntax/src/utils.rs4
-rw-r--r--crates/ra_syntax/src/validation.rs10
-rw-r--r--crates/ra_syntax/tests/test.rs4
22 files changed, 115 insertions, 100 deletions
diff --git a/crates/ra_analysis/src/completion.rs b/crates/ra_analysis/src/completion.rs
index 7c3476e5c..689d4c92f 100644
--- a/crates/ra_analysis/src/completion.rs
+++ b/crates/ra_analysis/src/completion.rs
@@ -2,7 +2,7 @@ use ra_editor::find_node_at_offset;
2use ra_syntax::{ 2use ra_syntax::{
3 algo::visit::{visitor, visitor_ctx, Visitor, VisitorCtx}, 3 algo::visit::{visitor, visitor_ctx, Visitor, VisitorCtx},
4 ast::{self, AstChildren, LoopBodyOwner, ModuleItemOwner}, 4 ast::{self, AstChildren, LoopBodyOwner, ModuleItemOwner},
5 AstNode, AtomEdit, File, 5 AstNode, AtomEdit, SourceFileNode,
6 SyntaxKind::*, 6 SyntaxKind::*,
7 SyntaxNodeRef, TextUnit, 7 SyntaxNodeRef, TextUnit,
8}; 8};
@@ -63,7 +63,7 @@ pub(crate) fn resolve_based_completion(
63pub(crate) fn find_target_module( 63pub(crate) fn find_target_module(
64 module_tree: &ModuleTree, 64 module_tree: &ModuleTree,
65 module_id: ModuleId, 65 module_id: ModuleId,
66 file: &File, 66 file: &SourceFileNode,
67 offset: TextUnit, 67 offset: TextUnit,
68) -> Option<ModuleId> { 68) -> Option<ModuleId> {
69 let name_ref: ast::NameRef = find_node_at_offset(file.syntax(), offset)?; 69 let name_ref: ast::NameRef = find_node_at_offset(file.syntax(), offset)?;
@@ -142,7 +142,7 @@ pub(crate) fn scope_completion(
142} 142}
143 143
144fn complete_module_items( 144fn complete_module_items(
145 file: &File, 145 file: &SourceFileNode,
146 items: AstChildren<ast::ModuleItem>, 146 items: AstChildren<ast::ModuleItem>,
147 this_item: Option<ast::NameRef>, 147 this_item: Option<ast::NameRef>,
148 acc: &mut Vec<CompletionItem>, 148 acc: &mut Vec<CompletionItem>,
@@ -164,7 +164,7 @@ fn complete_module_items(
164 ); 164 );
165} 165}
166 166
167fn complete_name_ref(file: &File, name_ref: ast::NameRef, acc: &mut Vec<CompletionItem>) { 167fn complete_name_ref(file: &SourceFileNode, name_ref: ast::NameRef, acc: &mut Vec<CompletionItem>) {
168 if !is_node::<ast::Path>(name_ref.syntax()) { 168 if !is_node::<ast::Path>(name_ref.syntax()) {
169 return; 169 return;
170 } 170 }
@@ -239,7 +239,7 @@ fn is_node<'a, N: AstNode<'a>>(node: SyntaxNodeRef<'a>) -> bool {
239} 239}
240 240
241fn complete_expr_keywords( 241fn complete_expr_keywords(
242 file: &File, 242 file: &SourceFileNode,
243 fn_def: ast::FnDef, 243 fn_def: ast::FnDef,
244 name_ref: ast::NameRef, 244 name_ref: ast::NameRef,
245 acc: &mut Vec<CompletionItem>, 245 acc: &mut Vec<CompletionItem>,
diff --git a/crates/ra_analysis/src/db.rs b/crates/ra_analysis/src/db.rs
index 627512553..194f1a6b0 100644
--- a/crates/ra_analysis/src/db.rs
+++ b/crates/ra_analysis/src/db.rs
@@ -1,7 +1,7 @@
1use std::sync::Arc; 1use std::sync::Arc;
2 2
3use ra_editor::LineIndex; 3use ra_editor::LineIndex;
4use ra_syntax::{File, SyntaxNode}; 4use ra_syntax::{SourceFileNode, SyntaxNode};
5use salsa::{self, Database}; 5use salsa::{self, Database};
6 6
7use crate::{ 7use crate::{
@@ -85,7 +85,7 @@ salsa::database_storage! {
85 85
86salsa::query_group! { 86salsa::query_group! {
87 pub(crate) trait SyntaxDatabase: crate::input::FilesDatabase { 87 pub(crate) trait SyntaxDatabase: crate::input::FilesDatabase {
88 fn file_syntax(file_id: FileId) -> File { 88 fn file_syntax(file_id: FileId) -> SourceFileNode {
89 type FileSyntaxQuery; 89 type FileSyntaxQuery;
90 } 90 }
91 fn file_lines(file_id: FileId) -> Arc<LineIndex> { 91 fn file_lines(file_id: FileId) -> Arc<LineIndex> {
@@ -103,9 +103,9 @@ salsa::query_group! {
103 } 103 }
104} 104}
105 105
106fn file_syntax(db: &impl SyntaxDatabase, file_id: FileId) -> File { 106fn file_syntax(db: &impl SyntaxDatabase, file_id: FileId) -> SourceFileNode {
107 let text = db.file_text(file_id); 107 let text = db.file_text(file_id);
108 File::parse(&*text) 108 SourceFileNode::parse(&*text)
109} 109}
110fn file_lines(db: &impl SyntaxDatabase, file_id: FileId) -> Arc<LineIndex> { 110fn file_lines(db: &impl SyntaxDatabase, file_id: FileId) -> Arc<LineIndex> {
111 let text = db.file_text(file_id); 111 let text = db.file_text(file_id);
diff --git a/crates/ra_analysis/src/descriptors/function/scope.rs b/crates/ra_analysis/src/descriptors/function/scope.rs
index 62b46ffba..bbe16947c 100644
--- a/crates/ra_analysis/src/descriptors/function/scope.rs
+++ b/crates/ra_analysis/src/descriptors/function/scope.rs
@@ -272,7 +272,7 @@ pub fn resolve_local_name<'a>(
272#[cfg(test)] 272#[cfg(test)]
273mod tests { 273mod tests {
274 use ra_editor::find_node_at_offset; 274 use ra_editor::find_node_at_offset;
275 use ra_syntax::File; 275 use ra_syntax::SourceFileNode;
276 use test_utils::extract_offset; 276 use test_utils::extract_offset;
277 277
278 use super::*; 278 use super::*;
@@ -287,7 +287,7 @@ mod tests {
287 buf.push_str(&code[off..]); 287 buf.push_str(&code[off..]);
288 buf 288 buf
289 }; 289 };
290 let file = File::parse(&code); 290 let file = SourceFileNode::parse(&code);
291 let marker: ast::PathExpr = find_node_at_offset(file.syntax(), off).unwrap(); 291 let marker: ast::PathExpr = find_node_at_offset(file.syntax(), off).unwrap();
292 let fn_def: ast::FnDef = find_node_at_offset(file.syntax(), off).unwrap(); 292 let fn_def: ast::FnDef = find_node_at_offset(file.syntax(), off).unwrap();
293 let scopes = FnScopes::new(fn_def); 293 let scopes = FnScopes::new(fn_def);
@@ -376,7 +376,7 @@ mod tests {
376 376
377 fn do_check_local_name(code: &str, expected_offset: u32) { 377 fn do_check_local_name(code: &str, expected_offset: u32) {
378 let (off, code) = extract_offset(code); 378 let (off, code) = extract_offset(code);
379 let file = File::parse(&code); 379 let file = SourceFileNode::parse(&code);
380 let fn_def: ast::FnDef = find_node_at_offset(file.syntax(), off).unwrap(); 380 let fn_def: ast::FnDef = find_node_at_offset(file.syntax(), off).unwrap();
381 let name_ref: ast::NameRef = find_node_at_offset(file.syntax(), off).unwrap(); 381 let name_ref: ast::NameRef = find_node_at_offset(file.syntax(), off).unwrap();
382 382
diff --git a/crates/ra_analysis/src/descriptors/module/scope.rs b/crates/ra_analysis/src/descriptors/module/scope.rs
index 215b31f8e..5fcbc3cb0 100644
--- a/crates/ra_analysis/src/descriptors/module/scope.rs
+++ b/crates/ra_analysis/src/descriptors/module/scope.rs
@@ -95,10 +95,10 @@ fn collect_imports(tree: ast::UseTree, acc: &mut Vec<Entry>) {
95#[cfg(test)] 95#[cfg(test)]
96mod tests { 96mod tests {
97 use super::*; 97 use super::*;
98 use ra_syntax::{ast::ModuleItemOwner, File}; 98 use ra_syntax::{ast::ModuleItemOwner, SourceFileNode};
99 99
100 fn do_check(code: &str, expected: &[&str]) { 100 fn do_check(code: &str, expected: &[&str]) {
101 let file = File::parse(&code); 101 let file = SourceFileNode::parse(&code);
102 let scope = ModuleScope::new(file.ast().items()); 102 let scope = ModuleScope::new(file.ast().items());
103 let actual = scope.entries.iter().map(|it| it.name()).collect::<Vec<_>>(); 103 let actual = scope.entries.iter().map(|it| it.name()).collect::<Vec<_>>();
104 assert_eq!(expected, actual.as_slice()); 104 assert_eq!(expected, actual.as_slice());
diff --git a/crates/ra_analysis/src/imp.rs b/crates/ra_analysis/src/imp.rs
index 166f1484f..00c4a08bd 100644
--- a/crates/ra_analysis/src/imp.rs
+++ b/crates/ra_analysis/src/imp.rs
@@ -7,7 +7,7 @@ use std::{
7use ra_editor::{self, find_node_at_offset, FileSymbol, LineIndex, LocalEdit}; 7use ra_editor::{self, find_node_at_offset, FileSymbol, LineIndex, LocalEdit};
8use ra_syntax::{ 8use ra_syntax::{
9 ast::{self, ArgListOwner, Expr, NameOwner}, 9 ast::{self, ArgListOwner, Expr, NameOwner},
10 AstNode, File, SmolStr, 10 AstNode, SourceFileNode, SmolStr,
11 SyntaxKind::*, 11 SyntaxKind::*,
12 SyntaxNodeRef, TextRange, TextUnit, 12 SyntaxNodeRef, TextRange, TextUnit,
13}; 13};
@@ -27,7 +27,7 @@ use crate::{
27 input::{FilesDatabase, SourceRoot, SourceRootId, WORKSPACE}, 27 input::{FilesDatabase, SourceRoot, SourceRootId, WORKSPACE},
28 symbol_index::SymbolIndex, 28 symbol_index::SymbolIndex,
29 AnalysisChange, Cancelable, CrateGraph, CrateId, Diagnostic, FileId, FileResolver, 29 AnalysisChange, Cancelable, CrateGraph, CrateId, Diagnostic, FileId, FileResolver,
30 FileSystemEdit, FilePosition, Query, SourceChange, SourceFileEdit, 30 FileSystemEdit, FilePosition, Query, SourceChange, SourceFileNodeEdit,
31}; 31};
32 32
33#[derive(Clone, Debug)] 33#[derive(Clone, Debug)]
@@ -180,7 +180,7 @@ impl fmt::Debug for AnalysisImpl {
180} 180}
181 181
182impl AnalysisImpl { 182impl AnalysisImpl {
183 pub fn file_syntax(&self, file_id: FileId) -> File { 183 pub fn file_syntax(&self, file_id: FileId) -> SourceFileNode {
184 self.db.file_syntax(file_id) 184 self.db.file_syntax(file_id)
185 } 185 }
186 pub fn file_line_index(&self, file_id: FileId) -> Arc<LineIndex> { 186 pub fn file_line_index(&self, file_id: FileId) -> Arc<LineIndex> {
@@ -562,7 +562,7 @@ impl AnalysisImpl {
562 562
563impl SourceChange { 563impl SourceChange {
564 pub(crate) fn from_local_edit(file_id: FileId, label: &str, edit: LocalEdit) -> SourceChange { 564 pub(crate) fn from_local_edit(file_id: FileId, label: &str, edit: LocalEdit) -> SourceChange {
565 let file_edit = SourceFileEdit { 565 let file_edit = SourceFileNodeEdit {
566 file_id, 566 file_id,
567 edits: edit.edit.into_atoms(), 567 edits: edit.edit.into_atoms(),
568 }; 568 };
diff --git a/crates/ra_analysis/src/lib.rs b/crates/ra_analysis/src/lib.rs
index 9475c938d..ad0273edc 100644
--- a/crates/ra_analysis/src/lib.rs
+++ b/crates/ra_analysis/src/lib.rs
@@ -20,7 +20,7 @@ pub mod mock_analysis;
20 20
21use std::{fmt, sync::Arc}; 21use std::{fmt, sync::Arc};
22 22
23use ra_syntax::{AtomEdit, File, TextRange, TextUnit}; 23use ra_syntax::{AtomEdit, SourceFileNode, TextRange, TextUnit};
24use rayon::prelude::*; 24use rayon::prelude::*;
25use relative_path::RelativePathBuf; 25use relative_path::RelativePathBuf;
26 26
@@ -128,13 +128,13 @@ pub struct FilePosition {
128#[derive(Debug)] 128#[derive(Debug)]
129pub struct SourceChange { 129pub struct SourceChange {
130 pub label: String, 130 pub label: String,
131 pub source_file_edits: Vec<SourceFileEdit>, 131 pub source_file_edits: Vec<SourceFileNodeEdit>,
132 pub file_system_edits: Vec<FileSystemEdit>, 132 pub file_system_edits: Vec<FileSystemEdit>,
133 pub cursor_position: Option<FilePosition>, 133 pub cursor_position: Option<FilePosition>,
134} 134}
135 135
136#[derive(Debug)] 136#[derive(Debug)]
137pub struct SourceFileEdit { 137pub struct SourceFileNodeEdit {
138 pub file_id: FileId, 138 pub file_id: FileId,
139 pub edits: Vec<AtomEdit>, 139 pub edits: Vec<AtomEdit>,
140} 140}
@@ -204,16 +204,16 @@ pub struct Analysis {
204} 204}
205 205
206impl Analysis { 206impl Analysis {
207 pub fn file_syntax(&self, file_id: FileId) -> File { 207 pub fn file_syntax(&self, file_id: FileId) -> SourceFileNode {
208 self.imp.file_syntax(file_id).clone() 208 self.imp.file_syntax(file_id).clone()
209 } 209 }
210 pub fn file_line_index(&self, file_id: FileId) -> Arc<LineIndex> { 210 pub fn file_line_index(&self, file_id: FileId) -> Arc<LineIndex> {
211 self.imp.file_line_index(file_id) 211 self.imp.file_line_index(file_id)
212 } 212 }
213 pub fn extend_selection(&self, file: &File, range: TextRange) -> TextRange { 213 pub fn extend_selection(&self, file: &SourceFileNode, range: TextRange) -> TextRange {
214 ra_editor::extend_selection(file, range).unwrap_or(range) 214 ra_editor::extend_selection(file, range).unwrap_or(range)
215 } 215 }
216 pub fn matching_brace(&self, file: &File, offset: TextUnit) -> Option<TextUnit> { 216 pub fn matching_brace(&self, file: &SourceFileNode, offset: TextUnit) -> Option<TextUnit> {
217 ra_editor::matching_brace(file, offset) 217 ra_editor::matching_brace(file, offset)
218 } 218 }
219 pub fn syntax_tree(&self, file_id: FileId) -> String { 219 pub fn syntax_tree(&self, file_id: FileId) -> String {
@@ -309,7 +309,7 @@ pub struct LibraryData {
309impl LibraryData { 309impl LibraryData {
310 pub fn prepare(files: Vec<(FileId, String)>, file_resolver: Arc<FileResolver>) -> LibraryData { 310 pub fn prepare(files: Vec<(FileId, String)>, file_resolver: Arc<FileResolver>) -> LibraryData {
311 let symbol_index = SymbolIndex::for_files(files.par_iter().map(|(file_id, text)| { 311 let symbol_index = SymbolIndex::for_files(files.par_iter().map(|(file_id, text)| {
312 let file = File::parse(text); 312 let file = SourceFileNode::parse(text);
313 (*file_id, file) 313 (*file_id, file)
314 })); 314 }));
315 LibraryData { 315 LibraryData {
diff --git a/crates/ra_analysis/src/symbol_index.rs b/crates/ra_analysis/src/symbol_index.rs
index b57ad5d33..3a0667ecd 100644
--- a/crates/ra_analysis/src/symbol_index.rs
+++ b/crates/ra_analysis/src/symbol_index.rs
@@ -6,7 +6,7 @@ use std::{
6use fst::{self, Streamer}; 6use fst::{self, Streamer};
7use ra_editor::{file_symbols, FileSymbol}; 7use ra_editor::{file_symbols, FileSymbol};
8use ra_syntax::{ 8use ra_syntax::{
9 File, 9 SourceFileNode,
10 SyntaxKind::{self, *}, 10 SyntaxKind::{self, *},
11}; 11};
12use rayon::prelude::*; 12use rayon::prelude::*;
@@ -34,7 +34,9 @@ impl Hash for SymbolIndex {
34} 34}
35 35
36impl SymbolIndex { 36impl SymbolIndex {
37 pub(crate) fn for_files(files: impl ParallelIterator<Item = (FileId, File)>) -> SymbolIndex { 37 pub(crate) fn for_files(
38 files: impl ParallelIterator<Item = (FileId, SourceFileNode)>,
39 ) -> SymbolIndex {
38 let mut symbols = files 40 let mut symbols = files
39 .flat_map(|(file_id, file)| { 41 .flat_map(|(file_id, file)| {
40 file_symbols(&file) 42 file_symbols(&file)
@@ -51,7 +53,7 @@ impl SymbolIndex {
51 SymbolIndex { symbols, map } 53 SymbolIndex { symbols, map }
52 } 54 }
53 55
54 pub(crate) fn for_file(file_id: FileId, file: File) -> SymbolIndex { 56 pub(crate) fn for_file(file_id: FileId, file: SourceFileNode) -> SymbolIndex {
55 SymbolIndex::for_files(rayon::iter::once((file_id, file))) 57 SymbolIndex::for_files(rayon::iter::once((file_id, file)))
56 } 58 }
57} 59}
diff --git a/crates/ra_analysis/src/syntax_ptr.rs b/crates/ra_analysis/src/syntax_ptr.rs
index 4afb1fc93..e45934ce0 100644
--- a/crates/ra_analysis/src/syntax_ptr.rs
+++ b/crates/ra_analysis/src/syntax_ptr.rs
@@ -1,4 +1,4 @@
1use ra_syntax::{File, SyntaxKind, SyntaxNode, SyntaxNodeRef, TextRange}; 1use ra_syntax::{SourceFileNode, SyntaxKind, SyntaxNode, SyntaxNodeRef, TextRange};
2 2
3use crate::db::SyntaxDatabase; 3use crate::db::SyntaxDatabase;
4use crate::FileId; 4use crate::FileId;
@@ -43,7 +43,7 @@ impl LocalSyntaxPtr {
43 } 43 }
44 } 44 }
45 45
46 pub(crate) fn resolve(self, file: &File) -> SyntaxNode { 46 pub(crate) fn resolve(self, file: &SourceFileNode) -> SyntaxNode {
47 let mut curr = file.syntax(); 47 let mut curr = file.syntax();
48 loop { 48 loop {
49 if curr.range() == self.range && curr.kind() == self.kind { 49 if curr.range() == self.range && curr.kind() == self.kind {
@@ -67,7 +67,7 @@ impl LocalSyntaxPtr {
67#[test] 67#[test]
68fn test_local_syntax_ptr() { 68fn test_local_syntax_ptr() {
69 use ra_syntax::{ast, AstNode}; 69 use ra_syntax::{ast, AstNode};
70 let file = File::parse("struct Foo { f: u32, }"); 70 let file = SourceFileNode::parse("struct Foo { f: u32, }");
71 let field = file 71 let field = file
72 .syntax() 72 .syntax()
73 .descendants() 73 .descendants()
diff --git a/crates/ra_cli/src/main.rs b/crates/ra_cli/src/main.rs
index 239d846b3..5ca86df4d 100644
--- a/crates/ra_cli/src/main.rs
+++ b/crates/ra_cli/src/main.rs
@@ -11,7 +11,7 @@ use std::{fs, io::Read, path::Path, time::Instant};
11use clap::{App, Arg, SubCommand}; 11use clap::{App, Arg, SubCommand};
12use join_to_string::join; 12use join_to_string::join;
13use ra_editor::{extend_selection, file_structure, syntax_tree}; 13use ra_editor::{extend_selection, file_structure, syntax_tree};
14use ra_syntax::{File, TextRange}; 14use ra_syntax::{SourceFileNode, TextRange};
15use tools::collect_tests; 15use tools::collect_tests;
16 16
17type Result<T> = ::std::result::Result<T, failure::Error>; 17type Result<T> = ::std::result::Result<T, failure::Error>;
@@ -79,9 +79,9 @@ fn main() -> Result<()> {
79 Ok(()) 79 Ok(())
80} 80}
81 81
82fn file() -> Result<File> { 82fn file() -> Result<SourceFileNode> {
83 let text = read_stdin()?; 83 let text = read_stdin()?;
84 Ok(File::parse(&text)) 84 Ok(SourceFileNode::parse(&text))
85} 85}
86 86
87fn read_stdin() -> Result<String> { 87fn read_stdin() -> Result<String> {
@@ -100,12 +100,12 @@ fn render_test(file: &Path, line: usize) -> Result<(String, String)> {
100 None => bail!("No test found at line {} at {}", line, file.display()), 100 None => bail!("No test found at line {} at {}", line, file.display()),
101 Some((_start_line, test)) => test, 101 Some((_start_line, test)) => test,
102 }; 102 };
103 let file = File::parse(&test.text); 103 let file = SourceFileNode::parse(&test.text);
104 let tree = syntax_tree(&file); 104 let tree = syntax_tree(&file);
105 Ok((test.text, tree)) 105 Ok((test.text, tree))
106} 106}
107 107
108fn selections(file: &File, start: u32, end: u32) -> String { 108fn selections(file: &SourceFileNode, start: u32, end: u32) -> String {
109 let mut ranges = Vec::new(); 109 let mut ranges = Vec::new();
110 let mut cur = Some(TextRange::from_to((start - 1).into(), (end - 1).into())); 110 let mut cur = Some(TextRange::from_to((start - 1).into(), (end - 1).into()));
111 while let Some(r) = cur { 111 while let Some(r) = cur {
diff --git a/crates/ra_editor/src/code_actions.rs b/crates/ra_editor/src/code_actions.rs
index ef6df0d53..0139b19d3 100644
--- a/crates/ra_editor/src/code_actions.rs
+++ b/crates/ra_editor/src/code_actions.rs
@@ -3,7 +3,7 @@ use join_to_string::join;
3use ra_syntax::{ 3use ra_syntax::{
4 algo::{find_covering_node, find_leaf_at_offset}, 4 algo::{find_covering_node, find_leaf_at_offset},
5 ast::{self, AstNode, AttrsOwner, NameOwner, TypeParamsOwner}, 5 ast::{self, AstNode, AttrsOwner, NameOwner, TypeParamsOwner},
6 Direction, File, 6 Direction, SourceFileNode,
7 SyntaxKind::{COMMA, WHITESPACE}, 7 SyntaxKind::{COMMA, WHITESPACE},
8 SyntaxNodeRef, TextRange, TextUnit, 8 SyntaxNodeRef, TextRange, TextUnit,
9}; 9};
@@ -16,7 +16,10 @@ pub struct LocalEdit {
16 pub cursor_position: Option<TextUnit>, 16 pub cursor_position: Option<TextUnit>,
17} 17}
18 18
19pub fn flip_comma<'a>(file: &'a File, offset: TextUnit) -> Option<impl FnOnce() -> LocalEdit + 'a> { 19pub fn flip_comma<'a>(
20 file: &'a SourceFileNode,
21 offset: TextUnit,
22) -> Option<impl FnOnce() -> LocalEdit + 'a> {
20 let syntax = file.syntax(); 23 let syntax = file.syntax();
21 24
22 let comma = find_leaf_at_offset(syntax, offset).find(|leaf| leaf.kind() == COMMA)?; 25 let comma = find_leaf_at_offset(syntax, offset).find(|leaf| leaf.kind() == COMMA)?;
@@ -33,7 +36,10 @@ pub fn flip_comma<'a>(file: &'a File, offset: TextUnit) -> Option<impl FnOnce()
33 }) 36 })
34} 37}
35 38
36pub fn add_derive<'a>(file: &'a File, offset: TextUnit) -> Option<impl FnOnce() -> LocalEdit + 'a> { 39pub fn add_derive<'a>(
40 file: &'a SourceFileNode,
41 offset: TextUnit,
42) -> Option<impl FnOnce() -> LocalEdit + 'a> {
37 let nominal = find_node_at_offset::<ast::NominalDef>(file.syntax(), offset)?; 43 let nominal = find_node_at_offset::<ast::NominalDef>(file.syntax(), offset)?;
38 Some(move || { 44 Some(move || {
39 let derive_attr = nominal 45 let derive_attr = nominal
@@ -58,7 +64,10 @@ pub fn add_derive<'a>(file: &'a File, offset: TextUnit) -> Option<impl FnOnce()
58 }) 64 })
59} 65}
60 66
61pub fn add_impl<'a>(file: &'a File, offset: TextUnit) -> Option<impl FnOnce() -> LocalEdit + 'a> { 67pub fn add_impl<'a>(
68 file: &'a SourceFileNode,
69 offset: TextUnit,
70) -> Option<impl FnOnce() -> LocalEdit + 'a> {
62 let nominal = find_node_at_offset::<ast::NominalDef>(file.syntax(), offset)?; 71 let nominal = find_node_at_offset::<ast::NominalDef>(file.syntax(), offset)?;
63 let name = nominal.name()?; 72 let name = nominal.name()?;
64 73
@@ -98,7 +107,7 @@ pub fn add_impl<'a>(file: &'a File, offset: TextUnit) -> Option<impl FnOnce() ->
98} 107}
99 108
100pub fn introduce_variable<'a>( 109pub fn introduce_variable<'a>(
101 file: &'a File, 110 file: &'a SourceFileNode,
102 range: TextRange, 111 range: TextRange,
103) -> Option<impl FnOnce() -> LocalEdit + 'a> { 112) -> Option<impl FnOnce() -> LocalEdit + 'a> {
104 let node = find_covering_node(file.syntax(), range); 113 let node = find_covering_node(file.syntax(), range);
diff --git a/crates/ra_editor/src/extend_selection.rs b/crates/ra_editor/src/extend_selection.rs
index 9d8df25c3..8f11d5364 100644
--- a/crates/ra_editor/src/extend_selection.rs
+++ b/crates/ra_editor/src/extend_selection.rs
@@ -1,11 +1,11 @@
1use ra_syntax::{ 1use ra_syntax::{
2 algo::{find_covering_node, find_leaf_at_offset, LeafAtOffset}, 2 algo::{find_covering_node, find_leaf_at_offset, LeafAtOffset},
3 Direction, File, 3 Direction, SourceFileNode,
4 SyntaxKind::*, 4 SyntaxKind::*,
5 SyntaxNodeRef, TextRange, TextUnit, 5 SyntaxNodeRef, TextRange, TextUnit,
6}; 6};
7 7
8pub fn extend_selection(file: &File, range: TextRange) -> Option<TextRange> { 8pub fn extend_selection(file: &SourceFileNode, range: TextRange) -> Option<TextRange> {
9 let syntax = file.syntax(); 9 let syntax = file.syntax();
10 extend(syntax.borrowed(), range) 10 extend(syntax.borrowed(), range)
11} 11}
@@ -120,7 +120,7 @@ mod tests {
120 120
121 fn do_check(before: &str, afters: &[&str]) { 121 fn do_check(before: &str, afters: &[&str]) {
122 let (cursor, before) = extract_offset(before); 122 let (cursor, before) = extract_offset(before);
123 let file = File::parse(&before); 123 let file = SourceFileNode::parse(&before);
124 let mut range = TextRange::offset_len(cursor, 0.into()); 124 let mut range = TextRange::offset_len(cursor, 0.into());
125 for &after in afters { 125 for &after in afters {
126 range = extend_selection(&file, range).unwrap(); 126 range = extend_selection(&file, range).unwrap();
diff --git a/crates/ra_editor/src/folding_ranges.rs b/crates/ra_editor/src/folding_ranges.rs
index 0803c8891..2a8fa3cda 100644
--- a/crates/ra_editor/src/folding_ranges.rs
+++ b/crates/ra_editor/src/folding_ranges.rs
@@ -1,7 +1,7 @@
1use rustc_hash::FxHashSet; 1use rustc_hash::FxHashSet;
2 2
3use ra_syntax::{ 3use ra_syntax::{
4 ast, AstNode, Direction, File, 4 ast, AstNode, Direction, SourceFileNode,
5 SyntaxKind::{self, *}, 5 SyntaxKind::{self, *},
6 SyntaxNodeRef, TextRange, 6 SyntaxNodeRef, TextRange,
7}; 7};
@@ -18,7 +18,7 @@ pub struct Fold {
18 pub kind: FoldKind, 18 pub kind: FoldKind,
19} 19}
20 20
21pub fn folding_ranges(file: &File) -> Vec<Fold> { 21pub fn folding_ranges(file: &SourceFileNode) -> Vec<Fold> {
22 let mut res = vec![]; 22 let mut res = vec![];
23 let mut visited_comments = FxHashSet::default(); 23 let mut visited_comments = FxHashSet::default();
24 let mut visited_imports = FxHashSet::default(); 24 let mut visited_imports = FxHashSet::default();
@@ -171,7 +171,7 @@ mod tests {
171 171
172 fn do_check(text: &str, fold_kinds: &[FoldKind]) { 172 fn do_check(text: &str, fold_kinds: &[FoldKind]) {
173 let (ranges, text) = extract_ranges(text); 173 let (ranges, text) = extract_ranges(text);
174 let file = File::parse(&text); 174 let file = SourceFileNode::parse(&text);
175 let folds = folding_ranges(&file); 175 let folds = folding_ranges(&file);
176 176
177 assert_eq!( 177 assert_eq!(
diff --git a/crates/ra_editor/src/lib.rs b/crates/ra_editor/src/lib.rs
index f92181b86..ff4e8303d 100644
--- a/crates/ra_editor/src/lib.rs
+++ b/crates/ra_editor/src/lib.rs
@@ -30,7 +30,7 @@ pub use ra_syntax::AtomEdit;
30use ra_syntax::{ 30use ra_syntax::{
31 algo::find_leaf_at_offset, 31 algo::find_leaf_at_offset,
32 ast::{self, AstNode, NameOwner}, 32 ast::{self, AstNode, NameOwner},
33 File, 33 SourceFileNode,
34 Location, 34 Location,
35 SyntaxKind::{self, *}, 35 SyntaxKind::{self, *},
36 SyntaxNodeRef, TextRange, TextUnit, 36 SyntaxNodeRef, TextRange, TextUnit,
@@ -60,7 +60,7 @@ pub enum RunnableKind {
60 Bin, 60 Bin,
61} 61}
62 62
63pub fn matching_brace(file: &File, offset: TextUnit) -> Option<TextUnit> { 63pub fn matching_brace(file: &SourceFileNode, offset: TextUnit) -> Option<TextUnit> {
64 const BRACES: &[SyntaxKind] = &[ 64 const BRACES: &[SyntaxKind] = &[
65 L_CURLY, R_CURLY, L_BRACK, R_BRACK, L_PAREN, R_PAREN, L_ANGLE, R_ANGLE, 65 L_CURLY, R_CURLY, L_BRACK, R_BRACK, L_PAREN, R_PAREN, L_ANGLE, R_ANGLE,
66 ]; 66 ];
@@ -78,7 +78,7 @@ pub fn matching_brace(file: &File, offset: TextUnit) -> Option<TextUnit> {
78 Some(matching_node.range().start()) 78 Some(matching_node.range().start())
79} 79}
80 80
81pub fn highlight(file: &File) -> Vec<HighlightedRange> { 81pub fn highlight(file: &SourceFileNode) -> Vec<HighlightedRange> {
82 let mut res = Vec::new(); 82 let mut res = Vec::new();
83 for node in file.syntax().descendants() { 83 for node in file.syntax().descendants() {
84 let tag = match node.kind() { 84 let tag = match node.kind() {
@@ -100,7 +100,7 @@ pub fn highlight(file: &File) -> Vec<HighlightedRange> {
100 res 100 res
101} 101}
102 102
103pub fn diagnostics(file: &File) -> Vec<Diagnostic> { 103pub fn diagnostics(file: &SourceFileNode) -> Vec<Diagnostic> {
104 fn location_to_range(location: Location) -> TextRange { 104 fn location_to_range(location: Location) -> TextRange {
105 match location { 105 match location {
106 Location::Offset(offset) => TextRange::offset_len(offset, 1.into()), 106 Location::Offset(offset) => TextRange::offset_len(offset, 1.into()),
@@ -117,11 +117,11 @@ pub fn diagnostics(file: &File) -> Vec<Diagnostic> {
117 .collect() 117 .collect()
118} 118}
119 119
120pub fn syntax_tree(file: &File) -> String { 120pub fn syntax_tree(file: &SourceFileNode) -> String {
121 ::ra_syntax::utils::dump_tree(file.syntax()) 121 ::ra_syntax::utils::dump_tree(file.syntax())
122} 122}
123 123
124pub fn runnables(file: &File) -> Vec<Runnable> { 124pub fn runnables(file: &SourceFileNode) -> Vec<Runnable> {
125 file.syntax() 125 file.syntax()
126 .descendants() 126 .descendants()
127 .filter_map(ast::FnDef::cast) 127 .filter_map(ast::FnDef::cast)
@@ -163,7 +163,7 @@ mod tests {
163 163
164 #[test] 164 #[test]
165 fn test_highlighting() { 165 fn test_highlighting() {
166 let file = File::parse( 166 let file = SourceFileNode::parse(
167 r#" 167 r#"
168// comment 168// comment
169fn main() {} 169fn main() {}
@@ -184,7 +184,7 @@ fn main() {}
184 184
185 #[test] 185 #[test]
186 fn test_runnables() { 186 fn test_runnables() {
187 let file = File::parse( 187 let file = SourceFileNode::parse(
188 r#" 188 r#"
189fn main() {} 189fn main() {}
190 190
@@ -209,7 +209,7 @@ fn test_foo() {}
209 fn test_matching_brace() { 209 fn test_matching_brace() {
210 fn do_check(before: &str, after: &str) { 210 fn do_check(before: &str, after: &str) {
211 let (pos, before) = extract_offset(before); 211 let (pos, before) = extract_offset(before);
212 let file = File::parse(&before); 212 let file = SourceFileNode::parse(&before);
213 let new_pos = match matching_brace(&file, pos) { 213 let new_pos = match matching_brace(&file, pos) {
214 None => pos, 214 None => pos,
215 Some(pos) => pos, 215 Some(pos) => pos,
diff --git a/crates/ra_editor/src/symbols.rs b/crates/ra_editor/src/symbols.rs
index f7681c76f..6d3b0514a 100644
--- a/crates/ra_editor/src/symbols.rs
+++ b/crates/ra_editor/src/symbols.rs
@@ -3,7 +3,7 @@ use crate::TextRange;
3use ra_syntax::{ 3use ra_syntax::{
4 algo::visit::{visitor, Visitor}, 4 algo::visit::{visitor, Visitor},
5 ast::{self, DocCommentsOwner, NameOwner}, 5 ast::{self, DocCommentsOwner, NameOwner},
6 AstNode, File, SmolStr, SyntaxKind, SyntaxNodeRef, WalkEvent, 6 AstNode, SourceFileNode, SmolStr, SyntaxKind, SyntaxNodeRef, WalkEvent,
7}; 7};
8 8
9#[derive(Debug, Clone)] 9#[derive(Debug, Clone)]
@@ -23,7 +23,7 @@ pub struct FileSymbol {
23} 23}
24 24
25impl FileSymbol { 25impl FileSymbol {
26 pub fn docs(&self, file: &File) -> Option<String> { 26 pub fn docs(&self, file: &SourceFileNode) -> Option<String> {
27 file.syntax() 27 file.syntax()
28 .descendants() 28 .descendants()
29 .filter(|node| node.kind() == self.kind && node.range() == self.node_range) 29 .filter(|node| node.kind() == self.kind && node.range() == self.node_range)
@@ -52,7 +52,7 @@ impl FileSymbol {
52 } 52 }
53} 53}
54 54
55pub fn file_symbols(file: &File) -> Vec<FileSymbol> { 55pub fn file_symbols(file: &SourceFileNode) -> Vec<FileSymbol> {
56 file.syntax().descendants().filter_map(to_symbol).collect() 56 file.syntax().descendants().filter_map(to_symbol).collect()
57} 57}
58 58
@@ -77,7 +77,7 @@ fn to_symbol(node: SyntaxNodeRef) -> Option<FileSymbol> {
77 .accept(node)? 77 .accept(node)?
78} 78}
79 79
80pub fn file_structure(file: &File) -> Vec<StructureNode> { 80pub fn file_structure(file: &SourceFileNode) -> Vec<StructureNode> {
81 let mut res = Vec::new(); 81 let mut res = Vec::new();
82 let mut stack = Vec::new(); 82 let mut stack = Vec::new();
83 83
@@ -153,7 +153,7 @@ mod tests {
153 153
154 #[test] 154 #[test]
155 fn test_file_structure() { 155 fn test_file_structure() {
156 let file = File::parse( 156 let file = SourceFileNode::parse(
157 r#" 157 r#"
158struct Foo { 158struct Foo {
159 x: i32 159 x: i32
diff --git a/crates/ra_editor/src/test_utils.rs b/crates/ra_editor/src/test_utils.rs
index bc3d700f6..cbeb6433b 100644
--- a/crates/ra_editor/src/test_utils.rs
+++ b/crates/ra_editor/src/test_utils.rs
@@ -1,10 +1,14 @@
1use crate::LocalEdit; 1use crate::LocalEdit;
2pub use crate::_test_utils::*; 2pub use crate::_test_utils::*;
3use ra_syntax::{File, TextRange, TextUnit}; 3use ra_syntax::{SourceFileNode, TextRange, TextUnit};
4 4
5pub fn check_action<F: Fn(&File, TextUnit) -> Option<LocalEdit>>(before: &str, after: &str, f: F) { 5pub fn check_action<F: Fn(&SourceFileNode, TextUnit) -> Option<LocalEdit>>(
6 before: &str,
7 after: &str,
8 f: F,
9) {
6 let (before_cursor_pos, before) = extract_offset(before); 10 let (before_cursor_pos, before) = extract_offset(before);
7 let file = File::parse(&before); 11 let file = SourceFileNode::parse(&before);
8 let result = f(&file, before_cursor_pos).expect("code action is not applicable"); 12 let result = f(&file, before_cursor_pos).expect("code action is not applicable");
9 let actual = result.edit.apply(&before); 13 let actual = result.edit.apply(&before);
10 let actual_cursor_pos = match result.cursor_position { 14 let actual_cursor_pos = match result.cursor_position {
@@ -15,13 +19,13 @@ pub fn check_action<F: Fn(&File, TextUnit) -> Option<LocalEdit>>(before: &str, a
15 assert_eq_text!(after, &actual); 19 assert_eq_text!(after, &actual);
16} 20}
17 21
18pub fn check_action_range<F: Fn(&File, TextRange) -> Option<LocalEdit>>( 22pub fn check_action_range<F: Fn(&SourceFileNode, TextRange) -> Option<LocalEdit>>(
19 before: &str, 23 before: &str,
20 after: &str, 24 after: &str,
21 f: F, 25 f: F,
22) { 26) {
23 let (range, before) = extract_range(before); 27 let (range, before) = extract_range(before);
24 let file = File::parse(&before); 28 let file = SourceFileNode::parse(&before);
25 let result = f(&file, range).expect("code action is not applicable"); 29 let result = f(&file, range).expect("code action is not applicable");
26 let actual = result.edit.apply(&before); 30 let actual = result.edit.apply(&before);
27 let actual_cursor_pos = match result.cursor_position { 31 let actual_cursor_pos = match result.cursor_position {
diff --git a/crates/ra_editor/src/typing.rs b/crates/ra_editor/src/typing.rs
index 5a457d148..f894d8392 100644
--- a/crates/ra_editor/src/typing.rs
+++ b/crates/ra_editor/src/typing.rs
@@ -4,14 +4,14 @@ use ra_syntax::{
4 algo::{find_covering_node, find_leaf_at_offset, LeafAtOffset}, 4 algo::{find_covering_node, find_leaf_at_offset, LeafAtOffset},
5 ast, 5 ast,
6 text_utils::{contains_offset_nonstrict, intersect}, 6 text_utils::{contains_offset_nonstrict, intersect},
7 AstNode, File, SyntaxKind, 7 AstNode, SourceFileNode, SyntaxKind,
8 SyntaxKind::*, 8 SyntaxKind::*,
9 SyntaxNodeRef, TextRange, TextUnit, 9 SyntaxNodeRef, TextRange, TextUnit,
10}; 10};
11 11
12use crate::{find_node_at_offset, EditBuilder, LocalEdit}; 12use crate::{find_node_at_offset, EditBuilder, LocalEdit};
13 13
14pub fn join_lines(file: &File, range: TextRange) -> LocalEdit { 14pub fn join_lines(file: &SourceFileNode, range: TextRange) -> LocalEdit {
15 let range = if range.is_empty() { 15 let range = if range.is_empty() {
16 let syntax = file.syntax(); 16 let syntax = file.syntax();
17 let text = syntax.text().slice(range.start()..); 17 let text = syntax.text().slice(range.start()..);
@@ -55,7 +55,7 @@ pub fn join_lines(file: &File, range: TextRange) -> LocalEdit {
55 } 55 }
56} 56}
57 57
58pub fn on_enter(file: &File, offset: TextUnit) -> Option<LocalEdit> { 58pub fn on_enter(file: &SourceFileNode, offset: TextUnit) -> Option<LocalEdit> {
59 let comment = find_leaf_at_offset(file.syntax(), offset) 59 let comment = find_leaf_at_offset(file.syntax(), offset)
60 .left_biased() 60 .left_biased()
61 .and_then(ast::Comment::cast)?; 61 .and_then(ast::Comment::cast)?;
@@ -80,7 +80,7 @@ pub fn on_enter(file: &File, offset: TextUnit) -> Option<LocalEdit> {
80 }) 80 })
81} 81}
82 82
83fn node_indent<'a>(file: &'a File, node: SyntaxNodeRef) -> Option<&'a str> { 83fn node_indent<'a>(file: &'a SourceFileNode, node: SyntaxNodeRef) -> Option<&'a str> {
84 let ws = match find_leaf_at_offset(file.syntax(), node.range().start()) { 84 let ws = match find_leaf_at_offset(file.syntax(), node.range().start()) {
85 LeafAtOffset::Between(l, r) => { 85 LeafAtOffset::Between(l, r) => {
86 assert!(r == node); 86 assert!(r == node);
@@ -100,7 +100,7 @@ fn node_indent<'a>(file: &'a File, node: SyntaxNodeRef) -> Option<&'a str> {
100 Some(&text[pos..]) 100 Some(&text[pos..])
101} 101}
102 102
103pub fn on_eq_typed(file: &File, offset: TextUnit) -> Option<LocalEdit> { 103pub fn on_eq_typed(file: &SourceFileNode, offset: TextUnit) -> Option<LocalEdit> {
104 let let_stmt: ast::LetStmt = find_node_at_offset(file.syntax(), offset)?; 104 let let_stmt: ast::LetStmt = find_node_at_offset(file.syntax(), offset)?;
105 if let_stmt.has_semi() { 105 if let_stmt.has_semi() {
106 return None; 106 return None;
@@ -390,7 +390,7 @@ fn foo() {
390 390
391 fn check_join_lines_sel(before: &str, after: &str) { 391 fn check_join_lines_sel(before: &str, after: &str) {
392 let (sel, before) = extract_range(before); 392 let (sel, before) = extract_range(before);
393 let file = File::parse(&before); 393 let file = SourceFileNode::parse(&before);
394 let result = join_lines(&file, sel); 394 let result = join_lines(&file, sel);
395 let actual = result.edit.apply(&before); 395 let actual = result.edit.apply(&before);
396 assert_eq_text!(after, &actual); 396 assert_eq_text!(after, &actual);
@@ -469,7 +469,7 @@ pub fn handle_find_matching_brace() {
469 fn test_on_eq_typed() { 469 fn test_on_eq_typed() {
470 fn do_check(before: &str, after: &str) { 470 fn do_check(before: &str, after: &str) {
471 let (offset, before) = extract_offset(before); 471 let (offset, before) = extract_offset(before);
472 let file = File::parse(&before); 472 let file = SourceFileNode::parse(&before);
473 let result = on_eq_typed(&file, offset).unwrap(); 473 let result = on_eq_typed(&file, offset).unwrap();
474 let actual = result.edit.apply(&before); 474 let actual = result.edit.apply(&before);
475 assert_eq_text!(after, &actual); 475 assert_eq_text!(after, &actual);
@@ -513,7 +513,7 @@ fn foo() {
513 fn test_on_enter() { 513 fn test_on_enter() {
514 fn apply_on_enter(before: &str) -> Option<String> { 514 fn apply_on_enter(before: &str) -> Option<String> {
515 let (offset, before) = extract_offset(before); 515 let (offset, before) = extract_offset(before);
516 let file = File::parse(&before); 516 let file = SourceFileNode::parse(&before);
517 let result = on_enter(&file, offset)?; 517 let result = on_enter(&file, offset)?;
518 let actual = result.edit.apply(&before); 518 let actual = result.edit.apply(&before);
519 let actual = add_cursor(&actual, result.cursor_position.unwrap()); 519 let actual = add_cursor(&actual, result.cursor_position.unwrap());
diff --git a/crates/ra_lsp_server/src/conv.rs b/crates/ra_lsp_server/src/conv.rs
index fa04f4b00..e5a2449c2 100644
--- a/crates/ra_lsp_server/src/conv.rs
+++ b/crates/ra_lsp_server/src/conv.rs
@@ -2,7 +2,7 @@ use languageserver_types::{
2 Location, Position, Range, SymbolKind, TextDocumentEdit, TextDocumentIdentifier, 2 Location, Position, Range, SymbolKind, TextDocumentEdit, TextDocumentIdentifier,
3 TextDocumentItem, TextDocumentPositionParams, TextEdit, Url, VersionedTextDocumentIdentifier, 3 TextDocumentItem, TextDocumentPositionParams, TextEdit, Url, VersionedTextDocumentIdentifier,
4}; 4};
5use ra_analysis::{FileId, FileSystemEdit, SourceChange, SourceFileEdit, FilePosition}; 5use ra_analysis::{FileId, FileSystemEdit, SourceChange, SourceFileNodeEdit, FilePosition};
6use ra_editor::{AtomEdit, Edit, LineCol, LineIndex}; 6use ra_editor::{AtomEdit, Edit, LineCol, LineIndex};
7use ra_syntax::{SyntaxKind, TextRange, TextUnit}; 7use ra_syntax::{SyntaxKind, TextRange, TextUnit};
8 8
@@ -257,7 +257,7 @@ fn translate_offset_with_edit(
257 } 257 }
258} 258}
259 259
260impl TryConvWith for SourceFileEdit { 260impl TryConvWith for SourceFileNodeEdit {
261 type Ctx = ServerWorld; 261 type Ctx = ServerWorld;
262 type Output = TextDocumentEdit; 262 type Output = TextDocumentEdit;
263 fn try_conv_with(self, world: &ServerWorld) -> Result<TextDocumentEdit> { 263 fn try_conv_with(self, world: &ServerWorld) -> Result<TextDocumentEdit> {
diff --git a/crates/ra_syntax/src/lib.rs b/crates/ra_syntax/src/lib.rs
index 54012b7b6..9f8066c70 100644
--- a/crates/ra_syntax/src/lib.rs
+++ b/crates/ra_syntax/src/lib.rs
@@ -61,12 +61,12 @@ pub use crate::{
61 61
62use crate::yellow::GreenNode; 62use crate::yellow::GreenNode;
63 63
64// TODO: pick a single name for everything. SourceFile maybe? 64// TODO: pick a single name for everything. SourceFileNode maybe?
65/// File represents a parse tree for a single Rust file. 65/// File represents a parse tree for a single Rust file.
66pub type File = ast::RootNode; 66pub type SourceFileNode = ast::RootNode;
67 67
68impl File { 68impl SourceFileNode {
69 fn new(green: GreenNode, errors: Vec<SyntaxError>) -> File { 69 fn new(green: GreenNode, errors: Vec<SyntaxError>) -> SourceFileNode {
70 let root = SyntaxNode::new(green, errors); 70 let root = SyntaxNode::new(green, errors);
71 if cfg!(debug_assertions) { 71 if cfg!(debug_assertions) {
72 utils::validate_block_structure(root.borrowed()); 72 utils::validate_block_structure(root.borrowed());
@@ -74,24 +74,24 @@ impl File {
74 assert_eq!(root.kind(), SyntaxKind::ROOT); 74 assert_eq!(root.kind(), SyntaxKind::ROOT);
75 ast::RootNode { syntax: root } 75 ast::RootNode { syntax: root }
76 } 76 }
77 pub fn parse(text: &str) -> File { 77 pub fn parse(text: &str) -> SourceFileNode {
78 let tokens = tokenize(&text); 78 let tokens = tokenize(&text);
79 let (green, errors) = 79 let (green, errors) =
80 parser_impl::parse_with(yellow::GreenBuilder::new(), text, &tokens, grammar::root); 80 parser_impl::parse_with(yellow::GreenBuilder::new(), text, &tokens, grammar::root);
81 File::new(green, errors) 81 SourceFileNode::new(green, errors)
82 } 82 }
83 pub fn reparse(&self, edit: &AtomEdit) -> File { 83 pub fn reparse(&self, edit: &AtomEdit) -> SourceFileNode {
84 self.incremental_reparse(edit) 84 self.incremental_reparse(edit)
85 .unwrap_or_else(|| self.full_reparse(edit)) 85 .unwrap_or_else(|| self.full_reparse(edit))
86 } 86 }
87 pub fn incremental_reparse(&self, edit: &AtomEdit) -> Option<File> { 87 pub fn incremental_reparse(&self, edit: &AtomEdit) -> Option<SourceFileNode> {
88 reparsing::incremental_reparse(self.syntax(), edit, self.errors()) 88 reparsing::incremental_reparse(self.syntax(), edit, self.errors())
89 .map(|(green_node, errors)| File::new(green_node, errors)) 89 .map(|(green_node, errors)| SourceFileNode::new(green_node, errors))
90 } 90 }
91 fn full_reparse(&self, edit: &AtomEdit) -> File { 91 fn full_reparse(&self, edit: &AtomEdit) -> SourceFileNode {
92 let text = 92 let text =
93 text_utils::replace_range(self.syntax().text().to_string(), edit.delete, &edit.insert); 93 text_utils::replace_range(self.syntax().text().to_string(), edit.delete, &edit.insert);
94 File::parse(&text) 94 SourceFileNode::parse(&text)
95 } 95 }
96 /// Typed AST representation of the parse tree. 96 /// Typed AST representation of the parse tree.
97 pub fn ast(&self) -> ast::Root { 97 pub fn ast(&self) -> ast::Root {
diff --git a/crates/ra_syntax/src/reparsing.rs b/crates/ra_syntax/src/reparsing.rs
index 3c4ea5c22..d48133166 100644
--- a/crates/ra_syntax/src/reparsing.rs
+++ b/crates/ra_syntax/src/reparsing.rs
@@ -180,7 +180,7 @@ fn merge_errors(
180#[cfg(test)] 180#[cfg(test)]
181mod tests { 181mod tests {
182 use super::{ 182 use super::{
183 super::{test_utils::extract_range, text_utils::replace_range, utils::dump_tree, File}, 183 super::{test_utils::extract_range, text_utils::replace_range, utils::dump_tree, SourceFileNode},
184 reparse_block, reparse_leaf, AtomEdit, GreenNode, SyntaxError, SyntaxNodeRef, 184 reparse_block, reparse_leaf, AtomEdit, GreenNode, SyntaxError, SyntaxNodeRef,
185}; 185};
186 186
@@ -192,9 +192,9 @@ mod tests {
192 let (range, before) = extract_range(before); 192 let (range, before) = extract_range(before);
193 let after = replace_range(before.clone(), range, replace_with); 193 let after = replace_range(before.clone(), range, replace_with);
194 194
195 let fully_reparsed = File::parse(&after); 195 let fully_reparsed = SourceFileNode::parse(&after);
196 let incrementally_reparsed = { 196 let incrementally_reparsed = {
197 let f = File::parse(&before); 197 let f = SourceFileNode::parse(&before);
198 let edit = AtomEdit { 198 let edit = AtomEdit {
199 delete: range, 199 delete: range,
200 insert: replace_with.to_string(), 200 insert: replace_with.to_string(),
@@ -203,7 +203,7 @@ mod tests {
203 reparser(f.syntax(), &edit).expect("cannot incrementally reparse"); 203 reparser(f.syntax(), &edit).expect("cannot incrementally reparse");
204 let green_root = node.replace_with(green); 204 let green_root = node.replace_with(green);
205 let errors = super::merge_errors(f.errors(), new_errors, node, &edit); 205 let errors = super::merge_errors(f.errors(), new_errors, node, &edit);
206 File::new(green_root, errors) 206 SourceFileNode::new(green_root, errors)
207 }; 207 };
208 208
209 assert_eq_text!( 209 assert_eq_text!(
diff --git a/crates/ra_syntax/src/utils.rs b/crates/ra_syntax/src/utils.rs
index cad9544be..5bbdf80bb 100644
--- a/crates/ra_syntax/src/utils.rs
+++ b/crates/ra_syntax/src/utils.rs
@@ -1,4 +1,4 @@
1use crate::{File, SyntaxKind, SyntaxNodeRef, WalkEvent}; 1use crate::{SourceFileNode, SyntaxKind, SyntaxNodeRef, WalkEvent};
2use std::fmt::Write; 2use std::fmt::Write;
3use std::str; 3use std::str;
4 4
@@ -45,7 +45,7 @@ pub fn dump_tree(syntax: SyntaxNodeRef) -> String {
45} 45}
46 46
47pub fn check_fuzz_invariants(text: &str) { 47pub fn check_fuzz_invariants(text: &str) {
48 let file = File::parse(text); 48 let file = SourceFileNode::parse(text);
49 let root = file.syntax(); 49 let root = file.syntax();
50 validate_block_structure(root); 50 validate_block_structure(root);
51 let _ = file.ast(); 51 let _ = file.ast();
diff --git a/crates/ra_syntax/src/validation.rs b/crates/ra_syntax/src/validation.rs
index f345dbd6e..a10b297c0 100644
--- a/crates/ra_syntax/src/validation.rs
+++ b/crates/ra_syntax/src/validation.rs
@@ -5,7 +5,7 @@ use arrayvec::ArrayString;
5use crate::{ 5use crate::{
6 algo::visit::{visitor_ctx, VisitorCtx}, 6 algo::visit::{visitor_ctx, VisitorCtx},
7 ast::{self, AstNode}, 7 ast::{self, AstNode},
8 File, 8 SourceFileNode,
9 string_lexing::{self, CharComponentKind}, 9 string_lexing::{self, CharComponentKind},
10 yellow::{ 10 yellow::{
11 SyntaxError, 11 SyntaxError,
@@ -13,7 +13,7 @@ use crate::{
13 }, 13 },
14}; 14};
15 15
16pub(crate) fn validate(file: &File) -> Vec<SyntaxError> { 16pub(crate) fn validate(file: &SourceFileNode) -> Vec<SyntaxError> {
17 let mut errors = Vec::new(); 17 let mut errors = Vec::new();
18 for node in file.syntax().descendants() { 18 for node in file.syntax().descendants() {
19 let _ = visitor_ctx(&mut errors) 19 let _ = visitor_ctx(&mut errors)
@@ -155,11 +155,11 @@ fn is_ascii_escape(code: char) -> bool {
155 155
156#[cfg(test)] 156#[cfg(test)]
157mod test { 157mod test {
158 use crate::File; 158 use crate::SourceFileNode;
159 159
160 fn build_file(literal: &str) -> File { 160 fn build_file(literal: &str) -> SourceFileNode {
161 let src = format!("const C: char = '{}';", literal); 161 let src = format!("const C: char = '{}';", literal);
162 File::parse(&src) 162 SourceFileNode::parse(&src)
163 } 163 }
164 164
165 fn assert_valid_char(literal: &str) { 165 fn assert_valid_char(literal: &str) {
diff --git a/crates/ra_syntax/tests/test.rs b/crates/ra_syntax/tests/test.rs
index 9d1ded093..67acc9020 100644
--- a/crates/ra_syntax/tests/test.rs
+++ b/crates/ra_syntax/tests/test.rs
@@ -11,7 +11,7 @@ use std::{
11 11
12use ra_syntax::{ 12use ra_syntax::{
13 utils::{check_fuzz_invariants, dump_tree}, 13 utils::{check_fuzz_invariants, dump_tree},
14 File, 14 SourceFileNode,
15}; 15};
16 16
17#[test] 17#[test]
@@ -25,7 +25,7 @@ fn lexer_tests() {
25#[test] 25#[test]
26fn parser_tests() { 26fn parser_tests() {
27 dir_tests(&["parser/inline", "parser/ok", "parser/err"], |text| { 27 dir_tests(&["parser/inline", "parser/ok", "parser/err"], |text| {
28 let file = File::parse(text); 28 let file = SourceFileNode::parse(text);
29 dump_tree(file.syntax()) 29 dump_tree(file.syntax())
30 }) 30 })
31} 31}