Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix indentation in spec statements #164

Merged
merged 1 commit into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading