From 445e17b36c9e17cd39a605e260ad81e0c89c39ac Mon Sep 17 00:00:00 2001 From: ice1000 Date: Wed, 25 Apr 2018 20:48:31 +0800 Subject: [PATCH] [ completion ] Add ignore case --- common/src/org/ice1000/devkt/config/settings.kt | 2 +- common/src/org/ice1000/devkt/ui/dialogs.kt | 2 +- common/src/org/ice1000/devkt/ui/editor-ui.kt | 14 ++++++-------- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/common/src/org/ice1000/devkt/config/settings.kt b/common/src/org/ice1000/devkt/config/settings.kt index 10bdfc4..5aca899 100644 --- a/common/src/org/ice1000/devkt/config/settings.kt +++ b/common/src/org/ice1000/devkt/config/settings.kt @@ -86,7 +86,7 @@ object GlobalSettings { var shortcutBlockComment = ShortCut(true, false, true, Key.SLASH) var shortcutFind = ShortCut(true, false, false, Key.F) var shortcutReplace = ShortCut(true, false, false, Key.R) - var shortcutCompletion = ShortCut(true, false, false, Key.SPACE) + var shortcutCompletion = ShortCut(true, false, true, Key.SPACE) private fun defaultOf(name: String, value: String) { if (!properties.containsKey(name)) properties[name] = value diff --git a/common/src/org/ice1000/devkt/ui/dialogs.kt b/common/src/org/ice1000/devkt/ui/dialogs.kt index 675a89d..4510148 100644 --- a/common/src/org/ice1000/devkt/ui/dialogs.kt +++ b/common/src/org/ice1000/devkt/ui/dialogs.kt @@ -47,7 +47,7 @@ interface IFind { } select(0) } catch (e: PatternSyntaxException) { - //TODO 做出提示 + document.window.dialog("Invalid regex: $regex", MessageType.Error) } } diff --git a/common/src/org/ice1000/devkt/ui/editor-ui.kt b/common/src/org/ice1000/devkt/ui/editor-ui.kt index 7700e23..ba96c75 100644 --- a/common/src/org/ice1000/devkt/ui/editor-ui.kt +++ b/common/src/org/ice1000/devkt/ui/editor-ui.kt @@ -7,13 +7,10 @@ import org.ice1000.devkt.config.GlobalSettings import org.ice1000.devkt.lang.* import org.ice1000.devkt.openapi.ColorScheme import org.ice1000.devkt.openapi.ExtendedDevKtLanguage -import org.ice1000.devkt.openapi.nodeType import org.ice1000.devkt.openapi.ui.* import org.ice1000.devkt.openapi.util.* -import org.jetbrains.kotlin.com.intellij.lang.ASTNode import org.jetbrains.kotlin.com.intellij.psi.* import org.jetbrains.kotlin.com.intellij.psi.tree.TokenSet -import org.jetbrains.kotlin.psi.psiUtil.endOffset import org.jetbrains.kotlin.psi.psiUtil.startOffset import java.util.* @@ -73,8 +70,8 @@ class DevKtDocumentHandler( override fun getLength() = document.length private val lineCommentStart get() = currentLanguage.lineCommentStart private val blockComment get() = currentLanguage.blockComment - var initialCompletionList: Set = emptySet() - val lexicalCompletionList: MutableSet = hashSetOf() + private var initialCompletionList: Set = emptySet() + private val lexicalCompletionList: MutableSet = hashSetOf() override val canUndo get() = undoManager.canUndo override val canRedo get() = undoManager.canRedo @@ -296,11 +293,12 @@ class DevKtDocumentHandler( val caretPosition = document.caretPosition val currentText = currentNode.text.substring(0, caretPosition - currentNode.start) val completions = initialCompletionList + lexicalCompletionList - .filter { it.lookup.let { it.startsWith(currentText) && it != currentText } } + .filter { it.lookup.let { it.startsWith(currentText, true) && it != currentText } } if (completions.isNotEmpty()) window.showCompletionPopup(completions).show() } + // TODO: make async override fun reparse() { while (highlightCache.size <= document.length) highlightCache.add(null) // val time = System.currentTimeMillis() @@ -325,7 +323,7 @@ class DevKtDocumentHandler( if (end == caretPosition) currentTypingNodeCache = node if (text.isNotBlank() && text.length > 1) - lexicalCompletionList.add(CompletionElement(text)) + lexicalCompletionList += CompletionElement(text) highlight(start, end, language.attributesOf(type, colorScheme) ?: colorScheme.default) } } @@ -344,7 +342,7 @@ class DevKtDocumentHandler( .filter { it !is PsiWhiteSpace } .forEach { psi -> if (currentLanguage.shouldAddAsCompletion(psi)) - lexicalCompletionList.add(CompletionElement(psi.text)) + lexicalCompletionList += CompletionElement(psi.text) language.annotate(psi, this, colorScheme) } }