mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-25 12:33:33 +00:00
Move ParsedFile to top
This commit is contained in:
parent
f104458d45
commit
9fae494a8d
7 changed files with 39 additions and 39 deletions
|
@ -27,8 +27,9 @@ use std::{
|
|||
};
|
||||
|
||||
use libsyntax2::{
|
||||
ParsedFile,
|
||||
TextUnit, TextRange, SmolStr,
|
||||
ast::{self, AstNode, NameOwner, ParsedFile},
|
||||
ast::{self, AstNode, NameOwner},
|
||||
SyntaxKind::*,
|
||||
};
|
||||
use libeditor::{LineIndex, FileSymbol, find_node};
|
||||
|
|
|
@ -4,7 +4,8 @@ use std::{
|
|||
|
||||
use parking_lot::{RwLock, RwLockReadGuard, RwLockWriteGuard};
|
||||
use libsyntax2::{
|
||||
ast::{self, AstNode, NameOwner, ParsedFile},
|
||||
ParsedFile,
|
||||
ast::{self, AstNode, NameOwner},
|
||||
SyntaxNode, SmolStr,
|
||||
};
|
||||
use {FileId, FileResolver};
|
||||
|
|
|
@ -3,7 +3,8 @@ use std::{
|
|||
};
|
||||
|
||||
use libsyntax2::{
|
||||
ast::{self, AstNode, AttrsOwner, TypeParamsOwner, NameOwner, ParsedFile},
|
||||
ParsedFile,
|
||||
ast::{self, AstNode, AttrsOwner, TypeParamsOwner, NameOwner},
|
||||
SyntaxKind::COMMA,
|
||||
SyntaxNodeRef,
|
||||
algo::{
|
||||
|
|
|
@ -10,8 +10,7 @@ mod code_actions;
|
|||
mod typing;
|
||||
|
||||
use libsyntax2::{
|
||||
ast::{self, NameOwner},
|
||||
AstNode,
|
||||
ast::{self, AstNode, NameOwner},
|
||||
algo::{walk, find_leaf_at_offset},
|
||||
SyntaxKind::{self, *},
|
||||
};
|
||||
|
@ -52,11 +51,11 @@ pub enum RunnableKind {
|
|||
Bin,
|
||||
}
|
||||
|
||||
pub fn parse(text: &str) -> ast::ParsedFile {
|
||||
ast::ParsedFile::parse(text)
|
||||
pub fn parse(text: &str) -> ParsedFile {
|
||||
ParsedFile::parse(text)
|
||||
}
|
||||
|
||||
pub fn matching_brace(file: &ast::ParsedFile, offset: TextUnit) -> Option<TextUnit> {
|
||||
pub fn matching_brace(file: &ParsedFile, offset: TextUnit) -> Option<TextUnit> {
|
||||
const BRACES: &[SyntaxKind] = &[
|
||||
L_CURLY, R_CURLY,
|
||||
L_BRACK, R_BRACK,
|
||||
|
@ -76,7 +75,7 @@ pub fn matching_brace(file: &ast::ParsedFile, offset: TextUnit) -> Option<TextUn
|
|||
Some(matching_node.range().start())
|
||||
}
|
||||
|
||||
pub fn highlight(file: &ast::ParsedFile) -> Vec<HighlightedRange> {
|
||||
pub fn highlight(file: &ParsedFile) -> Vec<HighlightedRange> {
|
||||
let mut res = Vec::new();
|
||||
for node in walk::preorder(file.syntax()) {
|
||||
let tag = match node.kind() {
|
||||
|
@ -99,7 +98,7 @@ pub fn highlight(file: &ast::ParsedFile) -> Vec<HighlightedRange> {
|
|||
res
|
||||
}
|
||||
|
||||
pub fn diagnostics(file: &ast::ParsedFile) -> Vec<Diagnostic> {
|
||||
pub fn diagnostics(file: &ParsedFile) -> Vec<Diagnostic> {
|
||||
let mut res = Vec::new();
|
||||
|
||||
for node in walk::preorder(file.syntax()) {
|
||||
|
@ -117,11 +116,11 @@ pub fn diagnostics(file: &ast::ParsedFile) -> Vec<Diagnostic> {
|
|||
res
|
||||
}
|
||||
|
||||
pub fn syntax_tree(file: &ast::ParsedFile) -> String {
|
||||
pub fn syntax_tree(file: &ParsedFile) -> String {
|
||||
::libsyntax2::utils::dump_tree(file.syntax())
|
||||
}
|
||||
|
||||
pub fn runnables(file: &ast::ParsedFile) -> Vec<Runnable> {
|
||||
pub fn runnables(file: &ParsedFile) -> Vec<Runnable> {
|
||||
file.ast()
|
||||
.functions()
|
||||
.filter_map(|f| {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use libsyntax2::{
|
||||
TextUnit, TextRange, SyntaxNodeRef,
|
||||
TextUnit, TextRange, SyntaxNodeRef, ParsedFile,
|
||||
ast,
|
||||
algo::{
|
||||
walk::preorder,
|
||||
|
@ -11,7 +11,7 @@ use libsyntax2::{
|
|||
|
||||
use {ActionResult, EditBuilder};
|
||||
|
||||
pub fn join_lines(file: &ast::ParsedFile, range: TextRange) -> ActionResult {
|
||||
pub fn join_lines(file: &ParsedFile, 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))];
|
||||
|
|
|
@ -4,8 +4,7 @@ use itertools::Itertools;
|
|||
use smol_str::SmolStr;
|
||||
|
||||
use {
|
||||
SyntaxNode, SyntaxNodeRef, TreeRoot, SyntaxError,
|
||||
SyntaxKind::*,
|
||||
SyntaxNodeRef, SyntaxKind::*,
|
||||
};
|
||||
pub use self::generated::*;
|
||||
|
||||
|
@ -37,28 +36,6 @@ pub trait AttrsOwner<'a>: AstNode<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct ParsedFile {
|
||||
root: SyntaxNode
|
||||
}
|
||||
|
||||
impl ParsedFile {
|
||||
pub fn parse(text: &str) -> Self {
|
||||
let root = ::parse(text);
|
||||
ParsedFile { root }
|
||||
}
|
||||
pub fn ast(&self) -> File {
|
||||
File::cast(self.syntax()).unwrap()
|
||||
}
|
||||
pub fn syntax(&self) -> SyntaxNodeRef {
|
||||
self.root.borrowed()
|
||||
}
|
||||
pub fn errors(&self) -> Vec<SyntaxError> {
|
||||
self.syntax().root.syntax_root().errors.clone()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
impl<'a> FnDef<'a> {
|
||||
pub fn has_atom_attr(&self, atom: &str) -> bool {
|
||||
self.attrs()
|
||||
|
|
|
@ -44,12 +44,33 @@ pub mod text_utils;
|
|||
pub use {
|
||||
text_unit::{TextRange, TextUnit},
|
||||
smol_str::SmolStr,
|
||||
ast::{AstNode, ParsedFile},
|
||||
ast::AstNode,
|
||||
lexer::{tokenize, Token},
|
||||
syntax_kinds::SyntaxKind,
|
||||
yellow::{SyntaxNode, SyntaxNodeRef, OwnedRoot, RefRoot, TreeRoot, SyntaxError},
|
||||
};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct ParsedFile {
|
||||
root: SyntaxNode
|
||||
}
|
||||
|
||||
impl ParsedFile {
|
||||
pub fn parse(text: &str) -> Self {
|
||||
let root = ::parse(text);
|
||||
ParsedFile { root }
|
||||
}
|
||||
pub fn ast(&self) -> ast::File {
|
||||
ast::File::cast(self.syntax()).unwrap()
|
||||
}
|
||||
pub fn syntax(&self) -> SyntaxNodeRef {
|
||||
self.root.borrowed()
|
||||
}
|
||||
pub fn errors(&self) -> Vec<SyntaxError> {
|
||||
self.syntax().root.syntax_root().errors.clone()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
pub fn parse(text: &str) -> SyntaxNode {
|
||||
let tokens = tokenize(&text);
|
||||
|
|
Loading…
Reference in a new issue