mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-13 05:38:46 +00:00
More symbols
This commit is contained in:
parent
fe1fe866f3
commit
56aa6e20e0
7 changed files with 42 additions and 22 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -2,3 +2,4 @@
|
||||||
**/*.rs.bk
|
**/*.rs.bk
|
||||||
Cargo.lock
|
Cargo.lock
|
||||||
.vscode/*
|
.vscode/*
|
||||||
|
*.log
|
||||||
|
|
|
@ -63,5 +63,8 @@ fn to_symbol(node: SyntaxNodeRef) -> Option<FileSymbol> {
|
||||||
.visit(decl::<ast::Enum<_>>)
|
.visit(decl::<ast::Enum<_>>)
|
||||||
.visit(decl::<ast::Trait<_>>)
|
.visit(decl::<ast::Trait<_>>)
|
||||||
.visit(decl::<ast::Module<_>>)
|
.visit(decl::<ast::Module<_>>)
|
||||||
|
.visit(decl::<ast::TypeItem<_>>)
|
||||||
|
.visit(decl::<ast::ConstItem<_>>)
|
||||||
|
.visit(decl::<ast::StaticItem<_>>)
|
||||||
.accept(node)?
|
.accept(node)?
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,6 +70,9 @@ mod m {
|
||||||
}
|
}
|
||||||
|
|
||||||
enum E { X, Y(i32) }
|
enum E { X, Y(i32) }
|
||||||
|
type T = ();
|
||||||
|
static S: i32 = 92;
|
||||||
|
const C: i32 = 92;
|
||||||
"#);
|
"#);
|
||||||
let symbols = file_symbols(&file);
|
let symbols = file_symbols(&file);
|
||||||
dbg_eq(
|
dbg_eq(
|
||||||
|
@ -77,7 +80,10 @@ enum E { X, Y(i32) }
|
||||||
r#"[FileSymbol { parent: None, name: "Foo", name_range: [8; 11), node_range: [1; 26), kind: STRUCT },
|
r#"[FileSymbol { parent: None, name: "Foo", name_range: [8; 11), node_range: [1; 26), kind: STRUCT },
|
||||||
FileSymbol { parent: None, name: "m", name_range: [32; 33), node_range: [28; 53), kind: MODULE },
|
FileSymbol { parent: None, name: "m", name_range: [32; 33), node_range: [28; 53), kind: MODULE },
|
||||||
FileSymbol { parent: Some(1), name: "bar", name_range: [43; 46), node_range: [40; 51), kind: FUNCTION },
|
FileSymbol { parent: Some(1), name: "bar", name_range: [43; 46), node_range: [40; 51), kind: FUNCTION },
|
||||||
FileSymbol { parent: None, name: "E", name_range: [60; 61), node_range: [55; 75), kind: ENUM }]"#,
|
FileSymbol { parent: None, name: "E", name_range: [60; 61), node_range: [55; 75), kind: ENUM },
|
||||||
|
FileSymbol { parent: None, name: "T", name_range: [81; 82), node_range: [76; 88), kind: TYPE_ITEM },
|
||||||
|
FileSymbol { parent: None, name: "S", name_range: [96; 97), node_range: [89; 108), kind: STATIC_ITEM },
|
||||||
|
FileSymbol { parent: None, name: "C", name_range: [115; 116), node_range: [109; 127), kind: CONST_ITEM }]"#,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -180,3 +180,22 @@ impl<R: TreeRoot> AstNode<R> for Trait<R> {
|
||||||
impl<R: TreeRoot> ast::NameOwner<R> for Trait<R> {}
|
impl<R: TreeRoot> ast::NameOwner<R> for Trait<R> {}
|
||||||
impl<R: TreeRoot> Trait<R> {}
|
impl<R: TreeRoot> Trait<R> {}
|
||||||
|
|
||||||
|
// TypeItem
|
||||||
|
#[derive(Debug, Clone, Copy)]
|
||||||
|
pub struct TypeItem<R: TreeRoot = Arc<SyntaxRoot>> {
|
||||||
|
syntax: SyntaxNode<R>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<R: TreeRoot> AstNode<R> for TypeItem<R> {
|
||||||
|
fn cast(syntax: SyntaxNode<R>) -> Option<Self> {
|
||||||
|
match syntax.kind() {
|
||||||
|
TYPE_ITEM => Some(TypeItem { syntax }),
|
||||||
|
_ => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fn syntax(&self) -> &SyntaxNode<R> { &self.syntax }
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<R: TreeRoot> ast::NameOwner<R> for TypeItem<R> {}
|
||||||
|
impl<R: TreeRoot> TypeItem<R> {}
|
||||||
|
|
||||||
|
|
|
@ -219,27 +219,14 @@ Grammar(
|
||||||
["functions", "Function"]
|
["functions", "Function"]
|
||||||
]
|
]
|
||||||
),
|
),
|
||||||
"Function": (
|
"Function": ( traits: ["NameOwner"] ),
|
||||||
traits: ["NameOwner"]
|
"Struct": ( traits: ["NameOwner"] ),
|
||||||
),
|
"Enum": ( traits: ["NameOwner"] ),
|
||||||
"Struct": (
|
"Trait": ( traits: ["NameOwner"] ),
|
||||||
traits: ["NameOwner"]
|
"Module": ( traits: ["NameOwner"] ),
|
||||||
),
|
"ConstItem": ( traits: ["NameOwner"] ),
|
||||||
"Enum": (
|
"StaticItem": ( traits: ["NameOwner"] ),
|
||||||
traits: ["NameOwner"]
|
"TypeItem": ( traits: ["NameOwner"] ),
|
||||||
),
|
|
||||||
"Trait": (
|
|
||||||
traits: ["NameOwner"]
|
|
||||||
),
|
|
||||||
"Module": (
|
|
||||||
traits: ["NameOwner"]
|
|
||||||
),
|
|
||||||
"ConstItem": (
|
|
||||||
traits: ["NameOwner"]
|
|
||||||
),
|
|
||||||
"StaticItem": (
|
|
||||||
traits: ["NameOwner"]
|
|
||||||
),
|
|
||||||
"Name": (),
|
"Name": (),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
|
@ -74,6 +74,9 @@ fn to_symbol_kind(kind: SyntaxKind) -> SymbolKind {
|
||||||
SyntaxKind::ENUM => SymbolKind::Enum,
|
SyntaxKind::ENUM => SymbolKind::Enum,
|
||||||
SyntaxKind::TRAIT => SymbolKind::Interface,
|
SyntaxKind::TRAIT => SymbolKind::Interface,
|
||||||
SyntaxKind::MODULE => SymbolKind::Module,
|
SyntaxKind::MODULE => SymbolKind::Module,
|
||||||
|
SyntaxKind::TYPE_ITEM => SymbolKind::TypeParameter,
|
||||||
|
SyntaxKind::STATIC_ITEM => SymbolKind::Constant,
|
||||||
|
SyntaxKind::CONST_ITEM => SymbolKind::Constant,
|
||||||
_ => SymbolKind::Variable,
|
_ => SymbolKind::Variable,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -188,6 +188,7 @@ fn existing_tests(dir: &Path) -> Result<HashMap<String, (PathBuf, Test)>> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn install_code_extension() -> Result<()> {
|
fn install_code_extension() -> Result<()> {
|
||||||
|
execute!(r"cargo install --path crates/server --force")?;
|
||||||
execute!(
|
execute!(
|
||||||
r"
|
r"
|
||||||
cd code
|
cd code
|
||||||
|
|
Loading…
Reference in a new issue