Skip to content

Commit

Permalink
[ lang ] Update plain text
Browse files Browse the repository at this point in the history
  • Loading branch information
ice1000 committed Apr 20, 2018
1 parent 527aa57 commit 2bed9db
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions common/src/org/ice1000/devkt/lang/languages.kt
Original file line number Diff line number Diff line change
Expand Up @@ -74,22 +74,24 @@ abstract class DevKtLanguage<TextAttributes> internal constructor(
* @see DevKtLanguage
*/
sealed class BuiltinDevKtLanguage<TextAttributes>(
private val annotator: Annotator<TextAttributes>,
private val syntaxHighlighter: SyntaxHighlighter<TextAttributes>,
annotator: Annotator<TextAttributes>,
syntaxHighlighter: SyntaxHighlighter<TextAttributes>,
language: Language
) : DevKtLanguage<TextAttributes>(language),
Annotator<TextAttributes> by annotator,
SyntaxHighlighter<TextAttributes> by syntaxHighlighter {
override fun satisfies(fileName: String) = false
override val lineCommentStart = "//"
override val blockComment: Pair<String, String>? = "/*" to "*/"
override fun handleTyping(offset: Int, text: String?, element: PsiElement?, document: IDevKtDocumentHandler<TextAttributes>) {
element.takeIf { text == "\n" }?.run {
val whitespace = containingFile.findElementAt(document.startOffsetOf(document.lineOf(offset)))
as? PsiWhiteSpace ?: return@run null
super.handleTyping(offset, whitespace.text, element, document)
} ?: super.handleTyping(offset, text, element, document)
}
override fun handleTyping(
offset: Int,
text: String?,
element: PsiElement?,
document: IDevKtDocumentHandler<TextAttributes>) = element.takeIf { text == "\n" }?.run {
val whitespace = containingFile.findElementAt(document.startOffsetOf(document.lineOf(offset)))
as? PsiWhiteSpace ?: return@run null
super.handleTyping(offset, whitespace.text, element, document)
} ?: super.handleTyping(offset, text, element, document)
}

/**
Expand Down Expand Up @@ -138,12 +140,11 @@ class Kotlin<TextAttributes>(
class PlainText<TextAttributes>(
annotator: Annotator<TextAttributes>,
syntaxHighlighter: SyntaxHighlighter<TextAttributes>
) : BuiltinDevKtLanguage<TextAttributes>(
annotator,
syntaxHighlighter,
PlainTextLanguage.INSTANCE) {
override fun satisfies(fileName: String) = fileName.endsWith(".txt") || '.' !in fileName
) : DevKtLanguage<TextAttributes>(PlainTextLanguage.INSTANCE),
Annotator<TextAttributes> by annotator,
SyntaxHighlighter<TextAttributes> by syntaxHighlighter {
override fun satisfies(fileName: String) =
fileName.endsWith(".txt") && !fileName.endsWith(".lua.txt") || '.' !in fileName
private val lexer = EmptyLexer()
override fun createLexer(project: Project) = lexer
override val blockComment: Pair<String, String>? get() = null
}

0 comments on commit 2bed9db

Please sign in to comment.