diff --git a/crates/ra_analysis/src/completion.rs b/crates/ra_analysis/src/completion.rs index 7c3476e5c2..689d4c92f8 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; use ra_syntax::{ algo::visit::{visitor, visitor_ctx, Visitor, VisitorCtx}, ast::{self, AstChildren, LoopBodyOwner, ModuleItemOwner}, - AstNode, AtomEdit, File, + AstNode, AtomEdit, SourceFileNode, SyntaxKind::*, SyntaxNodeRef, TextUnit, }; @@ -63,7 +63,7 @@ pub(crate) fn resolve_based_completion( pub(crate) fn find_target_module( module_tree: &ModuleTree, module_id: ModuleId, - file: &File, + file: &SourceFileNode, offset: TextUnit, ) -> Option { let name_ref: ast::NameRef = find_node_at_offset(file.syntax(), offset)?; @@ -142,7 +142,7 @@ pub(crate) fn scope_completion( } fn complete_module_items( - file: &File, + file: &SourceFileNode, items: AstChildren, this_item: Option, acc: &mut Vec, @@ -164,7 +164,7 @@ fn complete_module_items( ); } -fn complete_name_ref(file: &File, name_ref: ast::NameRef, acc: &mut Vec) { +fn complete_name_ref(file: &SourceFileNode, name_ref: ast::NameRef, acc: &mut Vec) { if !is_node::(name_ref.syntax()) { return; } @@ -239,7 +239,7 @@ fn is_node<'a, N: AstNode<'a>>(node: SyntaxNodeRef<'a>) -> bool { } fn complete_expr_keywords( - file: &File, + file: &SourceFileNode, fn_def: ast::FnDef, name_ref: ast::NameRef, acc: &mut Vec, diff --git a/crates/ra_analysis/src/db.rs b/crates/ra_analysis/src/db.rs index 6275125530..194f1a6b08 100644 --- a/crates/ra_analysis/src/db.rs +++ b/crates/ra_analysis/src/db.rs @@ -1,7 +1,7 @@ use std::sync::Arc; use ra_editor::LineIndex; -use ra_syntax::{File, SyntaxNode}; +use ra_syntax::{SourceFileNode, SyntaxNode}; use salsa::{self, Database}; use crate::{ @@ -85,7 +85,7 @@ salsa::database_storage! { salsa::query_group! { pub(crate) trait SyntaxDatabase: crate::input::FilesDatabase { - fn file_syntax(file_id: FileId) -> File { + fn file_syntax(file_id: FileId) -> SourceFileNode { type FileSyntaxQuery; } fn file_lines(file_id: FileId) -> Arc { @@ -103,9 +103,9 @@ salsa::query_group! { } } -fn file_syntax(db: &impl SyntaxDatabase, file_id: FileId) -> File { +fn file_syntax(db: &impl SyntaxDatabase, file_id: FileId) -> SourceFileNode { let text = db.file_text(file_id); - File::parse(&*text) + SourceFileNode::parse(&*text) } fn file_lines(db: &impl SyntaxDatabase, file_id: FileId) -> Arc { 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 62b46ffba7..bbe16947cc 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>( #[cfg(test)] mod tests { use ra_editor::find_node_at_offset; - use ra_syntax::File; + use ra_syntax::SourceFileNode; use test_utils::extract_offset; use super::*; @@ -287,7 +287,7 @@ mod tests { buf.push_str(&code[off..]); buf }; - let file = File::parse(&code); + let file = SourceFileNode::parse(&code); let marker: ast::PathExpr = find_node_at_offset(file.syntax(), off).unwrap(); let fn_def: ast::FnDef = find_node_at_offset(file.syntax(), off).unwrap(); let scopes = FnScopes::new(fn_def); @@ -376,7 +376,7 @@ mod tests { fn do_check_local_name(code: &str, expected_offset: u32) { let (off, code) = extract_offset(code); - let file = File::parse(&code); + let file = SourceFileNode::parse(&code); let fn_def: ast::FnDef = find_node_at_offset(file.syntax(), off).unwrap(); let name_ref: ast::NameRef = find_node_at_offset(file.syntax(), off).unwrap(); diff --git a/crates/ra_analysis/src/descriptors/module/scope.rs b/crates/ra_analysis/src/descriptors/module/scope.rs index 215b31f8ef..5fcbc3cb05 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) { #[cfg(test)] mod tests { use super::*; - use ra_syntax::{ast::ModuleItemOwner, File}; + use ra_syntax::{ast::ModuleItemOwner, SourceFileNode}; fn do_check(code: &str, expected: &[&str]) { - let file = File::parse(&code); + let file = SourceFileNode::parse(&code); let scope = ModuleScope::new(file.ast().items()); let actual = scope.entries.iter().map(|it| it.name()).collect::>(); assert_eq!(expected, actual.as_slice()); diff --git a/crates/ra_analysis/src/imp.rs b/crates/ra_analysis/src/imp.rs index 166f1484f3..00c4a08bd5 100644 --- a/crates/ra_analysis/src/imp.rs +++ b/crates/ra_analysis/src/imp.rs @@ -7,7 +7,7 @@ use std::{ use ra_editor::{self, find_node_at_offset, FileSymbol, LineIndex, LocalEdit}; use ra_syntax::{ ast::{self, ArgListOwner, Expr, NameOwner}, - AstNode, File, SmolStr, + AstNode, SourceFileNode, SmolStr, SyntaxKind::*, SyntaxNodeRef, TextRange, TextUnit, }; @@ -27,7 +27,7 @@ use crate::{ input::{FilesDatabase, SourceRoot, SourceRootId, WORKSPACE}, symbol_index::SymbolIndex, AnalysisChange, Cancelable, CrateGraph, CrateId, Diagnostic, FileId, FileResolver, - FileSystemEdit, FilePosition, Query, SourceChange, SourceFileEdit, + FileSystemEdit, FilePosition, Query, SourceChange, SourceFileNodeEdit, }; #[derive(Clone, Debug)] @@ -180,7 +180,7 @@ impl fmt::Debug for AnalysisImpl { } impl AnalysisImpl { - pub fn file_syntax(&self, file_id: FileId) -> File { + pub fn file_syntax(&self, file_id: FileId) -> SourceFileNode { self.db.file_syntax(file_id) } pub fn file_line_index(&self, file_id: FileId) -> Arc { @@ -562,7 +562,7 @@ impl AnalysisImpl { impl SourceChange { pub(crate) fn from_local_edit(file_id: FileId, label: &str, edit: LocalEdit) -> SourceChange { - let file_edit = SourceFileEdit { + let file_edit = SourceFileNodeEdit { file_id, edits: edit.edit.into_atoms(), }; diff --git a/crates/ra_analysis/src/lib.rs b/crates/ra_analysis/src/lib.rs index 9475c938d1..ad0273edc0 100644 --- a/crates/ra_analysis/src/lib.rs +++ b/crates/ra_analysis/src/lib.rs @@ -20,7 +20,7 @@ pub mod mock_analysis; use std::{fmt, sync::Arc}; -use ra_syntax::{AtomEdit, File, TextRange, TextUnit}; +use ra_syntax::{AtomEdit, SourceFileNode, TextRange, TextUnit}; use rayon::prelude::*; use relative_path::RelativePathBuf; @@ -128,13 +128,13 @@ pub struct FilePosition { #[derive(Debug)] pub struct SourceChange { pub label: String, - pub source_file_edits: Vec, + pub source_file_edits: Vec, pub file_system_edits: Vec, pub cursor_position: Option, } #[derive(Debug)] -pub struct SourceFileEdit { +pub struct SourceFileNodeEdit { pub file_id: FileId, pub edits: Vec, } @@ -204,16 +204,16 @@ pub struct Analysis { } impl Analysis { - pub fn file_syntax(&self, file_id: FileId) -> File { + pub fn file_syntax(&self, file_id: FileId) -> SourceFileNode { self.imp.file_syntax(file_id).clone() } pub fn file_line_index(&self, file_id: FileId) -> Arc { self.imp.file_line_index(file_id) } - pub fn extend_selection(&self, file: &File, range: TextRange) -> TextRange { + pub fn extend_selection(&self, file: &SourceFileNode, range: TextRange) -> TextRange { ra_editor::extend_selection(file, range).unwrap_or(range) } - pub fn matching_brace(&self, file: &File, offset: TextUnit) -> Option { + pub fn matching_brace(&self, file: &SourceFileNode, offset: TextUnit) -> Option { ra_editor::matching_brace(file, offset) } pub fn syntax_tree(&self, file_id: FileId) -> String { @@ -309,7 +309,7 @@ pub struct LibraryData { impl LibraryData { pub fn prepare(files: Vec<(FileId, String)>, file_resolver: Arc) -> LibraryData { let symbol_index = SymbolIndex::for_files(files.par_iter().map(|(file_id, text)| { - let file = File::parse(text); + let file = SourceFileNode::parse(text); (*file_id, file) })); LibraryData { diff --git a/crates/ra_analysis/src/symbol_index.rs b/crates/ra_analysis/src/symbol_index.rs index b57ad5d331..3a0667ecda 100644 --- a/crates/ra_analysis/src/symbol_index.rs +++ b/crates/ra_analysis/src/symbol_index.rs @@ -6,7 +6,7 @@ use std::{ use fst::{self, Streamer}; use ra_editor::{file_symbols, FileSymbol}; use ra_syntax::{ - File, + SourceFileNode, SyntaxKind::{self, *}, }; use rayon::prelude::*; @@ -34,7 +34,9 @@ impl Hash for SymbolIndex { } impl SymbolIndex { - pub(crate) fn for_files(files: impl ParallelIterator) -> SymbolIndex { + pub(crate) fn for_files( + files: impl ParallelIterator, + ) -> SymbolIndex { let mut symbols = files .flat_map(|(file_id, file)| { file_symbols(&file) @@ -51,7 +53,7 @@ impl SymbolIndex { SymbolIndex { symbols, map } } - pub(crate) fn for_file(file_id: FileId, file: File) -> SymbolIndex { + pub(crate) fn for_file(file_id: FileId, file: SourceFileNode) -> SymbolIndex { SymbolIndex::for_files(rayon::iter::once((file_id, file))) } } diff --git a/crates/ra_analysis/src/syntax_ptr.rs b/crates/ra_analysis/src/syntax_ptr.rs index 4afb1fc930..e45934ce09 100644 --- a/crates/ra_analysis/src/syntax_ptr.rs +++ b/crates/ra_analysis/src/syntax_ptr.rs @@ -1,4 +1,4 @@ -use ra_syntax::{File, SyntaxKind, SyntaxNode, SyntaxNodeRef, TextRange}; +use ra_syntax::{SourceFileNode, SyntaxKind, SyntaxNode, SyntaxNodeRef, TextRange}; use crate::db::SyntaxDatabase; use crate::FileId; @@ -43,7 +43,7 @@ impl LocalSyntaxPtr { } } - pub(crate) fn resolve(self, file: &File) -> SyntaxNode { + pub(crate) fn resolve(self, file: &SourceFileNode) -> SyntaxNode { let mut curr = file.syntax(); loop { if curr.range() == self.range && curr.kind() == self.kind { @@ -67,7 +67,7 @@ impl LocalSyntaxPtr { #[test] fn test_local_syntax_ptr() { use ra_syntax::{ast, AstNode}; - let file = File::parse("struct Foo { f: u32, }"); + let file = SourceFileNode::parse("struct Foo { f: u32, }"); let field = file .syntax() .descendants() diff --git a/crates/ra_cli/src/main.rs b/crates/ra_cli/src/main.rs index 239d846b32..5ca86df4dd 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}; use clap::{App, Arg, SubCommand}; use join_to_string::join; use ra_editor::{extend_selection, file_structure, syntax_tree}; -use ra_syntax::{File, TextRange}; +use ra_syntax::{SourceFileNode, TextRange}; use tools::collect_tests; type Result = ::std::result::Result; @@ -79,9 +79,9 @@ fn main() -> Result<()> { Ok(()) } -fn file() -> Result { +fn file() -> Result { let text = read_stdin()?; - Ok(File::parse(&text)) + Ok(SourceFileNode::parse(&text)) } fn read_stdin() -> Result { @@ -100,12 +100,12 @@ fn render_test(file: &Path, line: usize) -> Result<(String, String)> { None => bail!("No test found at line {} at {}", line, file.display()), Some((_start_line, test)) => test, }; - let file = File::parse(&test.text); + let file = SourceFileNode::parse(&test.text); let tree = syntax_tree(&file); Ok((test.text, tree)) } -fn selections(file: &File, start: u32, end: u32) -> String { +fn selections(file: &SourceFileNode, start: u32, end: u32) -> String { let mut ranges = Vec::new(); let mut cur = Some(TextRange::from_to((start - 1).into(), (end - 1).into())); while let Some(r) = cur { diff --git a/crates/ra_editor/src/code_actions.rs b/crates/ra_editor/src/code_actions.rs index ef6df0d53e..0139b19d3a 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; use ra_syntax::{ algo::{find_covering_node, find_leaf_at_offset}, ast::{self, AstNode, AttrsOwner, NameOwner, TypeParamsOwner}, - Direction, File, + Direction, SourceFileNode, SyntaxKind::{COMMA, WHITESPACE}, SyntaxNodeRef, TextRange, TextUnit, }; @@ -16,7 +16,10 @@ pub struct LocalEdit { pub cursor_position: Option, } -pub fn flip_comma<'a>(file: &'a File, offset: TextUnit) -> Option LocalEdit + 'a> { +pub fn flip_comma<'a>( + file: &'a SourceFileNode, + offset: TextUnit, +) -> Option LocalEdit + 'a> { let syntax = file.syntax(); 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(file: &'a File, offset: TextUnit) -> Option LocalEdit + 'a> { +pub fn add_derive<'a>( + file: &'a SourceFileNode, + offset: TextUnit, +) -> Option LocalEdit + 'a> { let nominal = find_node_at_offset::(file.syntax(), offset)?; Some(move || { let derive_attr = nominal @@ -58,7 +64,10 @@ pub fn add_derive<'a>(file: &'a File, offset: TextUnit) -> Option(file: &'a File, offset: TextUnit) -> Option LocalEdit + 'a> { +pub fn add_impl<'a>( + file: &'a SourceFileNode, + offset: TextUnit, +) -> Option LocalEdit + 'a> { let nominal = find_node_at_offset::(file.syntax(), offset)?; let name = nominal.name()?; @@ -98,7 +107,7 @@ pub fn add_impl<'a>(file: &'a File, offset: TextUnit) -> Option } pub fn introduce_variable<'a>( - file: &'a File, + file: &'a SourceFileNode, range: TextRange, ) -> Option LocalEdit + 'a> { 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 9d8df25c3a..8f11d5364b 100644 --- a/crates/ra_editor/src/extend_selection.rs +++ b/crates/ra_editor/src/extend_selection.rs @@ -1,11 +1,11 @@ use ra_syntax::{ algo::{find_covering_node, find_leaf_at_offset, LeafAtOffset}, - Direction, File, + Direction, SourceFileNode, SyntaxKind::*, SyntaxNodeRef, TextRange, TextUnit, }; -pub fn extend_selection(file: &File, range: TextRange) -> Option { +pub fn extend_selection(file: &SourceFileNode, range: TextRange) -> Option { let syntax = file.syntax(); extend(syntax.borrowed(), range) } @@ -120,7 +120,7 @@ mod tests { fn do_check(before: &str, afters: &[&str]) { let (cursor, before) = extract_offset(before); - let file = File::parse(&before); + let file = SourceFileNode::parse(&before); let mut range = TextRange::offset_len(cursor, 0.into()); for &after in afters { 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 0803c88913..2a8fa3cda9 100644 --- a/crates/ra_editor/src/folding_ranges.rs +++ b/crates/ra_editor/src/folding_ranges.rs @@ -1,7 +1,7 @@ use rustc_hash::FxHashSet; use ra_syntax::{ - ast, AstNode, Direction, File, + ast, AstNode, Direction, SourceFileNode, SyntaxKind::{self, *}, SyntaxNodeRef, TextRange, }; @@ -18,7 +18,7 @@ pub struct Fold { pub kind: FoldKind, } -pub fn folding_ranges(file: &File) -> Vec { +pub fn folding_ranges(file: &SourceFileNode) -> Vec { let mut res = vec![]; let mut visited_comments = FxHashSet::default(); let mut visited_imports = FxHashSet::default(); @@ -171,7 +171,7 @@ mod tests { fn do_check(text: &str, fold_kinds: &[FoldKind]) { let (ranges, text) = extract_ranges(text); - let file = File::parse(&text); + let file = SourceFileNode::parse(&text); let folds = folding_ranges(&file); assert_eq!( diff --git a/crates/ra_editor/src/lib.rs b/crates/ra_editor/src/lib.rs index f92181b867..ff4e8303de 100644 --- a/crates/ra_editor/src/lib.rs +++ b/crates/ra_editor/src/lib.rs @@ -30,7 +30,7 @@ pub use ra_syntax::AtomEdit; use ra_syntax::{ algo::find_leaf_at_offset, ast::{self, AstNode, NameOwner}, - File, + SourceFileNode, Location, SyntaxKind::{self, *}, SyntaxNodeRef, TextRange, TextUnit, @@ -60,7 +60,7 @@ pub enum RunnableKind { Bin, } -pub fn matching_brace(file: &File, offset: TextUnit) -> Option { +pub fn matching_brace(file: &SourceFileNode, offset: TextUnit) -> Option { const BRACES: &[SyntaxKind] = &[ L_CURLY, R_CURLY, L_BRACK, R_BRACK, L_PAREN, R_PAREN, L_ANGLE, R_ANGLE, ]; @@ -78,7 +78,7 @@ pub fn matching_brace(file: &File, offset: TextUnit) -> Option { Some(matching_node.range().start()) } -pub fn highlight(file: &File) -> Vec { +pub fn highlight(file: &SourceFileNode) -> Vec { let mut res = Vec::new(); for node in file.syntax().descendants() { let tag = match node.kind() { @@ -100,7 +100,7 @@ pub fn highlight(file: &File) -> Vec { res } -pub fn diagnostics(file: &File) -> Vec { +pub fn diagnostics(file: &SourceFileNode) -> Vec { fn location_to_range(location: Location) -> TextRange { match location { Location::Offset(offset) => TextRange::offset_len(offset, 1.into()), @@ -117,11 +117,11 @@ pub fn diagnostics(file: &File) -> Vec { .collect() } -pub fn syntax_tree(file: &File) -> String { +pub fn syntax_tree(file: &SourceFileNode) -> String { ::ra_syntax::utils::dump_tree(file.syntax()) } -pub fn runnables(file: &File) -> Vec { +pub fn runnables(file: &SourceFileNode) -> Vec { file.syntax() .descendants() .filter_map(ast::FnDef::cast) @@ -163,7 +163,7 @@ mod tests { #[test] fn test_highlighting() { - let file = File::parse( + let file = SourceFileNode::parse( r#" // comment fn main() {} @@ -184,7 +184,7 @@ fn main() {} #[test] fn test_runnables() { - let file = File::parse( + let file = SourceFileNode::parse( r#" fn main() {} @@ -209,7 +209,7 @@ fn test_foo() {} fn test_matching_brace() { fn do_check(before: &str, after: &str) { let (pos, before) = extract_offset(before); - let file = File::parse(&before); + let file = SourceFileNode::parse(&before); let new_pos = match matching_brace(&file, pos) { None => pos, Some(pos) => pos, diff --git a/crates/ra_editor/src/symbols.rs b/crates/ra_editor/src/symbols.rs index f7681c76f3..6d3b0514a2 100644 --- a/crates/ra_editor/src/symbols.rs +++ b/crates/ra_editor/src/symbols.rs @@ -3,7 +3,7 @@ use crate::TextRange; use ra_syntax::{ algo::visit::{visitor, Visitor}, ast::{self, DocCommentsOwner, NameOwner}, - AstNode, File, SmolStr, SyntaxKind, SyntaxNodeRef, WalkEvent, + AstNode, SourceFileNode, SmolStr, SyntaxKind, SyntaxNodeRef, WalkEvent, }; #[derive(Debug, Clone)] @@ -23,7 +23,7 @@ pub struct FileSymbol { } impl FileSymbol { - pub fn docs(&self, file: &File) -> Option { + pub fn docs(&self, file: &SourceFileNode) -> Option { file.syntax() .descendants() .filter(|node| node.kind() == self.kind && node.range() == self.node_range) @@ -52,7 +52,7 @@ impl FileSymbol { } } -pub fn file_symbols(file: &File) -> Vec { +pub fn file_symbols(file: &SourceFileNode) -> Vec { file.syntax().descendants().filter_map(to_symbol).collect() } @@ -77,7 +77,7 @@ fn to_symbol(node: SyntaxNodeRef) -> Option { .accept(node)? } -pub fn file_structure(file: &File) -> Vec { +pub fn file_structure(file: &SourceFileNode) -> Vec { let mut res = Vec::new(); let mut stack = Vec::new(); @@ -153,7 +153,7 @@ mod tests { #[test] fn test_file_structure() { - let file = File::parse( + let file = SourceFileNode::parse( r#" struct Foo { x: i32 diff --git a/crates/ra_editor/src/test_utils.rs b/crates/ra_editor/src/test_utils.rs index bc3d700f64..cbeb6433b1 100644 --- a/crates/ra_editor/src/test_utils.rs +++ b/crates/ra_editor/src/test_utils.rs @@ -1,10 +1,14 @@ use crate::LocalEdit; pub use crate::_test_utils::*; -use ra_syntax::{File, TextRange, TextUnit}; +use ra_syntax::{SourceFileNode, TextRange, TextUnit}; -pub fn check_action Option>(before: &str, after: &str, f: F) { +pub fn check_action Option>( + before: &str, + after: &str, + f: F, +) { let (before_cursor_pos, before) = extract_offset(before); - let file = File::parse(&before); + let file = SourceFileNode::parse(&before); let result = f(&file, before_cursor_pos).expect("code action is not applicable"); let actual = result.edit.apply(&before); let actual_cursor_pos = match result.cursor_position { @@ -15,13 +19,13 @@ pub fn check_action Option>(before: &str, a assert_eq_text!(after, &actual); } -pub fn check_action_range Option>( +pub fn check_action_range Option>( before: &str, after: &str, f: F, ) { let (range, before) = extract_range(before); - let file = File::parse(&before); + let file = SourceFileNode::parse(&before); let result = f(&file, range).expect("code action is not applicable"); let actual = result.edit.apply(&before); 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 5a457d1482..f894d83922 100644 --- a/crates/ra_editor/src/typing.rs +++ b/crates/ra_editor/src/typing.rs @@ -4,14 +4,14 @@ use ra_syntax::{ algo::{find_covering_node, find_leaf_at_offset, LeafAtOffset}, ast, text_utils::{contains_offset_nonstrict, intersect}, - AstNode, File, SyntaxKind, + AstNode, SourceFileNode, SyntaxKind, SyntaxKind::*, SyntaxNodeRef, TextRange, TextUnit, }; use crate::{find_node_at_offset, EditBuilder, LocalEdit}; -pub fn join_lines(file: &File, range: TextRange) -> LocalEdit { +pub fn join_lines(file: &SourceFileNode, range: TextRange) -> LocalEdit { let range = if range.is_empty() { let syntax = file.syntax(); let text = syntax.text().slice(range.start()..); @@ -55,7 +55,7 @@ pub fn join_lines(file: &File, range: TextRange) -> LocalEdit { } } -pub fn on_enter(file: &File, offset: TextUnit) -> Option { +pub fn on_enter(file: &SourceFileNode, offset: TextUnit) -> Option { let comment = find_leaf_at_offset(file.syntax(), offset) .left_biased() .and_then(ast::Comment::cast)?; @@ -80,7 +80,7 @@ pub fn on_enter(file: &File, offset: TextUnit) -> Option { }) } -fn node_indent<'a>(file: &'a File, node: SyntaxNodeRef) -> Option<&'a str> { +fn node_indent<'a>(file: &'a SourceFileNode, node: SyntaxNodeRef) -> Option<&'a str> { let ws = match find_leaf_at_offset(file.syntax(), node.range().start()) { LeafAtOffset::Between(l, r) => { assert!(r == node); @@ -100,7 +100,7 @@ fn node_indent<'a>(file: &'a File, node: SyntaxNodeRef) -> Option<&'a str> { Some(&text[pos..]) } -pub fn on_eq_typed(file: &File, offset: TextUnit) -> Option { +pub fn on_eq_typed(file: &SourceFileNode, offset: TextUnit) -> Option { let let_stmt: ast::LetStmt = find_node_at_offset(file.syntax(), offset)?; if let_stmt.has_semi() { return None; @@ -390,7 +390,7 @@ fn foo() { fn check_join_lines_sel(before: &str, after: &str) { let (sel, before) = extract_range(before); - let file = File::parse(&before); + let file = SourceFileNode::parse(&before); let result = join_lines(&file, sel); let actual = result.edit.apply(&before); assert_eq_text!(after, &actual); @@ -469,7 +469,7 @@ pub fn handle_find_matching_brace() { fn test_on_eq_typed() { fn do_check(before: &str, after: &str) { let (offset, before) = extract_offset(before); - let file = File::parse(&before); + let file = SourceFileNode::parse(&before); let result = on_eq_typed(&file, offset).unwrap(); let actual = result.edit.apply(&before); assert_eq_text!(after, &actual); @@ -513,7 +513,7 @@ fn foo() { fn test_on_enter() { fn apply_on_enter(before: &str) -> Option { let (offset, before) = extract_offset(before); - let file = File::parse(&before); + let file = SourceFileNode::parse(&before); let result = on_enter(&file, offset)?; let actual = result.edit.apply(&before); 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 fa04f4b00b..e5a2449c24 100644 --- a/crates/ra_lsp_server/src/conv.rs +++ b/crates/ra_lsp_server/src/conv.rs @@ -2,7 +2,7 @@ use languageserver_types::{ Location, Position, Range, SymbolKind, TextDocumentEdit, TextDocumentIdentifier, TextDocumentItem, TextDocumentPositionParams, TextEdit, Url, VersionedTextDocumentIdentifier, }; -use ra_analysis::{FileId, FileSystemEdit, SourceChange, SourceFileEdit, FilePosition}; +use ra_analysis::{FileId, FileSystemEdit, SourceChange, SourceFileNodeEdit, FilePosition}; use ra_editor::{AtomEdit, Edit, LineCol, LineIndex}; use ra_syntax::{SyntaxKind, TextRange, TextUnit}; @@ -257,7 +257,7 @@ fn translate_offset_with_edit( } } -impl TryConvWith for SourceFileEdit { +impl TryConvWith for SourceFileNodeEdit { type Ctx = ServerWorld; type Output = TextDocumentEdit; fn try_conv_with(self, world: &ServerWorld) -> Result { diff --git a/crates/ra_syntax/src/lib.rs b/crates/ra_syntax/src/lib.rs index 54012b7b62..9f8066c709 100644 --- a/crates/ra_syntax/src/lib.rs +++ b/crates/ra_syntax/src/lib.rs @@ -61,12 +61,12 @@ pub use crate::{ use crate::yellow::GreenNode; -// TODO: pick a single name for everything. SourceFile maybe? +// TODO: pick a single name for everything. SourceFileNode maybe? /// File represents a parse tree for a single Rust file. -pub type File = ast::RootNode; +pub type SourceFileNode = ast::RootNode; -impl File { - fn new(green: GreenNode, errors: Vec) -> File { +impl SourceFileNode { + fn new(green: GreenNode, errors: Vec) -> SourceFileNode { let root = SyntaxNode::new(green, errors); if cfg!(debug_assertions) { utils::validate_block_structure(root.borrowed()); @@ -74,24 +74,24 @@ impl File { assert_eq!(root.kind(), SyntaxKind::ROOT); ast::RootNode { syntax: root } } - pub fn parse(text: &str) -> File { + pub fn parse(text: &str) -> SourceFileNode { let tokens = tokenize(&text); let (green, errors) = parser_impl::parse_with(yellow::GreenBuilder::new(), text, &tokens, grammar::root); - File::new(green, errors) + SourceFileNode::new(green, errors) } - pub fn reparse(&self, edit: &AtomEdit) -> File { + pub fn reparse(&self, edit: &AtomEdit) -> SourceFileNode { self.incremental_reparse(edit) .unwrap_or_else(|| self.full_reparse(edit)) } - pub fn incremental_reparse(&self, edit: &AtomEdit) -> Option { + pub fn incremental_reparse(&self, edit: &AtomEdit) -> Option { reparsing::incremental_reparse(self.syntax(), edit, self.errors()) - .map(|(green_node, errors)| File::new(green_node, errors)) + .map(|(green_node, errors)| SourceFileNode::new(green_node, errors)) } - fn full_reparse(&self, edit: &AtomEdit) -> File { + fn full_reparse(&self, edit: &AtomEdit) -> SourceFileNode { let text = text_utils::replace_range(self.syntax().text().to_string(), edit.delete, &edit.insert); - File::parse(&text) + SourceFileNode::parse(&text) } /// Typed AST representation of the parse tree. pub fn ast(&self) -> ast::Root { diff --git a/crates/ra_syntax/src/reparsing.rs b/crates/ra_syntax/src/reparsing.rs index 3c4ea5c22b..d48133166c 100644 --- a/crates/ra_syntax/src/reparsing.rs +++ b/crates/ra_syntax/src/reparsing.rs @@ -180,7 +180,7 @@ fn merge_errors( #[cfg(test)] mod tests { use super::{ - super::{test_utils::extract_range, text_utils::replace_range, utils::dump_tree, File}, + super::{test_utils::extract_range, text_utils::replace_range, utils::dump_tree, SourceFileNode}, reparse_block, reparse_leaf, AtomEdit, GreenNode, SyntaxError, SyntaxNodeRef, }; @@ -192,9 +192,9 @@ mod tests { let (range, before) = extract_range(before); let after = replace_range(before.clone(), range, replace_with); - let fully_reparsed = File::parse(&after); + let fully_reparsed = SourceFileNode::parse(&after); let incrementally_reparsed = { - let f = File::parse(&before); + let f = SourceFileNode::parse(&before); let edit = AtomEdit { delete: range, insert: replace_with.to_string(), @@ -203,7 +203,7 @@ mod tests { reparser(f.syntax(), &edit).expect("cannot incrementally reparse"); let green_root = node.replace_with(green); let errors = super::merge_errors(f.errors(), new_errors, node, &edit); - File::new(green_root, errors) + SourceFileNode::new(green_root, errors) }; assert_eq_text!( diff --git a/crates/ra_syntax/src/utils.rs b/crates/ra_syntax/src/utils.rs index cad9544bef..5bbdf80bb7 100644 --- a/crates/ra_syntax/src/utils.rs +++ b/crates/ra_syntax/src/utils.rs @@ -1,4 +1,4 @@ -use crate::{File, SyntaxKind, SyntaxNodeRef, WalkEvent}; +use crate::{SourceFileNode, SyntaxKind, SyntaxNodeRef, WalkEvent}; use std::fmt::Write; use std::str; @@ -45,7 +45,7 @@ pub fn dump_tree(syntax: SyntaxNodeRef) -> String { } pub fn check_fuzz_invariants(text: &str) { - let file = File::parse(text); + let file = SourceFileNode::parse(text); let root = file.syntax(); validate_block_structure(root); let _ = file.ast(); diff --git a/crates/ra_syntax/src/validation.rs b/crates/ra_syntax/src/validation.rs index f345dbd6e7..a10b297c0f 100644 --- a/crates/ra_syntax/src/validation.rs +++ b/crates/ra_syntax/src/validation.rs @@ -5,7 +5,7 @@ use arrayvec::ArrayString; use crate::{ algo::visit::{visitor_ctx, VisitorCtx}, ast::{self, AstNode}, - File, + SourceFileNode, string_lexing::{self, CharComponentKind}, yellow::{ SyntaxError, @@ -13,7 +13,7 @@ use crate::{ }, }; -pub(crate) fn validate(file: &File) -> Vec { +pub(crate) fn validate(file: &SourceFileNode) -> Vec { let mut errors = Vec::new(); for node in file.syntax().descendants() { let _ = visitor_ctx(&mut errors) @@ -155,11 +155,11 @@ fn is_ascii_escape(code: char) -> bool { #[cfg(test)] mod test { - use crate::File; + use crate::SourceFileNode; - fn build_file(literal: &str) -> File { + fn build_file(literal: &str) -> SourceFileNode { let src = format!("const C: char = '{}';", literal); - File::parse(&src) + SourceFileNode::parse(&src) } fn assert_valid_char(literal: &str) { diff --git a/crates/ra_syntax/tests/test.rs b/crates/ra_syntax/tests/test.rs index 9d1ded093b..67acc9020a 100644 --- a/crates/ra_syntax/tests/test.rs +++ b/crates/ra_syntax/tests/test.rs @@ -11,7 +11,7 @@ use std::{ use ra_syntax::{ utils::{check_fuzz_invariants, dump_tree}, - File, + SourceFileNode, }; #[test] @@ -25,7 +25,7 @@ fn lexer_tests() { #[test] fn parser_tests() { dir_tests(&["parser/inline", "parser/ok", "parser/err"], |text| { - let file = File::parse(text); + let file = SourceFileNode::parse(text); dump_tree(file.syntax()) }) } diff --git a/editors/code/src/commands/apply_source_change.ts b/editors/code/src/commands/apply_source_change.ts index cf921e3ac0..ec420d1abb 100644 --- a/editors/code/src/commands/apply_source_change.ts +++ b/editors/code/src/commands/apply_source_change.ts @@ -12,14 +12,14 @@ interface FileSystemEdit { export interface SourceChange { label: string; - sourceFileEdits: lc.TextDocumentEdit[]; + SourceFileNodeEdits: lc.TextDocumentEdit[]; fileSystemEdits: FileSystemEdit[]; cursorPosition?: lc.TextDocumentPositionParams; } export async function handle(change: SourceChange) { const wsEdit = new vscode.WorkspaceEdit(); - for (const sourceEdit of change.sourceFileEdits) { + for (const sourceEdit of change.SourceFileNodeEdits) { const uri = Server.client.protocol2CodeConverter.asUri( sourceEdit.textDocument.uri );