@@ -7,11 +7,7 @@ use rowan::SyntaxElement;
77
88use crate :: {
99 algo:: neighbor,
10- ast:: {
11- self ,
12- edit:: { AstNodeEdit , IndentLevel } ,
13- make, GenericParamsOwner ,
14- } ,
10+ ast:: { self , edit:: IndentLevel , make, GenericParamsOwner } ,
1511 ted:: { self , Position } ,
1612 AstNode , AstToken , Direction ,
1713 SyntaxKind :: { ATTR , COMMENT , WHITESPACE } ,
@@ -20,7 +16,7 @@ use crate::{
2016
2117use super :: NameOwner ;
2218
23- pub trait GenericParamsOwnerEdit : ast:: GenericParamsOwner + AstNodeEdit {
19+ pub trait GenericParamsOwnerEdit : ast:: GenericParamsOwner {
2420 fn get_or_create_generic_param_list ( & self ) -> ast:: GenericParamList ;
2521 fn get_or_create_where_clause ( & self ) -> ast:: WhereClause ;
2622}
@@ -198,7 +194,7 @@ fn create_generic_param_list(position: Position) -> ast::GenericParamList {
198194 gpl
199195}
200196
201- pub trait AttrsOwnerEdit : ast:: AttrsOwner + AstNodeEdit {
197+ pub trait AttrsOwnerEdit : ast:: AttrsOwner {
202198 fn remove_attrs_and_docs ( & self ) {
203199 remove_attrs_and_docs ( self . syntax ( ) ) ;
204200
@@ -222,7 +218,7 @@ pub trait AttrsOwnerEdit: ast::AttrsOwner + AstNodeEdit {
222218 }
223219}
224220
225- impl < T : ast:: AttrsOwner + AstNodeEdit > AttrsOwnerEdit for T { }
221+ impl < T : ast:: AttrsOwner > AttrsOwnerEdit for T { }
226222
227223impl ast:: GenericParamList {
228224 pub fn add_generic_param ( & self , generic_param : ast:: GenericParam ) {
@@ -487,6 +483,26 @@ fn normalize_ws_between_braces(node: &SyntaxNode) -> Option<()> {
487483 Some ( ( ) )
488484}
489485
486+ pub trait Indent : AstNode + Clone + Sized {
487+ fn indent_level ( & self ) -> IndentLevel {
488+ IndentLevel :: from_node ( self . syntax ( ) )
489+ }
490+ fn indent ( & self , level : IndentLevel ) -> & Self {
491+ level. increase_indent ( self . syntax ( ) ) ;
492+ self
493+ }
494+ fn dedent ( & self , level : IndentLevel ) -> & Self {
495+ level. decrease_indent ( self . syntax ( ) ) ;
496+ self
497+ }
498+ fn reset_indent ( & self ) -> & Self {
499+ let level = IndentLevel :: from_node ( self . syntax ( ) ) ;
500+ self . dedent ( level)
501+ }
502+ }
503+
504+ impl < N : AstNode + Clone > Indent for N { }
505+
490506#[ cfg( test) ]
491507mod tests {
492508 use std:: fmt;
@@ -526,4 +542,22 @@ mod tests {
526542 check_create_gpl :: < ast:: Enum > ( "enum E" , "enum E<>" ) ;
527543 check_create_gpl :: < ast:: Enum > ( "enum E {" , "enum E<> {" ) ;
528544 }
545+
546+ #[ test]
547+ fn test_increase_indent ( ) {
548+ let arm_list = ast_mut_from_text :: < ast:: Fn > (
549+ "fn foo() {
550+ ;
551+ ;
552+ }" ,
553+ ) ;
554+ arm_list. indent ( IndentLevel ( 2 ) ) ;
555+ assert_eq ! (
556+ arm_list. to_string( ) ,
557+ "fn foo() {
558+ ;
559+ ;
560+ }" ,
561+ ) ;
562+ }
529563}
0 commit comments