From edd80b39538c0714d56c09781b70544f585f21dd Mon Sep 17 00:00:00 2001 From: Tmk Date: Thu, 26 Sep 2024 02:39:35 +0800 Subject: [PATCH] feat: integrate spellchecker --- .../thrift/ThriftSpellcheckingStrategy.java | 18 +++++++++++++++++ thrift/src/main/resources/META-INF/plugin.xml | 2 ++ .../thrift/inspections/SpellcheckingTest.java | 15 ++++++++++++++ .../src/test/resources/spell/usages1.thrift | 20 +++++++++++++++++++ 4 files changed, 55 insertions(+) create mode 100644 thrift/src/main/java/com/intellij/plugins/thrift/ThriftSpellcheckingStrategy.java create mode 100644 thrift/src/test/java/com/intellij/plugins/thrift/inspections/SpellcheckingTest.java create mode 100644 thrift/src/test/resources/spell/usages1.thrift diff --git a/thrift/src/main/java/com/intellij/plugins/thrift/ThriftSpellcheckingStrategy.java b/thrift/src/main/java/com/intellij/plugins/thrift/ThriftSpellcheckingStrategy.java new file mode 100644 index 00000000..84bb1a13 --- /dev/null +++ b/thrift/src/main/java/com/intellij/plugins/thrift/ThriftSpellcheckingStrategy.java @@ -0,0 +1,18 @@ +package com.intellij.plugins.thrift; + +import com.intellij.plugins.thrift.lang.psi.ThriftEnumField; +import com.intellij.psi.PsiElement; +import com.intellij.spellchecker.tokenizer.SpellcheckingStrategy; +import com.intellij.spellchecker.tokenizer.Tokenizer; +import org.jetbrains.annotations.NotNull; + +public final class ThriftSpellcheckingStrategy extends SpellcheckingStrategy { + @Override + public @NotNull Tokenizer getTokenizer(PsiElement element) { + PsiElement parent = element.getParent(); + if (parent instanceof ThriftEnumField && ((ThriftEnumField) parent).getIdentifier() == element) { + return SpellcheckingStrategy.TEXT_TOKENIZER; + } + return super.getTokenizer(element); + } +} diff --git a/thrift/src/main/resources/META-INF/plugin.xml b/thrift/src/main/resources/META-INF/plugin.xml index f3833852..898a5036 100644 --- a/thrift/src/main/resources/META-INF/plugin.xml +++ b/thrift/src/main/resources/META-INF/plugin.xml @@ -83,6 +83,8 @@ + + diff --git a/thrift/src/test/java/com/intellij/plugins/thrift/inspections/SpellcheckingTest.java b/thrift/src/test/java/com/intellij/plugins/thrift/inspections/SpellcheckingTest.java new file mode 100644 index 00000000..dc845954 --- /dev/null +++ b/thrift/src/test/java/com/intellij/plugins/thrift/inspections/SpellcheckingTest.java @@ -0,0 +1,15 @@ +package com.intellij.plugins.thrift.inspections; + +import com.intellij.spellchecker.inspections.SpellCheckingInspection; +import org.junit.jupiter.api.Test; + +public class SpellcheckingTest extends ThriftInspectionTestBase { + public SpellcheckingTest() { + super("spell", SpellCheckingInspection.class); + } + + @Test + public void testUsages1() { + doTest(); + } +} diff --git a/thrift/src/test/resources/spell/usages1.thrift b/thrift/src/test/resources/spell/usages1.thrift new file mode 100644 index 00000000..6ad7b2bf --- /dev/null +++ b/thrift/src/test/resources/spell/usages1.thrift @@ -0,0 +1,20 @@ +struct Userr { + 1: required string nmae +} + +enum Mothed +{ + GET = 1, + POST = 2, + UNKOW = 3, +} + +exception Xceptoin { + 1: i32 erroorCode, + 2: string message +} + +service TypoSrevice // 7 +{ + string Naem(1: string tyypo), // commemt +}