From f8b36bbc3b968754b71844d942286e81415627b8 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 7 Nov 2018 18:32:33 +0300 Subject: Rename File -> SourceFileNode --- crates/ra_analysis/src/completion.rs | 10 +++++----- crates/ra_analysis/src/db.rs | 8 ++++---- crates/ra_analysis/src/descriptors/function/scope.rs | 6 +++--- crates/ra_analysis/src/descriptors/module/scope.rs | 4 ++-- crates/ra_analysis/src/imp.rs | 8 ++++---- crates/ra_analysis/src/lib.rs | 14 +++++++------- crates/ra_analysis/src/symbol_index.rs | 8 +++++--- crates/ra_analysis/src/syntax_ptr.rs | 6 +++--- 8 files changed, 33 insertions(+), 31 deletions(-) (limited to 'crates/ra_analysis/src') 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; 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 627512553..194f1a6b0 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 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>( #[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 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) { #[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 166f1484f..00c4a08bd 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 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; 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 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::{ 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 4afb1fc93..e45934ce0 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() -- cgit v1.2.3