Skip to content

Commit ef9ac9f

Browse files
committed
fix
1 parent 0f81575 commit ef9ac9f

File tree

1 file changed

+15
-20
lines changed

1 file changed

+15
-20
lines changed

src/main/kotlin/com/emberjs/gts/GtsSupport.kt

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ import com.intellij.refactoring.suggested.endOffset
9090
import com.intellij.refactoring.suggested.startOffset
9191
import com.intellij.util.Processor
9292
import com.intellij.xml.template.formatter.AbstractXmlTemplateFormattingModelBuilder
93+
import java.util.WeakHashMap
9394
import java.util.function.Predicate
9495
import javax.swing.Icon
9596

@@ -797,11 +798,16 @@ val NoWrap by lazy {
797798
Wrap.createWrap(WrapType.NONE, false).apply { ignoreParentWraps() }
798799
}
799800

800-
class BlockData(parent1: Block, node: ASTNode, subBlocks: MutableList<Block>) {
801-
val parent: Block = parent1
802-
val node: ASTNode = node
803-
val subBlocks: MutableList<Block> = subBlocks
804-
}
801+
class BlockInfo(val parent: Block, val originalBlock: Block)
802+
803+
val blockinfo = WeakHashMap<Block, BlockInfo>()
804+
805+
val Block.block: Block
806+
get() = blockinfo.get(this)!!.originalBlock
807+
808+
val Block.parent: Block
809+
get() = blockinfo.get(this)!!.parent
810+
805811

806812
open class SyntheticBlockWrapper(val block: SyntheticBlock, val hbsBlock: Block?, val styleSettings: CodeStyleSettings): Block by block {
807813

@@ -813,7 +819,7 @@ open class SyntheticBlockWrapper(val block: SyntheticBlock, val hbsBlock: Block?
813819
return b.debugName ?: b.javaClass.simpleName
814820
}
815821

816-
fun mapToWrapper(block: Block): Block? {
822+
fun mapToWrapper(block: Block): Block {
817823
if (block is ASTBlock && block.node != null) {
818824
return JSAstBlockWrapper(block, block.node!!, this, hbsBlock, styleSettings)
819825
}
@@ -839,35 +845,24 @@ open class SyntheticBlockWrapper(val block: SyntheticBlock, val hbsBlock: Block?
839845
}
840846
}
841847

842-
val psiElement = this.astnode?.psi
843-
if (psiElement is JSVariable || (psiElement is JSExpressionStatement) && psiElement.children.find { it is JSAssignmentExpression } != null) {
844-
val last = PsiTreeUtil.collectElements(psiElement) { it is JSLiteralExpression}.lastOrNull()
845-
if (last is JSLiteralExpression && last.textLength == 0 && last.textOffset == psiElement.endOffset) {
846-
val outerLanguageBlock = parent?.parent?.nexOuterLanguageBlock(parent.block) ?: parent?.nexOuterLanguageBlock(this.block)
847-
if (outerLanguageBlock != null) {
848-
outerLanguageBlock.patched = true
849-
outerLanguageBlock.parent = this
850-
}
851-
}
852-
}
853848
this.cachedBlocks = blocks
854849
return blocks
855850
}
856851
}
857852

858853

859854
// wrapper to patch JsBlocks to include outer language block into JSAssignmentExpression and JSVarStatement
860-
open class JsBlockWrapper(val block: Block, val nnode: ASTNode, val parent: BlockData?, var hbsBlock: Block? = null, val styleSettings: CodeStyleSettings): JSBlock(
855+
open class JsBlockWrapper(val block: Block, val nnode: ASTNode, val parent: Block?, var hbsBlock: Block? = null, val styleSettings: CodeStyleSettings): JSBlock(
861856
nnode, block.alignment, block.indent, block.wrap, styleSettings) {
862857

863-
private var cachedBlocks: MutableList<JsBlockWrapper>? = null
858+
private var cachedBlocks: MutableList<Block>? = null
864859

865860
init {
866861
this.subBlocks
867862
}
868863

869864
override fun getWrap(): Wrap? {
870-
if (parent?.sub Blocks?.lastOrNull()?.block is RootBlockWrapper) {
865+
if (parent?.subBlocks?.lastOrNull()?.block is RootBlockWrapper) {
871866
return NoWrap
872867
}
873868
if (subBlocks.lastOrNull()?.block is RootBlockWrapper) {

0 commit comments

Comments
 (0)