-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented a spell checking intention.
- Loading branch information
Showing
2 changed files
with
68 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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> | ||
|
@@ -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> | ||
|
@@ -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> | ||
|
64 changes: 64 additions & 0 deletions
64
src/de/halirutan/mathematica/codeinsight/spellcheck/MathematicaSpellCheck.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |