File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -213,6 +213,28 @@ pub trait AttrsOwnerEdit: ast::HasAttrs {
213213 }
214214 }
215215 }
216+
217+ fn add_attr ( & self , attr : ast:: Attr ) {
218+ add_attr ( self . syntax ( ) , attr) ;
219+
220+ fn add_attr ( node : & SyntaxNode , attr : ast:: Attr ) {
221+ let indent = IndentLevel :: from_node ( node) ;
222+ attr. reindent_to ( indent) ;
223+
224+ let after_attrs_and_comments = node
225+ . children_with_tokens ( )
226+ . find ( |it| !matches ! ( it. kind( ) , WHITESPACE | COMMENT | ATTR ) )
227+ . map_or ( Position :: first_child_of ( node) , |it| Position :: before ( it) ) ;
228+
229+ ted:: insert_all (
230+ after_attrs_and_comments,
231+ vec ! [
232+ attr. syntax( ) . clone( ) . into( ) ,
233+ make:: tokens:: whitespace( & format!( "\n {indent}" ) ) . into( ) ,
234+ ] ,
235+ )
236+ }
237+ }
216238}
217239
218240impl < T : ast:: HasAttrs > AttrsOwnerEdit for T { }
You can’t perform that action at this time.
0 commit comments