Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
84 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,31 @@ | ||
package org.jetbrains.vuejs.language | ||
|
||
import com.intellij.lang.HtmlScriptContentProvider | ||
import com.intellij.lang.Language | ||
import com.intellij.lang.LanguageHtmlScriptContentProvider | ||
|
||
interface VueHandledLexer { | ||
fun seenScript():Boolean | ||
fun setSeenScriptType() | ||
fun seenStyle():Boolean | ||
fun setSeenStyleType() | ||
fun seenTag():Boolean | ||
fun getScriptType(): String? | ||
fun getStyleType(): String? | ||
|
||
fun scriptContentViaLang(): HtmlScriptContentProvider? { | ||
return Language.getRegisteredLanguages() | ||
.filter { getScriptType()!!.equals(it.id, ignoreCase = true) } | ||
.map { LanguageHtmlScriptContentProvider.getScriptContentProvider(it) } | ||
.firstOrNull { it != null } | ||
} | ||
|
||
fun styleViaLang(default: Language?): Language? { | ||
if (default != null && getStyleType() != null) { | ||
default.dialects | ||
.filter { getStyleType().equals(it.id, ignoreCase = true) } | ||
.forEach { return it } | ||
} | ||
return null | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
vuejs/src/org/jetbrains/vuejs/language/VueHighlightingLexer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package org.jetbrains.vuejs.language | ||
|
||
import com.intellij.lang.HtmlScriptContentProvider | ||
import com.intellij.lang.Language | ||
import com.intellij.lexer.HtmlHighlightingLexer | ||
import com.intellij.psi.xml.XmlTokenType | ||
|
||
class VueHighlightingLexer : HtmlHighlightingLexer(), VueHandledLexer { | ||
init { | ||
registerHandler(XmlTokenType.XML_NAME, VueLangAttributeHandler()) | ||
} | ||
|
||
override fun findScriptContentProvider(mimeType: String?): HtmlScriptContentProvider? { | ||
val type = super.findScriptContentProvider(mimeType ?: "text/ecmascript-6") | ||
return type ?: scriptContentViaLang() | ||
} | ||
|
||
override fun getStyleLanguage(): Language? { | ||
return styleViaLang(ourDefaultStyleLanguage) ?: super.getStyleLanguage() | ||
} | ||
|
||
override fun seenScript() = seenScript | ||
override fun seenStyle()= seenStyle | ||
override fun seenTag() = seenTag | ||
override fun getScriptType() = scriptType | ||
override fun getStyleType() = styleType | ||
|
||
override fun setSeenScriptType() { | ||
seenContentType = true | ||
} | ||
|
||
override fun setSeenStyleType() { | ||
seenStylesheetType = true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
vuejs/src/org/jetbrains/vuejs/language/VueSyntaxHighlighterFactory.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package org.jetbrains.vuejs.language | ||
|
||
import com.intellij.ide.highlighter.HtmlFileHighlighter | ||
import com.intellij.lexer.Lexer | ||
import com.intellij.openapi.fileTypes.SingleLazyInstanceSyntaxHighlighterFactory | ||
import com.intellij.openapi.fileTypes.SyntaxHighlighter | ||
|
||
class VueSyntaxHighlighterFactory : SingleLazyInstanceSyntaxHighlighterFactory() { | ||
override fun createHighlighter(): SyntaxHighlighter { | ||
return object : HtmlFileHighlighter() { | ||
override fun getHighlightingLexer(): Lexer { | ||
return VueHighlightingLexer() | ||
} | ||
} | ||
} | ||
} |