rename ParsedFile -> File

This commit is contained in:
Aleksey Kladov 2018-08-25 11:44:58 +03:00
parent cf278ed3bf
commit 220d285b4a
11 changed files with 39 additions and 39 deletions

View file

@ -10,7 +10,7 @@ use std::{
}; };
use clap::{App, Arg, SubCommand}; use clap::{App, Arg, SubCommand};
use tools::collect_tests; use tools::collect_tests;
use libeditor::{ParsedFile, syntax_tree, file_structure}; use libeditor::{File, syntax_tree, file_structure};
type Result<T> = ::std::result::Result<T, failure::Error>; type Result<T> = ::std::result::Result<T, failure::Error>;
@ -68,7 +68,7 @@ fn main() -> Result<()> {
Ok(()) Ok(())
} }
fn file() -> Result<ParsedFile> { fn file() -> Result<File> {
let text = read_stdin()?; let text = read_stdin()?;
Ok(libeditor::parse(&text)) Ok(libeditor::parse(&text))
} }

View file

@ -27,7 +27,7 @@ use std::{
}; };
use libsyntax2::{ use libsyntax2::{
ParsedFile, File,
TextUnit, TextRange, SmolStr, TextUnit, TextRange, SmolStr,
ast::{self, AstNode, NameOwner}, ast::{self, AstNode, NameOwner},
SyntaxKind::*, SyntaxKind::*,
@ -132,7 +132,7 @@ impl WorldState {
impl World { impl World {
pub fn file_syntax(&self, file_id: FileId) -> Result<ParsedFile> { pub fn file_syntax(&self, file_id: FileId) -> Result<File> {
let data = self.file_data(file_id)?; let data = self.file_data(file_id)?;
Ok(data.syntax().clone()) Ok(data.syntax().clone())
} }
@ -265,7 +265,7 @@ struct WorldData {
struct FileData { struct FileData {
text: String, text: String,
symbols: OnceCell<FileSymbols>, symbols: OnceCell<FileSymbols>,
syntax: OnceCell<ParsedFile>, syntax: OnceCell<File>,
lines: OnceCell<LineIndex>, lines: OnceCell<LineIndex>,
} }
@ -279,14 +279,14 @@ impl FileData {
} }
} }
fn syntax(&self) -> &ParsedFile { fn syntax(&self) -> &File {
self.syntax 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()) 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 { fn symbols(&self) -> &FileSymbols {

View file

@ -4,13 +4,13 @@ use std::{
use parking_lot::{RwLock, RwLockReadGuard, RwLockWriteGuard}; use parking_lot::{RwLock, RwLockReadGuard, RwLockWriteGuard};
use libsyntax2::{ use libsyntax2::{
ParsedFile, File,
ast::{self, AstNode, NameOwner}, ast::{self, AstNode, NameOwner},
SyntaxNode, SmolStr, SyntaxNode, SmolStr,
}; };
use {FileId, FileResolver}; 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)] #[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
pub struct ModuleId(FileId); pub struct ModuleId(FileId);

View file

@ -1,6 +1,6 @@
use libeditor::{FileSymbol, file_symbols}; use libeditor::{FileSymbol, file_symbols};
use libsyntax2::{ use libsyntax2::{
ParsedFile, File,
SyntaxKind::{self, *}, SyntaxKind::{self, *},
}; };
use fst::{self, IntoStreamer, Streamer}; use fst::{self, IntoStreamer, Streamer};
@ -12,7 +12,7 @@ pub(crate) struct FileSymbols {
} }
impl FileSymbols { impl FileSymbols {
pub(crate) fn new(file: &ParsedFile) -> FileSymbols { pub(crate) fn new(file: &File) -> FileSymbols {
let mut symbols = file_symbols(file) let mut symbols = file_symbols(file)
.into_iter() .into_iter()
.map(|s| (s.name.as_str().to_lowercase(), s)) .map(|s| (s.name.as_str().to_lowercase(), s))

View file

@ -3,7 +3,7 @@ use std::{
}; };
use libsyntax2::{ use libsyntax2::{
ParsedFile, File,
ast::{self, AstNode, AttrsOwner, TypeParamsOwner, NameOwner}, ast::{self, AstNode, AttrsOwner, TypeParamsOwner, NameOwner},
SyntaxKind::COMMA, SyntaxKind::COMMA,
SyntaxNodeRef, SyntaxNodeRef,
@ -21,7 +21,7 @@ pub struct ActionResult {
pub cursor_position: Option<TextUnit>, pub cursor_position: Option<TextUnit>,
} }
pub fn flip_comma<'a>(file: &'a ParsedFile, offset: TextUnit) -> Option<impl FnOnce() -> ActionResult + 'a> { pub fn flip_comma<'a>(file: &'a File, offset: TextUnit) -> Option<impl FnOnce() -> ActionResult + 'a> {
let syntax = file.syntax(); let syntax = file.syntax();
let comma = find_leaf_at_offset(syntax, offset).find(|leaf| leaf.kind() == COMMA)?; 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<impl FnO
}) })
} }
pub fn add_derive<'a>(file: &'a ParsedFile, offset: TextUnit) -> Option<impl FnOnce() -> ActionResult + 'a> { pub fn add_derive<'a>(file: &'a File, offset: TextUnit) -> Option<impl FnOnce() -> ActionResult + 'a> {
let nominal = find_node::<ast::NominalDef>(file.syntax(), offset)?; let nominal = find_node::<ast::NominalDef>(file.syntax(), offset)?;
Some(move || { Some(move || {
let derive_attr = nominal let derive_attr = nominal
@ -65,7 +65,7 @@ pub fn add_derive<'a>(file: &'a ParsedFile, offset: TextUnit) -> Option<impl FnO
}) })
} }
pub fn add_impl<'a>(file: &'a ParsedFile, offset: TextUnit) -> Option<impl FnOnce() -> ActionResult + 'a> { pub fn add_impl<'a>(file: &'a File, offset: TextUnit) -> Option<impl FnOnce() -> ActionResult + 'a> {
let nominal = find_node::<ast::NominalDef>(file.syntax(), offset)?; let nominal = find_node::<ast::NominalDef>(file.syntax(), offset)?;
let name = nominal.name()?; let name = nominal.name()?;

View file

@ -1,10 +1,10 @@
use libsyntax2::{ use libsyntax2::{
ParsedFile, TextRange, SyntaxNodeRef, File, TextRange, SyntaxNodeRef,
SyntaxKind::WHITESPACE, SyntaxKind::WHITESPACE,
algo::{find_leaf_at_offset, find_covering_node, ancestors}, algo::{find_leaf_at_offset, find_covering_node, ancestors},
}; };
pub fn extend_selection(file: &ParsedFile, range: TextRange) -> Option<TextRange> { pub fn extend_selection(file: &File, range: TextRange) -> Option<TextRange> {
let syntax = file.syntax(); let syntax = file.syntax();
extend(syntax.borrowed(), range) extend(syntax.borrowed(), range)
} }

View file

@ -14,7 +14,7 @@ use libsyntax2::{
algo::{walk, find_leaf_at_offset}, algo::{walk, find_leaf_at_offset},
SyntaxKind::{self, *}, SyntaxKind::{self, *},
}; };
pub use libsyntax2::{ParsedFile, TextRange, TextUnit}; pub use libsyntax2::{File, TextRange, TextUnit};
pub use self::{ pub use self::{
line_index::{LineIndex, LineCol}, line_index::{LineIndex, LineCol},
extend_selection::extend_selection, extend_selection::extend_selection,
@ -51,11 +51,11 @@ pub enum RunnableKind {
Bin, Bin,
} }
pub fn parse(text: &str) -> ParsedFile { pub fn parse(text: &str) -> File {
ParsedFile::parse(text) File::parse(text)
} }
pub fn matching_brace(file: &ParsedFile, offset: TextUnit) -> Option<TextUnit> { pub fn matching_brace(file: &File, offset: TextUnit) -> Option<TextUnit> {
const BRACES: &[SyntaxKind] = &[ const BRACES: &[SyntaxKind] = &[
L_CURLY, R_CURLY, L_CURLY, R_CURLY,
L_BRACK, R_BRACK, L_BRACK, R_BRACK,
@ -75,7 +75,7 @@ pub fn matching_brace(file: &ParsedFile, offset: TextUnit) -> Option<TextUnit> {
Some(matching_node.range().start()) Some(matching_node.range().start())
} }
pub fn highlight(file: &ParsedFile) -> Vec<HighlightedRange> { pub fn highlight(file: &File) -> Vec<HighlightedRange> {
let mut res = Vec::new(); let mut res = Vec::new();
for node in walk::preorder(file.syntax()) { for node in walk::preorder(file.syntax()) {
let tag = match node.kind() { let tag = match node.kind() {
@ -98,7 +98,7 @@ pub fn highlight(file: &ParsedFile) -> Vec<HighlightedRange> {
res res
} }
pub fn diagnostics(file: &ParsedFile) -> Vec<Diagnostic> { pub fn diagnostics(file: &File) -> Vec<Diagnostic> {
let mut res = Vec::new(); let mut res = Vec::new();
for node in walk::preorder(file.syntax()) { for node in walk::preorder(file.syntax()) {
@ -116,11 +116,11 @@ pub fn diagnostics(file: &ParsedFile) -> Vec<Diagnostic> {
res res
} }
pub fn syntax_tree(file: &ParsedFile) -> String { pub fn syntax_tree(file: &File) -> String {
::libsyntax2::utils::dump_tree(file.syntax()) ::libsyntax2::utils::dump_tree(file.syntax())
} }
pub fn runnables(file: &ParsedFile) -> Vec<Runnable> { pub fn runnables(file: &File) -> Vec<Runnable> {
file.ast() file.ast()
.functions() .functions()
.filter_map(|f| { .filter_map(|f| {

View file

@ -1,5 +1,5 @@
use libsyntax2::{ use libsyntax2::{
SyntaxKind, SyntaxNodeRef, AstNode, ParsedFile, SmolStr, SyntaxKind, SyntaxNodeRef, AstNode, File, SmolStr,
ast::{self, NameOwner}, ast::{self, NameOwner},
algo::{ algo::{
visit::{visitor, Visitor}, visit::{visitor, Visitor},
@ -24,7 +24,7 @@ pub struct FileSymbol {
pub kind: SyntaxKind, pub kind: SyntaxKind,
} }
pub fn file_symbols(file: &ParsedFile) -> Vec<FileSymbol> { pub fn file_symbols(file: &File) -> Vec<FileSymbol> {
preorder(file.syntax()) preorder(file.syntax())
.filter_map(to_symbol) .filter_map(to_symbol)
.collect() .collect()
@ -52,7 +52,7 @@ fn to_symbol(node: SyntaxNodeRef) -> Option<FileSymbol> {
} }
pub fn file_structure(file: &ParsedFile) -> Vec<StructureNode> { pub fn file_structure(file: &File) -> Vec<StructureNode> {
let mut res = Vec::new(); let mut res = Vec::new();
let mut stack = Vec::new(); let mut stack = Vec::new();

View file

@ -1,5 +1,5 @@
use libsyntax2::{ use libsyntax2::{
TextUnit, TextRange, SyntaxNodeRef, ParsedFile, TextUnit, TextRange, SyntaxNodeRef, File,
algo::{ algo::{
walk::preorder, walk::preorder,
find_covering_node, find_covering_node,
@ -10,7 +10,7 @@ use libsyntax2::{
use {ActionResult, EditBuilder}; 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 range = if range.is_empty() {
let text = file.syntax().text(); let text = file.syntax().text();
let text = &text[TextRange::from_to(range.start(), TextUnit::of_str(&text))]; let text = &text[TextRange::from_to(range.start(), TextUnit::of_str(&text))];

View file

@ -5,7 +5,7 @@ extern crate assert_eq_text;
use assert_eq_text::{assert_eq_dbg}; use assert_eq_text::{assert_eq_dbg};
use libeditor::{ use libeditor::{
ParsedFile, TextUnit, TextRange, ActionResult, File, TextUnit, TextRange, ActionResult,
highlight, runnables, extend_selection, file_structure, highlight, runnables, extend_selection, file_structure,
flip_comma, add_derive, add_impl, matching_brace, flip_comma, add_derive, add_impl, matching_brace,
join_lines, join_lines,
@ -234,11 +234,11 @@ struct Foo { f: u32 }
"); ");
} }
fn file(text: &str) -> ParsedFile { fn file(text: &str) -> File {
ParsedFile::parse(text) File::parse(text)
} }
fn check_action<F: Fn(&ParsedFile, TextUnit) -> Option<ActionResult>>( fn check_action<F: Fn(&File, TextUnit) -> Option<ActionResult>>(
before: &str, before: &str,
after: &str, after: &str,
f: F, f: F,

View file

@ -51,14 +51,14 @@ pub use {
}; };
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct ParsedFile { pub struct File {
root: SyntaxNode root: SyntaxNode
} }
impl ParsedFile { impl File {
pub fn parse(text: &str) -> Self { pub fn parse(text: &str) -> Self {
let root = ::parse(text); let root = ::parse(text);
ParsedFile { root } File { root }
} }
pub fn ast(&self) -> ast::Root { pub fn ast(&self) -> ast::Root {
ast::Root::cast(self.syntax()).unwrap() ast::Root::cast(self.syntax()).unwrap()