Skip to content

Commit

Permalink
Implemented a spell checking intention.
Browse files Browse the repository at this point in the history
  • Loading branch information
halirutan committed Jun 8, 2017
1 parent 5334c46 commit 68ac75f
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 1 deletion.
5 changes: 4 additions & 1 deletion resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<id>de.halirutan.mathematica</id>
<name>Mathematica Support</name>
<category>Custom Language</category>
<version>2.1.1</version>
<version>2.2</version>
<idea-version since-build="163"/>
<vendor email="[email protected]" url="http://mathematicaplugin.halirutan.de">Patrick Scheibe</vendor>
<depends>com.intellij.modules.lang</depends>
Expand Down Expand Up @@ -67,6 +67,7 @@
<i>New features and bug-fixes:</i>
<br/>
<ul>
<li>Spell check for symbols, comments and strings</li>
<li>Code folding based on section comments like (* ::Section:: *)</li>
<li>SurroundWith (Ctrl+Alt+T) will now do something useful when pressed without an active selection</li>
<li>Added Ctrl+Space completion inside comments</li>
Expand Down Expand Up @@ -187,6 +188,8 @@
<gotoRelatedProvider
implementation="de.halirutan.mathematica.codeinsight.navigation.MathematicaGotoRelatedProvider"/>

<spellchecker.support language="Mathematica"
implementationClass="de.halirutan.mathematica.codeinsight.spellcheck.MathematicaSpellCheck"/>
<intentionAction>
<className>de.halirutan.mathematica.intentions.localization.MoveVariableToLocalisation</className>
</intentionAction>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* Copyright (c) 2017 Patrick Scheibe
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

package de.halirutan.mathematica.codeinsight.spellcheck;

import com.intellij.codeInspection.SuppressionUtil;
import com.intellij.psi.PsiComment;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiLanguageInjectionHost;
import com.intellij.psi.PsiWhiteSpace;
import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil;
import com.intellij.spellchecker.tokenizer.PsiIdentifierOwnerTokenizer;
import com.intellij.spellchecker.tokenizer.SpellcheckingStrategy;
import com.intellij.spellchecker.tokenizer.Tokenizer;
import de.halirutan.mathematica.parsing.psi.api.Symbol;
import de.halirutan.mathematica.parsing.psi.api.string.MString;
import org.jetbrains.annotations.NotNull;

/**
* Spell check for Mathematica. This works out of the box since Mathematica uses Camel Case built in functions which
* are separated correctly by the built-in tokenizer for spelling.
*
* @author patrick (08.06.17).
*/
public class MathematicaSpellCheck extends SpellcheckingStrategy {

@NotNull
public Tokenizer getTokenizer(PsiElement element) {
if (element instanceof PsiWhiteSpace) {
return EMPTY_TOKENIZER;
}
if (element instanceof PsiLanguageInjectionHost && InjectedLanguageUtil.hasInjections((PsiLanguageInjectionHost) element)) {
return EMPTY_TOKENIZER;
}
if (element instanceof Symbol) return new PsiIdentifierOwnerTokenizer();
if (element instanceof MString) return TEXT_TOKENIZER;
if (element instanceof PsiComment) {
if (SuppressionUtil.isSuppressionComment(element)) {
return EMPTY_TOKENIZER;
}
return myCommentTokenizer;
}
return EMPTY_TOKENIZER;
}

}

0 comments on commit 68ac75f

Please sign in to comment.