Skip to content

Commit

Permalink
[ completion ] Add ignore case
Browse files Browse the repository at this point in the history
  • Loading branch information
ice1000 committed Apr 25, 2018
1 parent 0272621 commit 445e17b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
2 changes: 1 addition & 1 deletion common/src/org/ice1000/devkt/config/settings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion common/src/org/ice1000/devkt/ui/dialogs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ interface IFind {
}
select(0)
} catch (e: PatternSyntaxException) {
//TODO 做出提示
document.window.dialog("Invalid regex: $regex", MessageType.Error)
}
}

Expand Down
14 changes: 6 additions & 8 deletions common/src/org/ice1000/devkt/ui/editor-ui.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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.*

Expand Down Expand Up @@ -73,8 +70,8 @@ class DevKtDocumentHandler<TextAttributes>(
override fun getLength() = document.length
private val lineCommentStart get() = currentLanguage.lineCommentStart
private val blockComment get() = currentLanguage.blockComment
var initialCompletionList: Set<CompletionElement> = emptySet()
val lexicalCompletionList: MutableSet<CompletionElement> = hashSetOf()
private var initialCompletionList: Set<CompletionElement> = emptySet()
private val lexicalCompletionList: MutableSet<CompletionElement> = hashSetOf()
override val canUndo get() = undoManager.canUndo
override val canRedo get() = undoManager.canRedo

Expand Down Expand Up @@ -296,11 +293,12 @@ class DevKtDocumentHandler<TextAttributes>(
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()
Expand All @@ -325,7 +323,7 @@ class DevKtDocumentHandler<TextAttributes>(
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)
}
}
Expand All @@ -344,7 +342,7 @@ class DevKtDocumentHandler<TextAttributes>(
.filter { it !is PsiWhiteSpace }
.forEach { psi ->
if (currentLanguage.shouldAddAsCompletion(psi))
lexicalCompletionList.add(CompletionElement(psi.text))
lexicalCompletionList += CompletionElement(psi.text)
language.annotate(psi, this, colorScheme)
}
}
Expand Down

0 comments on commit 445e17b

Please sign in to comment.