Skip to content

Commit

Permalink
Merge pull request #62 from nobodxbodon/中文补全问题
Browse files Browse the repository at this point in the history
🐛 #61 保留中文触发补全
  • Loading branch information
tuchg committed Aug 5, 2022
2 parents 5cac289 + ec87f95 commit 16aef0d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,17 @@ class ChinesePrefixMatcher(prefixMatcher: PrefixMatcher) : PlainPrefixMatcher(pr

override fun prefixMatches(name: String): Boolean {
// log.info { "${prefix} - ${name} ${myMatcher.matches(name)}" }
return if (Pinyin.hasChinese(name)) {
if (originalMatcher?.prefixMatches(name) == true) {
return true
}
if (Pinyin.hasChinese(name)) {
for (s in toPinyin(name, Pinyin.LOW_CASE)) {
if (countContainsSomeChar(s, prefix) >= prefix.length) {
return true
}
}
return false
} else originalMatcher?.prefixMatches(name) == true
}
return false
}


Expand Down
10 changes: 10 additions & 0 deletions src/test/kotlin/CompletionTests.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,16 @@ class CompletionTests : CompletionAutoPopupTestCase() {
Assert.assertEquals("方法", 补全项.get(1).lookupString)
}

fun `test @Java补全中文命名`() {
myFixture.configureByText("Test.java", "class a { int 吃了; int 信息 = <caret> }")
myFixture.type("吃")
val 补全项 = myFixture.completeBasic()
Assert.assertTrue("补全项不应为空", 补全项.isNotEmpty())
Assert.assertEquals(2, 补全项.size)
Assert.assertEquals("吃了", 补全项.get(0).lookupString)
Assert.assertEquals("吃了", 补全项.get(1).lookupString)
}

fun `test @Java输入错误后无补全`() {
myFixture.configureByText("Test.java", "class a { int 方法() { <caret> } }")
myFixture.type("fo")
Expand Down

0 comments on commit 16aef0d

Please sign in to comment.