mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-03 07:04:49 +00:00
rename file -> root
This commit is contained in:
parent
9fae494a8d
commit
cf278ed3bf
160 changed files with 187 additions and 188 deletions
|
@ -104,32 +104,6 @@ impl<'a> ast::TypeParamsOwner<'a> for EnumDef<'a> {}
|
|||
impl<'a> ast::AttrsOwner<'a> for EnumDef<'a> {}
|
||||
impl<'a> EnumDef<'a> {}
|
||||
|
||||
// File
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct File<'a> {
|
||||
syntax: SyntaxNodeRef<'a>,
|
||||
}
|
||||
|
||||
impl<'a> AstNode<'a> for File<'a> {
|
||||
fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
|
||||
match syntax.kind() {
|
||||
FILE => Some(File { syntax }),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
|
||||
}
|
||||
|
||||
impl<'a> File<'a> {
|
||||
pub fn functions(self) -> impl Iterator<Item = FnDef<'a>> + 'a {
|
||||
super::children(self)
|
||||
}
|
||||
|
||||
pub fn modules(self) -> impl Iterator<Item = Module<'a>> + 'a {
|
||||
super::children(self)
|
||||
}
|
||||
}
|
||||
|
||||
// FnDef
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct FnDef<'a> {
|
||||
|
@ -439,6 +413,32 @@ impl<'a> AstNode<'a> for ReferenceType<'a> {
|
|||
|
||||
impl<'a> ReferenceType<'a> {}
|
||||
|
||||
// Root
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct Root<'a> {
|
||||
syntax: SyntaxNodeRef<'a>,
|
||||
}
|
||||
|
||||
impl<'a> AstNode<'a> for Root<'a> {
|
||||
fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
|
||||
match syntax.kind() {
|
||||
ROOT => Some(Root { syntax }),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
|
||||
}
|
||||
|
||||
impl<'a> Root<'a> {
|
||||
pub fn functions(self) -> impl Iterator<Item = FnDef<'a>> + 'a {
|
||||
super::children(self)
|
||||
}
|
||||
|
||||
pub fn modules(self) -> impl Iterator<Item = Module<'a>> + 'a {
|
||||
super::children(self)
|
||||
}
|
||||
}
|
||||
|
||||
// SliceType
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct SliceType<'a> {
|
||||
|
|
|
@ -114,7 +114,7 @@ Grammar(
|
|||
"SHEBANG",
|
||||
],
|
||||
nodes: [
|
||||
"FILE",
|
||||
"ROOT",
|
||||
|
||||
"STRUCT_DEF",
|
||||
"ENUM_DEF",
|
||||
|
@ -235,7 +235,7 @@ Grammar(
|
|||
"ARG_LIST",
|
||||
],
|
||||
ast: {
|
||||
"File": (
|
||||
"Root": (
|
||||
collections: [
|
||||
["functions", "FnDef"],
|
||||
["modules", "Module"],
|
||||
|
|
|
@ -40,7 +40,7 @@ pub(crate) fn file(p: &mut Parser) {
|
|||
let file = p.start();
|
||||
p.eat(SHEBANG);
|
||||
items::mod_contents(p, false);
|
||||
file.complete(p, FILE);
|
||||
file.complete(p, ROOT);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -60,8 +60,8 @@ impl ParsedFile {
|
|||
let root = ::parse(text);
|
||||
ParsedFile { root }
|
||||
}
|
||||
pub fn ast(&self) -> ast::File {
|
||||
ast::File::cast(self.syntax()).unwrap()
|
||||
pub fn ast(&self) -> ast::Root {
|
||||
ast::Root::cast(self.syntax()).unwrap()
|
||||
}
|
||||
pub fn syntax(&self) -> SyntaxNodeRef {
|
||||
self.root.borrowed()
|
||||
|
|
|
@ -115,7 +115,7 @@ pub enum SyntaxKind {
|
|||
COMMENT,
|
||||
DOC_COMMENT,
|
||||
SHEBANG,
|
||||
FILE,
|
||||
ROOT,
|
||||
STRUCT_DEF,
|
||||
ENUM_DEF,
|
||||
FN_DEF,
|
||||
|
@ -375,7 +375,7 @@ impl SyntaxKind {
|
|||
COMMENT => &SyntaxInfo { name: "COMMENT" },
|
||||
DOC_COMMENT => &SyntaxInfo { name: "DOC_COMMENT" },
|
||||
SHEBANG => &SyntaxInfo { name: "SHEBANG" },
|
||||
FILE => &SyntaxInfo { name: "FILE" },
|
||||
ROOT => &SyntaxInfo { name: "ROOT" },
|
||||
STRUCT_DEF => &SyntaxInfo { name: "STRUCT_DEF" },
|
||||
ENUM_DEF => &SyntaxInfo { name: "ENUM_DEF" },
|
||||
FN_DEF => &SyntaxInfo { name: "FN_DEF" },
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue