mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-12 21:28:51 +00:00
rename ParsedFile -> File
This commit is contained in:
parent
cf278ed3bf
commit
220d285b4a
11 changed files with 39 additions and 39 deletions
|
@ -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<T> = ::std::result::Result<T, failure::Error>;
|
||||
|
||||
|
@ -68,7 +68,7 @@ fn main() -> Result<()> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn file() -> Result<ParsedFile> {
|
||||
fn file() -> Result<File> {
|
||||
let text = read_stdin()?;
|
||||
Ok(libeditor::parse(&text))
|
||||
}
|
||||
|
|
|
@ -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<ParsedFile> {
|
||||
pub fn file_syntax(&self, file_id: FileId) -> Result<File> {
|
||||
let data = self.file_data(file_id)?;
|
||||
Ok(data.syntax().clone())
|
||||
}
|
||||
|
@ -265,7 +265,7 @@ struct WorldData {
|
|||
struct FileData {
|
||||
text: String,
|
||||
symbols: OnceCell<FileSymbols>,
|
||||
syntax: OnceCell<ParsedFile>,
|
||||
syntax: OnceCell<File>,
|
||||
lines: OnceCell<LineIndex>,
|
||||
}
|
||||
|
||||
|
@ -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 {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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<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 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)?;
|
||||
Some(move || {
|
||||
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 name = nominal.name()?;
|
||||
|
||||
|
|
|
@ -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<TextRange> {
|
||||
pub fn extend_selection(file: &File, range: TextRange) -> Option<TextRange> {
|
||||
let syntax = file.syntax();
|
||||
extend(syntax.borrowed(), range)
|
||||
}
|
||||
|
|
|
@ -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<TextUnit> {
|
||||
pub fn matching_brace(file: &File, offset: TextUnit) -> Option<TextUnit> {
|
||||
const BRACES: &[SyntaxKind] = &[
|
||||
L_CURLY, R_CURLY,
|
||||
L_BRACK, R_BRACK,
|
||||
|
@ -75,7 +75,7 @@ pub fn matching_brace(file: &ParsedFile, offset: TextUnit) -> Option<TextUnit> {
|
|||
Some(matching_node.range().start())
|
||||
}
|
||||
|
||||
pub fn highlight(file: &ParsedFile) -> Vec<HighlightedRange> {
|
||||
pub fn highlight(file: &File) -> Vec<HighlightedRange> {
|
||||
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<HighlightedRange> {
|
|||
res
|
||||
}
|
||||
|
||||
pub fn diagnostics(file: &ParsedFile) -> Vec<Diagnostic> {
|
||||
pub fn diagnostics(file: &File) -> Vec<Diagnostic> {
|
||||
let mut res = Vec::new();
|
||||
|
||||
for node in walk::preorder(file.syntax()) {
|
||||
|
@ -116,11 +116,11 @@ pub fn diagnostics(file: &ParsedFile) -> Vec<Diagnostic> {
|
|||
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<Runnable> {
|
||||
pub fn runnables(file: &File) -> Vec<Runnable> {
|
||||
file.ast()
|
||||
.functions()
|
||||
.filter_map(|f| {
|
||||
|
|
|
@ -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<FileSymbol> {
|
||||
pub fn file_symbols(file: &File) -> Vec<FileSymbol> {
|
||||
preorder(file.syntax())
|
||||
.filter_map(to_symbol)
|
||||
.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 stack = Vec::new();
|
||||
|
||||
|
|
|
@ -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))];
|
||||
|
|
|
@ -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<F: Fn(&ParsedFile, TextUnit) -> Option<ActionResult>>(
|
||||
fn check_action<F: Fn(&File, TextUnit) -> Option<ActionResult>>(
|
||||
before: &str,
|
||||
after: &str,
|
||||
f: F,
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in a new issue