From 220d285b4afb250e59a08e9b1ad38c2fc2275782 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 25 Aug 2018 11:44:58 +0300 Subject: rename ParsedFile -> File --- crates/cli/src/main.rs | 4 ++-- crates/libanalysis/src/lib.rs | 14 +++++++------- crates/libanalysis/src/module_map.rs | 4 ++-- crates/libanalysis/src/symbol_index.rs | 4 ++-- crates/libeditor/src/code_actions.rs | 8 ++++---- crates/libeditor/src/extend_selection.rs | 4 ++-- crates/libeditor/src/lib.rs | 16 ++++++++-------- crates/libeditor/src/symbols.rs | 6 +++--- crates/libeditor/src/typing.rs | 4 ++-- crates/libeditor/tests/test.rs | 8 ++++---- crates/libsyntax2/src/lib.rs | 6 +++--- 11 files changed, 39 insertions(+), 39 deletions(-) diff --git a/crates/cli/src/main.rs b/crates/cli/src/main.rs index e8e2ce7ee..fc28691fc 100644 --- a/crates/cli/src/main.rs +++ b/crates/cli/src/main.rs @@ -10,7 +10,7 @@ use std::{ }; use clap::{App, Arg, SubCommand}; use tools::collect_tests; -use libeditor::{ParsedFile, syntax_tree, file_structure}; +use libeditor::{File, syntax_tree, file_structure}; type Result = ::std::result::Result; @@ -68,7 +68,7 @@ fn main() -> Result<()> { Ok(()) } -fn file() -> Result { +fn file() -> Result { let text = read_stdin()?; Ok(libeditor::parse(&text)) } diff --git a/crates/libanalysis/src/lib.rs b/crates/libanalysis/src/lib.rs index a0f17a689..c84ab6077 100644 --- a/crates/libanalysis/src/lib.rs +++ b/crates/libanalysis/src/lib.rs @@ -27,7 +27,7 @@ use std::{ }; use libsyntax2::{ - ParsedFile, + File, TextUnit, TextRange, SmolStr, ast::{self, AstNode, NameOwner}, SyntaxKind::*, @@ -132,7 +132,7 @@ impl WorldState { impl World { - pub fn file_syntax(&self, file_id: FileId) -> Result { + pub fn file_syntax(&self, file_id: FileId) -> Result { let data = self.file_data(file_id)?; Ok(data.syntax().clone()) } @@ -265,7 +265,7 @@ struct WorldData { struct FileData { text: String, symbols: OnceCell, - syntax: OnceCell, + syntax: OnceCell, lines: OnceCell, } @@ -279,14 +279,14 @@ impl FileData { } } - fn syntax(&self) -> &ParsedFile { + fn syntax(&self) -> &File { self.syntax - .get_or_init(|| ParsedFile::parse(&self.text)) + .get_or_init(|| File::parse(&self.text)) } - fn syntax_transient(&self) -> ParsedFile { + fn syntax_transient(&self) -> File { self.syntax.get().map(|s| s.clone()) - .unwrap_or_else(|| ParsedFile::parse(&self.text)) + .unwrap_or_else(|| File::parse(&self.text)) } fn symbols(&self) -> &FileSymbols { diff --git a/crates/libanalysis/src/module_map.rs b/crates/libanalysis/src/module_map.rs index e8d32928a..6a9104d84 100644 --- a/crates/libanalysis/src/module_map.rs +++ b/crates/libanalysis/src/module_map.rs @@ -4,13 +4,13 @@ use std::{ use parking_lot::{RwLock, RwLockReadGuard, RwLockWriteGuard}; use libsyntax2::{ - ParsedFile, + File, ast::{self, AstNode, NameOwner}, SyntaxNode, SmolStr, }; use {FileId, FileResolver}; -type SyntaxProvider<'a> = dyn Fn(FileId) -> ParsedFile + 'a; +type SyntaxProvider<'a> = dyn Fn(FileId) -> File + 'a; #[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)] pub struct ModuleId(FileId); diff --git a/crates/libanalysis/src/symbol_index.rs b/crates/libanalysis/src/symbol_index.rs index 426de4c76..73cbf5702 100644 --- a/crates/libanalysis/src/symbol_index.rs +++ b/crates/libanalysis/src/symbol_index.rs @@ -1,6 +1,6 @@ use libeditor::{FileSymbol, file_symbols}; use libsyntax2::{ - ParsedFile, + File, SyntaxKind::{self, *}, }; use fst::{self, IntoStreamer, Streamer}; @@ -12,7 +12,7 @@ pub(crate) struct FileSymbols { } impl FileSymbols { - pub(crate) fn new(file: &ParsedFile) -> FileSymbols { + pub(crate) fn new(file: &File) -> FileSymbols { let mut symbols = file_symbols(file) .into_iter() .map(|s| (s.name.as_str().to_lowercase(), s)) diff --git a/crates/libeditor/src/code_actions.rs b/crates/libeditor/src/code_actions.rs index c7c043b39..b3305be2a 100644 --- a/crates/libeditor/src/code_actions.rs +++ b/crates/libeditor/src/code_actions.rs @@ -3,7 +3,7 @@ use std::{ }; use libsyntax2::{ - ParsedFile, + File, ast::{self, AstNode, AttrsOwner, TypeParamsOwner, NameOwner}, SyntaxKind::COMMA, SyntaxNodeRef, @@ -21,7 +21,7 @@ pub struct ActionResult { pub cursor_position: Option, } -pub fn flip_comma<'a>(file: &'a ParsedFile, offset: TextUnit) -> Option ActionResult + 'a> { +pub fn flip_comma<'a>(file: &'a File, offset: TextUnit) -> Option ActionResult + 'a> { let syntax = file.syntax(); let comma = find_leaf_at_offset(syntax, offset).find(|leaf| leaf.kind() == COMMA)?; @@ -38,7 +38,7 @@ pub fn flip_comma<'a>(file: &'a ParsedFile, offset: TextUnit) -> Option(file: &'a ParsedFile, offset: TextUnit) -> Option ActionResult + 'a> { +pub fn add_derive<'a>(file: &'a File, offset: TextUnit) -> Option ActionResult + 'a> { let nominal = find_node::(file.syntax(), offset)?; Some(move || { let derive_attr = nominal @@ -65,7 +65,7 @@ pub fn add_derive<'a>(file: &'a ParsedFile, offset: TextUnit) -> Option(file: &'a ParsedFile, offset: TextUnit) -> Option ActionResult + 'a> { +pub fn add_impl<'a>(file: &'a File, offset: TextUnit) -> Option ActionResult + 'a> { let nominal = find_node::(file.syntax(), offset)?; let name = nominal.name()?; diff --git a/crates/libeditor/src/extend_selection.rs b/crates/libeditor/src/extend_selection.rs index 32873f491..d1724b528 100644 --- a/crates/libeditor/src/extend_selection.rs +++ b/crates/libeditor/src/extend_selection.rs @@ -1,10 +1,10 @@ use libsyntax2::{ - ParsedFile, TextRange, SyntaxNodeRef, + File, TextRange, SyntaxNodeRef, SyntaxKind::WHITESPACE, algo::{find_leaf_at_offset, find_covering_node, ancestors}, }; -pub fn extend_selection(file: &ParsedFile, range: TextRange) -> Option { +pub fn extend_selection(file: &File, range: TextRange) -> Option { let syntax = file.syntax(); extend(syntax.borrowed(), range) } diff --git a/crates/libeditor/src/lib.rs b/crates/libeditor/src/lib.rs index 681cca81d..a6e6deba7 100644 --- a/crates/libeditor/src/lib.rs +++ b/crates/libeditor/src/lib.rs @@ -14,7 +14,7 @@ use libsyntax2::{ algo::{walk, find_leaf_at_offset}, SyntaxKind::{self, *}, }; -pub use libsyntax2::{ParsedFile, TextRange, TextUnit}; +pub use libsyntax2::{File, TextRange, TextUnit}; pub use self::{ line_index::{LineIndex, LineCol}, extend_selection::extend_selection, @@ -51,11 +51,11 @@ pub enum RunnableKind { Bin, } -pub fn parse(text: &str) -> ParsedFile { - ParsedFile::parse(text) +pub fn parse(text: &str) -> File { + File::parse(text) } -pub fn matching_brace(file: &ParsedFile, offset: TextUnit) -> Option { +pub fn matching_brace(file: &File, offset: TextUnit) -> Option { const BRACES: &[SyntaxKind] = &[ L_CURLY, R_CURLY, L_BRACK, R_BRACK, @@ -75,7 +75,7 @@ pub fn matching_brace(file: &ParsedFile, offset: TextUnit) -> Option { Some(matching_node.range().start()) } -pub fn highlight(file: &ParsedFile) -> Vec { +pub fn highlight(file: &File) -> Vec { let mut res = Vec::new(); for node in walk::preorder(file.syntax()) { let tag = match node.kind() { @@ -98,7 +98,7 @@ pub fn highlight(file: &ParsedFile) -> Vec { res } -pub fn diagnostics(file: &ParsedFile) -> Vec { +pub fn diagnostics(file: &File) -> Vec { let mut res = Vec::new(); for node in walk::preorder(file.syntax()) { @@ -116,11 +116,11 @@ pub fn diagnostics(file: &ParsedFile) -> Vec { res } -pub fn syntax_tree(file: &ParsedFile) -> String { +pub fn syntax_tree(file: &File) -> String { ::libsyntax2::utils::dump_tree(file.syntax()) } -pub fn runnables(file: &ParsedFile) -> Vec { +pub fn runnables(file: &File) -> Vec { file.ast() .functions() .filter_map(|f| { diff --git a/crates/libeditor/src/symbols.rs b/crates/libeditor/src/symbols.rs index 37cef6389..98a35dcdf 100644 --- a/crates/libeditor/src/symbols.rs +++ b/crates/libeditor/src/symbols.rs @@ -1,5 +1,5 @@ use libsyntax2::{ - SyntaxKind, SyntaxNodeRef, AstNode, ParsedFile, SmolStr, + SyntaxKind, SyntaxNodeRef, AstNode, File, SmolStr, ast::{self, NameOwner}, algo::{ visit::{visitor, Visitor}, @@ -24,7 +24,7 @@ pub struct FileSymbol { pub kind: SyntaxKind, } -pub fn file_symbols(file: &ParsedFile) -> Vec { +pub fn file_symbols(file: &File) -> Vec { preorder(file.syntax()) .filter_map(to_symbol) .collect() @@ -52,7 +52,7 @@ fn to_symbol(node: SyntaxNodeRef) -> Option { } -pub fn file_structure(file: &ParsedFile) -> Vec { +pub fn file_structure(file: &File) -> Vec { let mut res = Vec::new(); let mut stack = Vec::new(); diff --git a/crates/libeditor/src/typing.rs b/crates/libeditor/src/typing.rs index ebc7c77d2..e7eba671f 100644 --- a/crates/libeditor/src/typing.rs +++ b/crates/libeditor/src/typing.rs @@ -1,5 +1,5 @@ use libsyntax2::{ - TextUnit, TextRange, SyntaxNodeRef, ParsedFile, + TextUnit, TextRange, SyntaxNodeRef, File, algo::{ walk::preorder, find_covering_node, @@ -10,7 +10,7 @@ use libsyntax2::{ use {ActionResult, EditBuilder}; -pub fn join_lines(file: &ParsedFile, range: TextRange) -> ActionResult { +pub fn join_lines(file: &File, range: TextRange) -> ActionResult { let range = if range.is_empty() { let text = file.syntax().text(); let text = &text[TextRange::from_to(range.start(), TextUnit::of_str(&text))]; diff --git a/crates/libeditor/tests/test.rs b/crates/libeditor/tests/test.rs index 4f7c2e07a..3114a128e 100644 --- a/crates/libeditor/tests/test.rs +++ b/crates/libeditor/tests/test.rs @@ -5,7 +5,7 @@ extern crate assert_eq_text; use assert_eq_text::{assert_eq_dbg}; use libeditor::{ - ParsedFile, TextUnit, TextRange, ActionResult, + File, TextUnit, TextRange, ActionResult, highlight, runnables, extend_selection, file_structure, flip_comma, add_derive, add_impl, matching_brace, join_lines, @@ -234,11 +234,11 @@ struct Foo { f: u32 } "); } -fn file(text: &str) -> ParsedFile { - ParsedFile::parse(text) +fn file(text: &str) -> File { + File::parse(text) } -fn check_action Option>( +fn check_action Option>( before: &str, after: &str, f: F, diff --git a/crates/libsyntax2/src/lib.rs b/crates/libsyntax2/src/lib.rs index 9b45e2575..ab4a40435 100644 --- a/crates/libsyntax2/src/lib.rs +++ b/crates/libsyntax2/src/lib.rs @@ -51,14 +51,14 @@ pub use { }; #[derive(Clone, Debug)] -pub struct ParsedFile { +pub struct File { root: SyntaxNode } -impl ParsedFile { +impl File { pub fn parse(text: &str) -> Self { let root = ::parse(text); - ParsedFile { root } + File { root } } pub fn ast(&self) -> ast::Root { ast::Root::cast(self.syntax()).unwrap() -- cgit v1.2.3