Skip to content

Commit

Permalink
feat: integrate spellchecker (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
tmkx authored Oct 1, 2024
1 parent aa8a99b commit 8c3373a
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 0 deletions.
2 changes: 2 additions & 0 deletions thrift/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ dependencies {
testImplementation("org.junit.jupiter:junit-jupiter")
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
testRuntimeOnly("org.junit.vintage:junit-vintage-engine")
// See: https://plugins.jetbrains.com/docs/intellij/tools-intellij-platform-gradle-plugin-faq.html#missing-opentest4j-dependency-in-test-framework
testImplementation("org.opentest4j:opentest4j:1.3.0")

implementation("org.awaitility:awaitility:4.2.1")

Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}
2 changes: 2 additions & 0 deletions thrift/src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@
<frameworkSupport implementation="com.intellij.plugins.thrift.config.facet.ThriftFacetSupportProvider"/>
<facetType implementation="com.intellij.plugins.thrift.config.facet.ThriftFacetType"/>
<compileServer.plugin classpath="thrift-jps.jar" />

<spellchecker.support language="thrift" implementationClass="com.intellij.plugins.thrift.ThriftSpellcheckingStrategy"/>
</extensions>

<actions>
Expand Down
Original file line number Diff line number Diff line change
@@ -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("inspections/spell", SpellCheckingInspection.class);
}

@Test
public void testUsages1() {
doTest();
}
}
20 changes: 20 additions & 0 deletions thrift/src/test/resources/inspections/spell/usages1.thrift
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
struct <TYPO>Userr</TYPO> {
1: required string <TYPO>nmae</TYPO>
}

enum <TYPO>Mothed</TYPO>
{
GET = 1,
POST = 2,
<TYPO>UNKOW</TYPO> = 3,
}

exception <TYPO>Xceptoin</TYPO> {
1: i32 <TYPO>erroor</TYPO>Code,
2: string message
}

service Typo<TYPO>Srevice</TYPO> // 7
{
string <TYPO>Naem</TYPO>(1: string <TYPO>tyypo</TYPO>), // <TYPO>commemt</TYPO>
}

0 comments on commit 8c3373a

Please sign in to comment.