Skip to content

Commit

Permalink
Revert "Removes treating first element as operator in SExp"
Browse files Browse the repository at this point in the history
This reverts commit c489a4e.
  • Loading branch information
desaikd committed Jun 10, 2024
1 parent c489a4e commit 5c0f9b9
Show file tree
Hide file tree
Showing 26 changed files with 402 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,37 @@ class IonSExpressionBlock(
IonTypes.LPAREN,
IonTypes.RPAREN
)

override fun buildChildBlockFormatting(child: ASTNode): IonBlockFormattingOptions =
buildSpecialCaseChildBlockFormatting(child) ?:
super.buildChildBlockFormatting(child)

private fun buildSpecialCaseChildBlockFormatting(child: ASTNode): IonBlockFormattingOptions? {

// Lazy evaluate the previous sibling if needed.
val previous by lazy { child.previousSibling() }

/**
* Check if we are the first comment within the expression, there is a special comment
* case where we don't want to apply the child alignment to the comment. For example:
*
* (join // special case comment which is inline with operator
* // child comments are inline with inner values
* anotherValue
* )
*/
if (child elementIsA IonTypes.COMMENT && previous?.elementType == IonTypes.SEXPRESSION_OPERATOR) {

logger.debug { "Formatting [${child.psi.getLineNumber()}] - Special case inline expression comment line" }

val comment = child.psi
val expressionOperator = previous!!

if (comment.isOneLiner() && child.sameLineAs(expressionOperator)) {
return IonBlockFormatting.sameAlignment(this)
}
}

return null
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,37 @@ class IonSExpressionBlock(
IonTypes.LPAREN,
IonTypes.RPAREN
)

override fun buildChildBlockFormatting(child: ASTNode): IonBlockFormattingOptions =
buildSpecialCaseChildBlockFormatting(child) ?:
super.buildChildBlockFormatting(child)

private fun buildSpecialCaseChildBlockFormatting(child: ASTNode): IonBlockFormattingOptions? {

// Lazy evaluate the previous sibling if needed.
val previous by lazy { child.previousSibling() }

/**
* Check if we are the first comment within the expression, there is a special comment
* case where we don't want to apply the child alignment to the comment. For example:
*
* (join // special case comment which is inline with operator
* // child comments are inline with inner values
* anotherValue
* )
*/
if (child elementIsA IonTypes.COMMENT && previous?.elementType == IonTypes.SEXPRESSION_OPERATOR) {

logger.debug { "Formatting [${child.psi.getLineNumber()}] - Special case inline expression comment line" }

val comment = child.psi
val expressionOperator = previous!!

if (comment.isOneLiner() && child.sameLineAs(expressionOperator)) {
return IonBlockFormatting.sameAlignment(this)
}
}

return null
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,37 @@ class IonSExpressionBlock(
IonTypes.LPAREN,
IonTypes.RPAREN
)

override fun buildChildBlockFormatting(child: ASTNode): IonBlockFormattingOptions =
buildSpecialCaseChildBlockFormatting(child) ?:
super.buildChildBlockFormatting(child)

private fun buildSpecialCaseChildBlockFormatting(child: ASTNode): IonBlockFormattingOptions? {

// Lazy evaluate the previous sibling if needed.
val previous by lazy { child.previousSibling() }

/**
* Check if we are the first comment within the expression, there is a special comment
* case where we don't want to apply the child alignment to the comment. For example:
*
* (join // special case comment which is inline with operator
* // child comments are inline with inner values
* anotherValue
* )
*/
if (child elementIsA IonTypes.COMMENT && previous?.elementType == IonTypes.SEXPRESSION_OPERATOR) {

logger.debug { "Formatting [${child.psi.getLineNumber()}] - Special case inline expression comment line" }

val comment = child.psi
val expressionOperator = previous!!

if (comment.isOneLiner() && child.sameLineAs(expressionOperator)) {
return IonBlockFormatting.sameAlignment(this)
}
}

return null
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,37 @@ class IonSExpressionBlock(
IonTypes.LPAREN,
IonTypes.RPAREN
)

override fun buildChildBlockFormatting(child: ASTNode): IonBlockFormattingOptions =
buildSpecialCaseChildBlockFormatting(child) ?:
super.buildChildBlockFormatting(child)

private fun buildSpecialCaseChildBlockFormatting(child: ASTNode): IonBlockFormattingOptions? {

// Lazy evaluate the previous sibling if needed.
val previous by lazy { child.previousSibling() }

/**
* Check if we are the first comment within the expression, there is a special comment
* case where we don't want to apply the child alignment to the comment. For example:
*
* (join // special case comment which is inline with operator
* // child comments are inline with inner values
* anotherValue
* )
*/
if (child elementIsA IonTypes.COMMENT && previous?.elementType == IonTypes.SEXPRESSION_OPERATOR) {

logger.debug { "Formatting [${child.psi.getLineNumber()}] - Special case inline expression comment line" }

val comment = child.psi
val expressionOperator = previous!!

if (comment.isOneLiner() && child.sameLineAs(expressionOperator)) {
return IonBlockFormatting.sameAlignment(this)
}
}

return null
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,37 @@ class IonSExpressionBlock(
IonTypes.LPAREN,
IonTypes.RPAREN
)

override fun buildChildBlockFormatting(child: ASTNode): IonBlockFormattingOptions =
buildSpecialCaseChildBlockFormatting(child) ?:
super.buildChildBlockFormatting(child)

private fun buildSpecialCaseChildBlockFormatting(child: ASTNode): IonBlockFormattingOptions? {

// Lazy evaluate the previous sibling if needed.
val previous by lazy { child.previousSibling() }

/**
* Check if we are the first comment within the expression, there is a special comment
* case where we don't want to apply the child alignment to the comment. For example:
*
* (join // special case comment which is inline with operator
* // child comments are inline with inner values
* anotherValue
* )
*/
if (child elementIsA IonTypes.COMMENT && previous?.elementType == IonTypes.SEXPRESSION_OPERATOR) {

logger.debug { "Formatting [${child.psi.getLineNumber()}] - Special case inline expression comment line" }

val comment = child.psi
val expressionOperator = previous!!

if (comment.isOneLiner() && child.sameLineAs(expressionOperator)) {
return IonBlockFormatting.sameAlignment(this)
}
}

return null
}
}
66 changes: 63 additions & 3 deletions src/main/gen/com/amazon/ion/plugin/intellij/IonParser.java

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions src/main/gen/com/amazon/ion/plugin/intellij/psi/IonKey.java

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions src/main/gen/com/amazon/ion/plugin/intellij/psi/IonTypes.java

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions src/main/gen/com/amazon/ion/plugin/intellij/psi/IonValue.java

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 5c0f9b9

Please sign in to comment.