Skip to content

Commit 68ac75f

Browse files
committed
Implemented a spell checking intention.
1 parent 5334c46 commit 68ac75f

2 files changed

Lines changed: 68 additions & 1 deletion

File tree

resources/META-INF/plugin.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<id>de.halirutan.mathematica</id>
2424
<name>Mathematica Support</name>
2525
<category>Custom Language</category>
26-
<version>2.1.1</version>
26+
<version>2.2</version>
2727
<idea-version since-build="163"/>
2828
<vendor email="patrick@halirutan.de" url="http://mathematicaplugin.halirutan.de">Patrick Scheibe</vendor>
2929
<depends>com.intellij.modules.lang</depends>
@@ -67,6 +67,7 @@
6767
<i>New features and bug-fixes:</i>
6868
<br/>
6969
<ul>
70+
<li>Spell check for symbols, comments and strings</li>
7071
<li>Code folding based on section comments like (* ::Section:: *)</li>
7172
<li>SurroundWith (Ctrl+Alt+T) will now do something useful when pressed without an active selection</li>
7273
<li>Added Ctrl+Space completion inside comments</li>
@@ -187,6 +188,8 @@
187188
<gotoRelatedProvider
188189
implementation="de.halirutan.mathematica.codeinsight.navigation.MathematicaGotoRelatedProvider"/>
189190

191+
<spellchecker.support language="Mathematica"
192+
implementationClass="de.halirutan.mathematica.codeinsight.spellcheck.MathematicaSpellCheck"/>
190193
<intentionAction>
191194
<className>de.halirutan.mathematica.intentions.localization.MoveVariableToLocalisation</className>
192195
</intentionAction>
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* Copyright (c) 2017 Patrick Scheibe
3+
* Permission is hereby granted, free of charge, to any person obtaining a copy
4+
* of this software and associated documentation files (the "Software"), to deal
5+
* in the Software without restriction, including without limitation the rights
6+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
* copies of the Software, and to permit persons to whom the Software is
8+
* furnished to do so, subject to the following conditions:
9+
*
10+
* The above copyright notice and this permission notice shall be included in
11+
* all copies or substantial portions of the Software.
12+
*
13+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
* THE SOFTWARE.
20+
*/
21+
22+
package de.halirutan.mathematica.codeinsight.spellcheck;
23+
24+
import com.intellij.codeInspection.SuppressionUtil;
25+
import com.intellij.psi.PsiComment;
26+
import com.intellij.psi.PsiElement;
27+
import com.intellij.psi.PsiLanguageInjectionHost;
28+
import com.intellij.psi.PsiWhiteSpace;
29+
import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil;
30+
import com.intellij.spellchecker.tokenizer.PsiIdentifierOwnerTokenizer;
31+
import com.intellij.spellchecker.tokenizer.SpellcheckingStrategy;
32+
import com.intellij.spellchecker.tokenizer.Tokenizer;
33+
import de.halirutan.mathematica.parsing.psi.api.Symbol;
34+
import de.halirutan.mathematica.parsing.psi.api.string.MString;
35+
import org.jetbrains.annotations.NotNull;
36+
37+
/**
38+
* Spell check for Mathematica. This works out of the box since Mathematica uses Camel Case built in functions which
39+
* are separated correctly by the built-in tokenizer for spelling.
40+
*
41+
* @author patrick (08.06.17).
42+
*/
43+
public class MathematicaSpellCheck extends SpellcheckingStrategy {
44+
45+
@NotNull
46+
public Tokenizer getTokenizer(PsiElement element) {
47+
if (element instanceof PsiWhiteSpace) {
48+
return EMPTY_TOKENIZER;
49+
}
50+
if (element instanceof PsiLanguageInjectionHost && InjectedLanguageUtil.hasInjections((PsiLanguageInjectionHost) element)) {
51+
return EMPTY_TOKENIZER;
52+
}
53+
if (element instanceof Symbol) return new PsiIdentifierOwnerTokenizer();
54+
if (element instanceof MString) return TEXT_TOKENIZER;
55+
if (element instanceof PsiComment) {
56+
if (SuppressionUtil.isSuppressionComment(element)) {
57+
return EMPTY_TOKENIZER;
58+
}
59+
return myCommentTokenizer;
60+
}
61+
return EMPTY_TOKENIZER;
62+
}
63+
64+
}

0 commit comments

Comments
 (0)