From ec87f95a6c0d448e56916ce329852543b2a98726 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=B4=E7=83=9C?= Date: Wed, 27 Jul 2022 10:56:32 -0700 Subject: [PATCH] =?UTF-8?q?:bug:=20#61=20=E4=BF=9D=E7=95=99=E4=B8=AD?= =?UTF-8?q?=E6=96=87=E8=A7=A6=E5=8F=91=E8=A1=A5=E5=85=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../completion/ChinesePrefixMatcher.kt | 9 ++++++--- src/test/kotlin/CompletionTests.kt | 10 ++++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/com/github/tuchg/nonasciicodecompletionhelper/completion/ChinesePrefixMatcher.kt b/src/main/kotlin/com/github/tuchg/nonasciicodecompletionhelper/completion/ChinesePrefixMatcher.kt index 7b46515..1ce2940 100644 --- a/src/main/kotlin/com/github/tuchg/nonasciicodecompletionhelper/completion/ChinesePrefixMatcher.kt +++ b/src/main/kotlin/com/github/tuchg/nonasciicodecompletionhelper/completion/ChinesePrefixMatcher.kt @@ -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 } diff --git a/src/test/kotlin/CompletionTests.kt b/src/test/kotlin/CompletionTests.kt index ef1e809..401fb17 100644 --- a/src/test/kotlin/CompletionTests.kt +++ b/src/test/kotlin/CompletionTests.kt @@ -36,6 +36,16 @@ class CompletionTests : CompletionAutoPopupTestCase() { Assert.assertEquals("方法", 补全项.get(1).lookupString) } + fun `test @Java补全中文命名`() { + myFixture.configureByText("Test.java", "class a { int 吃了; int 信息 = }") + 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 方法() { } }") myFixture.type("fo")