Skip to content

Commit

Permalink
Fix switch statements indentation when formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
waleedyaseen committed Oct 7, 2023
1 parent e5d0c69 commit 55fb103
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- Fix regular expressions not being allowed in hook transmits list.
- Fix invalid symbol file inspection reporting an error for "commands.sym".
- Fix "Create procedure" placement of script.
- Fix switch statements indentation when formatting.

### Changed
- Inspections that require symbols will no longer run on files outside the project.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ import io.runescript.plugin.lang.psi.RsElementTypes

object RsBlockFactory {
fun create(context: RsFormatterContext, parent: RsBlock, node: ASTNode): RsBlock {
val childIndent = parent.childIndent ?: Indent.getNoneIndent()
return when (node.elementType) {
RsElementTypes.SCRIPT -> RsScriptBlock(context, node)
RsElementTypes.BLOCK_STATEMENT -> RsBracedBlock(context, node)
RsElementTypes.STATEMENT_LIST -> RsStatementListBlock(context, node)
RsElementTypes.SWITCH_STATEMENT -> RsSwitchStatementBlock(context, node)
RsElementTypes.SWITCH_STATEMENT -> RsSwitchStatementBlock(context, node, childIndent)
RsElementTypes.SWITCH_CASE -> RsSwitchCaseBlock(context, node)
else -> RsBlock(context, node, parent.childIndent ?: Indent.getNoneIndent(), null, null)
else -> RsBlock(context, node, childIndent, null, null)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import com.intellij.lang.ASTNode
import io.runescript.plugin.ide.formatter.RsFormatterContext
import io.runescript.plugin.ide.formatter.blocks.RsBlock

class RsSwitchStatementBlock(context: RsFormatterContext, node: ASTNode)
: RsBlock(context, node, Indent.getNoneIndent(), null, null) {
class RsSwitchStatementBlock(context: RsFormatterContext, node: ASTNode, indent: Indent) :
RsBlock(context, node, indent, null, null) {

override fun getChildIndent(): Indent? {
return Indent.getNoneIndent()
Expand Down

0 comments on commit 55fb103

Please sign in to comment.