From 56aa6e20e0279c69e0130905573b1607056cfaf9 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 11 Aug 2018 16:20:37 +0300 Subject: More symbols --- crates/libeditor/src/symbols.rs | 3 +++ crates/libeditor/tests/test.rs | 8 +++++++- crates/libsyntax2/src/ast/generated.rs | 19 +++++++++++++++++++ crates/libsyntax2/src/grammar.ron | 29 ++++++++--------------------- crates/server/src/handlers.rs | 3 +++ crates/tools/src/main.rs | 1 + 6 files changed, 41 insertions(+), 22 deletions(-) (limited to 'crates') diff --git a/crates/libeditor/src/symbols.rs b/crates/libeditor/src/symbols.rs index 3faf96868..5cd781c80 100644 --- a/crates/libeditor/src/symbols.rs +++ b/crates/libeditor/src/symbols.rs @@ -63,5 +63,8 @@ fn to_symbol(node: SyntaxNodeRef) -> Option { .visit(decl::>) .visit(decl::>) .visit(decl::>) + .visit(decl::>) + .visit(decl::>) + .visit(decl::>) .accept(node)? } diff --git a/crates/libeditor/tests/test.rs b/crates/libeditor/tests/test.rs index ba7181ab8..dedca49a4 100644 --- a/crates/libeditor/tests/test.rs +++ b/crates/libeditor/tests/test.rs @@ -70,6 +70,9 @@ mod m { } enum E { X, Y(i32) } +type T = (); +static S: i32 = 92; +const C: i32 = 92; "#); let symbols = file_symbols(&file); 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 }, 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: 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 }]"#, ) } diff --git a/crates/libsyntax2/src/ast/generated.rs b/crates/libsyntax2/src/ast/generated.rs index a4b116941..31f5ecc44 100644 --- a/crates/libsyntax2/src/ast/generated.rs +++ b/crates/libsyntax2/src/ast/generated.rs @@ -180,3 +180,22 @@ impl AstNode for Trait { impl ast::NameOwner for Trait {} impl Trait {} +// TypeItem +#[derive(Debug, Clone, Copy)] +pub struct TypeItem> { + syntax: SyntaxNode, +} + +impl AstNode for TypeItem { + fn cast(syntax: SyntaxNode) -> Option { + match syntax.kind() { + TYPE_ITEM => Some(TypeItem { syntax }), + _ => None, + } + } + fn syntax(&self) -> &SyntaxNode { &self.syntax } +} + +impl ast::NameOwner for TypeItem {} +impl TypeItem {} + diff --git a/crates/libsyntax2/src/grammar.ron b/crates/libsyntax2/src/grammar.ron index 3fe8fdf0b..d4e8c53d3 100644 --- a/crates/libsyntax2/src/grammar.ron +++ b/crates/libsyntax2/src/grammar.ron @@ -219,27 +219,14 @@ Grammar( ["functions", "Function"] ] ), - "Function": ( - traits: ["NameOwner"] - ), - "Struct": ( - traits: ["NameOwner"] - ), - "Enum": ( - traits: ["NameOwner"] - ), - "Trait": ( - traits: ["NameOwner"] - ), - "Module": ( - traits: ["NameOwner"] - ), - "ConstItem": ( - traits: ["NameOwner"] - ), - "StaticItem": ( - traits: ["NameOwner"] - ), + "Function": ( traits: ["NameOwner"] ), + "Struct": ( traits: ["NameOwner"] ), + "Enum": ( traits: ["NameOwner"] ), + "Trait": ( traits: ["NameOwner"] ), + "Module": ( traits: ["NameOwner"] ), + "ConstItem": ( traits: ["NameOwner"] ), + "StaticItem": ( traits: ["NameOwner"] ), + "TypeItem": ( traits: ["NameOwner"] ), "Name": (), }, ) diff --git a/crates/server/src/handlers.rs b/crates/server/src/handlers.rs index 51e940ef7..f6f960d22 100644 --- a/crates/server/src/handlers.rs +++ b/crates/server/src/handlers.rs @@ -74,6 +74,9 @@ fn to_symbol_kind(kind: SyntaxKind) -> SymbolKind { SyntaxKind::ENUM => SymbolKind::Enum, SyntaxKind::TRAIT => SymbolKind::Interface, SyntaxKind::MODULE => SymbolKind::Module, + SyntaxKind::TYPE_ITEM => SymbolKind::TypeParameter, + SyntaxKind::STATIC_ITEM => SymbolKind::Constant, + SyntaxKind::CONST_ITEM => SymbolKind::Constant, _ => SymbolKind::Variable, } } diff --git a/crates/tools/src/main.rs b/crates/tools/src/main.rs index b56be141a..289ad6e3c 100644 --- a/crates/tools/src/main.rs +++ b/crates/tools/src/main.rs @@ -188,6 +188,7 @@ fn existing_tests(dir: &Path) -> Result> { } fn install_code_extension() -> Result<()> { + execute!(r"cargo install --path crates/server --force")?; execute!( r" cd code -- cgit v1.2.3