@@ -67,6 +67,7 @@ import com.intellij.psi.formatter.xml.XmlTagBlock
67
67
import com.intellij.psi.html.HtmlTag
68
68
import com.intellij.psi.impl.source.PsiFileImpl
69
69
import com.intellij.psi.impl.source.html.HtmlDocumentImpl
70
+ import com.intellij.psi.impl.source.html.HtmlFileImpl
70
71
import com.intellij.psi.impl.source.resolve.reference.impl.PsiMultiReference
71
72
import com.intellij.psi.impl.source.tree.LeafElement
72
73
import com.intellij.psi.impl.source.tree.PsiWhiteSpaceImpl
@@ -83,6 +84,7 @@ import com.intellij.refactoring.suggested.endOffset
83
84
import com.intellij.refactoring.suggested.startOffset
84
85
import com.intellij.util.Processor
85
86
import com.intellij.xml.template.formatter.AbstractXmlTemplateFormattingModelBuilder
87
+ import com.intellij.xml.template.formatter.TemplateFormatUtil
86
88
import java.util.function.Predicate
87
89
import javax.swing.Icon
88
90
@@ -459,16 +461,32 @@ class GtsFileViewProviderFactory: FileViewProviderFactory {
459
461
460
462
}
461
463
462
- class GtsFileViewProvider (manager : PsiManager , virtualFile : VirtualFile , eventSystemEnabled : Boolean , private val baseLang : GtsLanguage = GtsLanguage .INSTANCE ) : MultiplePsiFilesPerDocumentFileViewProvider(manager, virtualFile, eventSystemEnabled), TemplateLanguageFileViewProvider {
464
+ class GtsFileViewProvider (manager : PsiManager , virtualFile : VirtualFile , eventSystemEnabled : Boolean , public val baseLang : GtsLanguage = GtsLanguage .INSTANCE ) : MultiplePsiFilesPerDocumentFileViewProvider(manager, virtualFile, eventSystemEnabled), TemplateLanguageFileViewProvider {
463
465
464
- override fun findElementAt (offset : Int ): PsiElement ? {
465
- val element = super .findElementAt(offset)
466
- if (element.elementType == HbTokenTypes .CONTENT ) {
467
- return super .findElementAt(offset, HTMLLanguage .INSTANCE )
466
+ override fun findElementAt (offset : Int , language : Language ): PsiElement ? {
467
+ var element: PsiElement ?
468
+ if (language == baseLang) {
469
+ this .languages.forEach {
470
+ element = super .findElementAt(offset, it)
471
+ if (element !is OuterLanguageElement ) {
472
+ return element
473
+ }
474
+ }
468
475
}
476
+ element = super .findElementAt(offset, language)
469
477
return element
470
478
}
471
479
480
+ override fun findElementAt (offset : Int ): PsiElement ? {
481
+ this .languages.forEach {
482
+ val element = super .findElementAt(offset, it)
483
+ if (element !is OuterLanguageElement ) {
484
+ return element
485
+ }
486
+ }
487
+ return null
488
+ }
489
+
472
490
override fun findReferenceAt (offset : Int ): PsiReference ? {
473
491
val ref = super .findReferenceAt(offset)
474
492
if (ref is PsiMultiReference ) {
@@ -904,17 +922,20 @@ class RootBlockWrapper(val block: DataLanguageBlockWrapper, val policy: HtmlPoli
904
922
}
905
923
906
924
fun getBaseIndent (forChild : Boolean = false): Indent ? {
907
- val file = this .node!! .psi.containingFile.originalFile
925
+ val viewProvider = this .node!! .psi.containingFile.viewProvider
926
+ val htmlFile = viewProvider.getPsi(HTMLLanguage .INSTANCE )
927
+ val jsFile = viewProvider.getPsi(JavaScriptSupportLoader .TYPESCRIPT ) ? : viewProvider.getPsi(JavaScriptSupportLoader .ECMA_SCRIPT_6 )
908
928
val project = this .node!! .psi.project
909
- val document = PsiDocumentManager .getInstance(project).getDocument(file)!!
910
- val INDENT_SIZE = this .policy.settings.getIndentOptionsByDocument(project, document).INDENT_SIZE
929
+ val document = PsiDocumentManager .getInstance(project).getDocument(htmlFile)!!
930
+ val INDENT_SIZE = this .policy.settings.getIndentSize(htmlFile.language.associatedFileType)
931
+ val JS_INDENT_SIZE = this .policy.settings.getIndentSize(jsFile.language.associatedFileType)
911
932
if (this .parent != null ) {
912
933
val blockRef = this .parent as ? JSAstBlockWrapper ? : ((this .parent as JsBlockWrapper ).parent as JSAstBlockWrapper )
913
934
914
935
var startOffset: Int? = null
915
936
if (blockRef.node!! .psi is JSClass ) {
916
937
val psiRef = blockRef.node!! .psi.parent
917
- startOffset = psiRef.textRange?.startOffset?.let { it + INDENT_SIZE }
938
+ startOffset = psiRef.textRange?.startOffset?.let { it + JS_INDENT_SIZE }
918
939
}
919
940
920
941
if (blockRef.node!! .psi.parent is JSVarStatement ) {
@@ -924,7 +945,7 @@ class RootBlockWrapper(val block: DataLanguageBlockWrapper, val policy: HtmlPoli
924
945
val lineTpl = document.getLineNumber(this .textRange.startOffset)
925
946
val parentLine = document.getLineNumber(startOffset)
926
947
if (lineTpl != parentLine) {
927
- startOffset + = INDENT_SIZE
948
+ startOffset + = JS_INDENT_SIZE
928
949
}
929
950
}
930
951
}
@@ -936,7 +957,7 @@ class RootBlockWrapper(val block: DataLanguageBlockWrapper, val policy: HtmlPoli
936
957
val lineTpl = document.getLineNumber(this .textRange.startOffset)
937
958
val parentLine = document.getLineNumber(startOffset)
938
959
if (lineTpl != parentLine) {
939
- startOffset + = INDENT_SIZE
960
+ startOffset + = JS_INDENT_SIZE
940
961
}
941
962
}
942
963
}
@@ -1012,6 +1033,7 @@ class GtsFormattingModelBuilder : AbstractXmlTemplateFormattingModelBuilder() {
1012
1033
}
1013
1034
}
1014
1035
1036
+
1015
1037
override fun createModel (formattingContext : FormattingContext ): FormattingModel {
1016
1038
1017
1039
if (formattingContext.node is OuterLanguageElement ) {
0 commit comments