aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorJonas Schievink <[email protected]>2021-03-19 18:42:06 +0000
committerJonas Schievink <[email protected]>2021-03-19 19:05:17 +0000
commitfc5f73de45478058aa6d61e328733224cfa16efa (patch)
tree18be45e538cfd9a31800fbdeb3edcf85d638863b /crates
parentfc21640a65b5caef8dbbc9e85e9616b843847fb4 (diff)
Move `AttrsOwnerNode` to syntax and make it public
Diffstat (limited to 'crates')
-rw-r--r--crates/ide/src/syntax_highlighting/inject.rs32
-rw-r--r--crates/syntax/src/ast.rs4
-rw-r--r--crates/syntax/src/ast/node_ext.rs30
3 files changed, 33 insertions, 33 deletions
diff --git a/crates/ide/src/syntax_highlighting/inject.rs b/crates/ide/src/syntax_highlighting/inject.rs
index 5722dea3a..d2e09dbb6 100644
--- a/crates/ide/src/syntax_highlighting/inject.rs
+++ b/crates/ide/src/syntax_highlighting/inject.rs
@@ -6,7 +6,7 @@ use either::Either;
6use hir::{HasAttrs, InFile, Semantics}; 6use hir::{HasAttrs, InFile, Semantics};
7use ide_db::{call_info::ActiveParameter, defs::Definition, SymbolKind}; 7use ide_db::{call_info::ActiveParameter, defs::Definition, SymbolKind};
8use syntax::{ 8use syntax::{
9 ast::{self, AstNode, AttrsOwner, DocCommentsOwner}, 9 ast::{self, AstNode, AttrsOwner, AttrsOwnerNode, DocCommentsOwner},
10 match_ast, AstToken, NodeOrToken, SyntaxNode, SyntaxToken, TextRange, TextSize, 10 match_ast, AstToken, NodeOrToken, SyntaxNode, SyntaxToken, TextRange, TextSize,
11}; 11};
12 12
@@ -89,36 +89,6 @@ const RUSTDOC_FENCE_TOKENS: &[&'static str] = &[
89 "edition2021", 89 "edition2021",
90]; 90];
91 91
92// Basically an owned dyn AttrsOwner without extra Boxing
93struct AttrsOwnerNode {
94 node: SyntaxNode,
95}
96
97impl AttrsOwnerNode {
98 fn new<N: DocCommentsOwner>(node: N) -> Self {
99 AttrsOwnerNode { node: node.syntax().clone() }
100 }
101}
102
103impl AttrsOwner for AttrsOwnerNode {}
104impl AstNode for AttrsOwnerNode {
105 fn can_cast(_: syntax::SyntaxKind) -> bool
106 where
107 Self: Sized,
108 {
109 false
110 }
111 fn cast(_: SyntaxNode) -> Option<Self>
112 where
113 Self: Sized,
114 {
115 None
116 }
117 fn syntax(&self) -> &SyntaxNode {
118 &self.node
119 }
120}
121
122fn doc_attributes<'node>( 92fn doc_attributes<'node>(
123 sema: &Semantics<RootDatabase>, 93 sema: &Semantics<RootDatabase>,
124 node: &'node SyntaxNode, 94 node: &'node SyntaxNode,
diff --git a/crates/syntax/src/ast.rs b/crates/syntax/src/ast.rs
index 38e0b04ef..7f472d4db 100644
--- a/crates/syntax/src/ast.rs
+++ b/crates/syntax/src/ast.rs
@@ -20,8 +20,8 @@ pub use self::{
20 expr_ext::{ArrayExprKind, BinOp, Effect, ElseBranch, LiteralKind, PrefixOp, RangeOp}, 20 expr_ext::{ArrayExprKind, BinOp, Effect, ElseBranch, LiteralKind, PrefixOp, RangeOp},
21 generated::{nodes::*, tokens::*}, 21 generated::{nodes::*, tokens::*},
22 node_ext::{ 22 node_ext::{
23 AttrKind, FieldKind, Macro, NameLike, NameOrNameRef, PathSegmentKind, SelfParamKind, 23 AttrKind, AttrsOwnerNode, FieldKind, Macro, NameLike, NameOrNameRef, PathSegmentKind,
24 SlicePatComponents, StructKind, TypeBoundKind, VisibilityKind, 24 SelfParamKind, SlicePatComponents, StructKind, TypeBoundKind, VisibilityKind,
25 }, 25 },
26 token_ext::*, 26 token_ext::*,
27 traits::*, 27 traits::*,
diff --git a/crates/syntax/src/ast/node_ext.rs b/crates/syntax/src/ast/node_ext.rs
index 5a9834cbb..01f580a40 100644
--- a/crates/syntax/src/ast/node_ext.rs
+++ b/crates/syntax/src/ast/node_ext.rs
@@ -90,6 +90,36 @@ impl NameOwner for Macro {
90 90
91impl AttrsOwner for Macro {} 91impl AttrsOwner for Macro {}
92 92
93/// Basically an owned `dyn AttrsOwner` without extra boxing.
94pub struct AttrsOwnerNode {
95 node: SyntaxNode,
96}
97
98impl AttrsOwnerNode {
99 pub fn new<N: AttrsOwner>(node: N) -> Self {
100 AttrsOwnerNode { node: node.syntax().clone() }
101 }
102}
103
104impl AttrsOwner for AttrsOwnerNode {}
105impl AstNode for AttrsOwnerNode {
106 fn can_cast(_: SyntaxKind) -> bool
107 where
108 Self: Sized,
109 {
110 false
111 }
112 fn cast(_: SyntaxNode) -> Option<Self>
113 where
114 Self: Sized,
115 {
116 None
117 }
118 fn syntax(&self) -> &SyntaxNode {
119 &self.node
120 }
121}
122
93#[derive(Debug, Clone, PartialEq, Eq)] 123#[derive(Debug, Clone, PartialEq, Eq)]
94pub enum AttrKind { 124pub enum AttrKind {
95 Inner, 125 Inner,