Skip to content

Commit

Permalink
fixed: TAB is not hardcoded anymore, 'contains' function searches for…
Browse files Browse the repository at this point in the history
… char

Resolves: #148
  • Loading branch information
Dmitry Kochik committed Jul 29, 2021
1 parent e7e2d56 commit 062f336
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import com.jetbrains.python.psi.PyCallExpression
import com.jetbrains.snakecharm.SnakemakeBundle
import com.jetbrains.snakecharm.lang.psi.SmkRuleOrCheckpointArgsSection

const val TAB = " "

class SmkMultilineFunctionCallInspection : SnakemakeInspection() {
override fun buildVisitor(
holder: ProblemsHolder,
Expand Down Expand Up @@ -53,7 +51,7 @@ class SmkMultilineFunctionCallInspection : SnakemakeInspection() {
) {
var element = expression.argumentList?.firstChild
while (element != null) {
if (element.elementType == TokenType.WHITE_SPACE && element.text.contains("\n")) {
if (element.elementType == TokenType.WHITE_SPACE && element.text.contains('\n')) {
incorrectElements.add(element)
break
}
Expand All @@ -74,10 +72,10 @@ class SmkMultilineFunctionCallInspection : SnakemakeInspection() {
return
}
val argumentList = (startElement as SmkRuleOrCheckpointArgsSection).argumentList ?: return
val indent = startElement.prevSibling.text
val indent = startElement.prevSibling.text.replace("\n", "")
// Moves every argument list element to new line
argumentList.arguments.forEach { expression ->
doc.insertString(expression.startOffset, "$indent$TAB")
doc.insertString(expression.startOffset, "\n$indent$indent")
PsiDocumentManager.getInstance(project).commitDocument(doc)
}
// Deletes every incorrect whitespace
Expand All @@ -89,7 +87,7 @@ class SmkMultilineFunctionCallInspection : SnakemakeInspection() {
space.delete()
PsiDocumentManager.getInstance(project).doPostponedOperationsAndUnblockDocument(doc)
if (!hasComment) {
doc.insertString(offset, "$indent$TAB$TAB")
doc.insertString(offset, "\n$indent$indent$indent")
PsiDocumentManager.getInstance(project).commitDocument(doc)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ open class SmkRuleOrCheckpointArgsSectionImpl(node: ASTNode) : SmkArgsSectionImp
while (true) {
node = when (node.elementType) {
TokenType.WHITE_SPACE -> {
if (node.text.contains("\n")) {
if (node.text.contains('\n')) {
return true
}
node.treeNext
Expand Down

0 comments on commit 062f336

Please sign in to comment.