Skip to content

Commit

Permalink
Merge pull request #164 from pontem-network/indent-fixes
Browse files Browse the repository at this point in the history
fix indentation in spec statements
  • Loading branch information
mkurnikov authored Jun 27, 2024
2 parents f03af08 + cb02ae5 commit a44c64e
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/main/kotlin/org/move/ide/formatter/impl/indent.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.intellij.lang.ASTNode
import org.move.ide.formatter.MoveFmtBlock
import org.move.lang.MvElementTypes.*
import org.move.lang.core.psi.MvExpr
import org.move.lang.core.psi.MvPragmaSpecStmt

fun MoveFmtBlock.computeChildIndent(childNode: ASTNode): Indent? {
val parentNode = node
Expand Down Expand Up @@ -52,6 +53,9 @@ fun MoveFmtBlock.computeChildIndent(childNode: ASTNode): Indent? {
// .myotherfield
parentPsi is MvExpr -> Indent.getContinuationWithoutFirstIndent()

// same thing as previous one, but for spec statements
parentPsi.isSpecStmt -> Indent.getContinuationWithoutFirstIndent()

else -> Indent.getNoneIndent()
}
}
Expand Down
8 changes: 8 additions & 0 deletions src/main/kotlin/org/move/ide/formatter/impl/utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ val DELIMITED_BLOCKS = orSet(

fun ASTNode?.isWhitespaceOrEmpty() = this == null || textLength == 0 || elementType == TokenType.WHITE_SPACE

val PsiElement.isSpecStmt: Boolean
get() = this is MvSchemaFieldStmt
|| this is MvGlobalVariableStmt
|| this is MvPragmaSpecStmt
|| this is MvUpdateSpecStmt
|| this is MvIncludeStmt
|| this is MvApplySchemaStmt

val PsiElement.isTopLevelItem: Boolean
get() = (this is MvModule || this is MvAddressDef || this is MvScript || this is MvModuleSpec)
&& parent is MoveFile
Expand Down
5 changes: 5 additions & 0 deletions src/test/resources/org/move/ide/formatter.fixtures/specs.move
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ module M {
spec initialize {
assert true;

pragma hello = world,
hello2 = world2;
include
MySchema;

/// After genesis, time progresses monotonically.
invariant update
old(is_operating()) ==> old(spec_now_microseconds()) <= spec_now_microseconds();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ module M {
spec initialize {
assert true;

pragma hello = world,
hello2 = world2;
include
MySchema;

/// After genesis, time progresses monotonically.
invariant update
old(is_operating()) ==> old(spec_now_microseconds()) <= spec_now_microseconds();
Expand Down

0 comments on commit a44c64e

Please sign in to comment.