@@ -15,9 +15,11 @@ function innerBody(context: TreeIndentContext) {
1515 break
1616 } else if ( before . name == "Comment" ) {
1717 pos = before . from
18- } else if ( before . name == "Body" ) {
18+ } else if ( before . name == "Body" || before . name == "MatchBody" ) {
1919 if ( context . baseIndentFor ( before ) + context . unit <= lineIndent ) found = before
2020 node = before
21+ } else if ( before . name == "MatchClause" ) {
22+ node = before
2123 } else if ( before . type . is ( "Statement" ) ) {
2224 node = before
2325 } else {
@@ -40,7 +42,7 @@ function indentBody(context: TreeIndentContext, node: SyntaxNode) {
4042 // A normally deindenting keyword that appears at a higher
4143 // indentation than the block should probably be handled by the next
4244 // level
43- if ( / ^ \s * ( e l s e : | e l i f | e x c e p t | f i n a l l y : ) / . test ( context . textAfter ) && context . lineIndent ( context . pos , - 1 ) > base )
45+ if ( / ^ \s * ( e l s e : | e l i f | e x c e p t | f i n a l l y : | c a s e \s + [ ^ = : ] + : ) / . test ( context . textAfter ) && context . lineIndent ( context . pos , - 1 ) > base )
4446 return null
4547 return base + context . unit
4648}
@@ -57,9 +59,20 @@ export const pythonLanguage = LRLanguage.define({
5759 let inner = innerBody ( context )
5860 return indentBody ( context , inner || context . node ) ?? context . continue ( )
5961 } ,
62+
63+ MatchBody : context => {
64+ let inner = innerBody ( context )
65+ return indentBody ( context , inner || context . node ) ?? context . continue ( )
66+ } ,
67+
6068 IfStatement : cx => / ^ \s * ( e l s e : | e l i f ) / . test ( cx . textAfter ) ? cx . baseIndent : cx . continue ( ) ,
6169 "ForStatement WhileStatement" : cx => / ^ \s * e l s e : / . test ( cx . textAfter ) ? cx . baseIndent : cx . continue ( ) ,
6270 TryStatement : cx => / ^ \s * ( e x c e p t | f i n a l l y : | e l s e : ) / . test ( cx . textAfter ) ? cx . baseIndent : cx . continue ( ) ,
71+ MatchStatement : cx => {
72+ if ( / ^ \s * c a s e / . test ( cx . textAfter ) ) return cx . baseIndent + cx . unit
73+ return cx . continue ( )
74+ } ,
75+
6376 "TupleExpression ComprehensionExpression ParamList ArgList ParenthesizedExpression" : delimitedIndent ( { closing : ")" } ) ,
6477 "DictionaryExpression DictionaryComprehensionExpression SetExpression SetComprehensionExpression" : delimitedIndent ( { closing : "}" } ) ,
6578 "ArrayExpression ArrayComprehensionExpression" : delimitedIndent ( { closing : "]" } ) ,
@@ -69,6 +82,7 @@ export const pythonLanguage = LRLanguage.define({
6982 return ( inner && indentBody ( context , inner ) ) ?? context . continue ( )
7083 }
7184 } ) ,
85+
7286 foldNodeProp . add ( {
7387 "ArrayExpression DictionaryExpression SetExpression TupleExpression" : foldInside ,
7488 Body : ( node , state ) => ( { from : node . from + 1 , to : node . to - ( node . to == state . doc . length ? 0 : 1 ) } )
@@ -82,7 +96,8 @@ export const pythonLanguage = LRLanguage.define({
8296 "F" , "FR" , "RF" , "R" , "U" , "B" , "BR" , "RB" ]
8397 } ,
8498 commentTokens : { line : "#" } ,
85- indentOnInput : / ^ \s * ( [ \} \] \) ] | e l s e : | e l i f | e x c e p t | f i n a l l y : ) $ /
99+ // Indent logic logic are triggered upon below input patterns
100+ indentOnInput : / ^ \s * ( [ \} \] \) ] | e l s e : | e l i f | e x c e p t | f i n a l l y : | c a s e \s + [ ^ : ] * : ? ) $ / ,
86101 }
87102} )
88103
0 commit comments