mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-02-04 15:06:56 +07:00
IJPL-155874 make SpellCheckingInspection dumb aware
GitOrigin-RevId: 629e15e2feb514e36a605e5478d8627b2828f502
This commit is contained in:
committed by
intellij-monorepo-bot
parent
14c1fea329
commit
0c64030e25
@@ -1,6 +1,7 @@
|
|||||||
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||||
package com.intellij.grazie
|
package com.intellij.grazie
|
||||||
|
|
||||||
|
import com.intellij.codeInspection.LocalInspectionTool
|
||||||
import com.intellij.grazie.grammar.LanguageToolChecker
|
import com.intellij.grazie.grammar.LanguageToolChecker
|
||||||
import com.intellij.grazie.ide.inspection.grammar.GrazieInspection
|
import com.intellij.grazie.ide.inspection.grammar.GrazieInspection
|
||||||
import com.intellij.grazie.jlanguage.Lang
|
import com.intellij.grazie.jlanguage.Lang
|
||||||
@@ -22,7 +23,7 @@ import kotlinx.coroutines.runBlocking
|
|||||||
|
|
||||||
abstract class GrazieTestBase : BasePlatformTestCase() {
|
abstract class GrazieTestBase : BasePlatformTestCase() {
|
||||||
companion object {
|
companion object {
|
||||||
val inspectionTools by lazy { arrayOf(GrazieInspection(), SpellCheckingInspection()) }
|
val inspectionTools: Array<out LocalInspectionTool> by lazy { arrayOf(GrazieInspection(), SpellCheckingInspection()) }
|
||||||
val enabledLanguages = setOf(Lang.AMERICAN_ENGLISH, Lang.GERMANY_GERMAN, Lang.RUSSIAN, Lang.ITALIAN)
|
val enabledLanguages = setOf(Lang.AMERICAN_ENGLISH, Lang.GERMANY_GERMAN, Lang.RUSSIAN, Lang.ITALIAN)
|
||||||
val enabledRules = setOf("LanguageTool.EN.COMMA_WHICH", "LanguageTool.EN.UPPERCASE_SENTENCE_START")
|
val enabledRules = setOf("LanguageTool.EN.COMMA_WHICH", "LanguageTool.EN.UPPERCASE_SENTENCE_START")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,7 +24,7 @@
|
|||||||
<localInspection shortName="SpellCheckingInspection" bundle="messages.SpellCheckerBundle"
|
<localInspection shortName="SpellCheckingInspection" bundle="messages.SpellCheckerBundle"
|
||||||
key="spellchecking.inspection.name" groupKey="proofread" enabledByDefault="true" level="TYPO"
|
key="spellchecking.inspection.name" groupKey="proofread" enabledByDefault="true" level="TYPO"
|
||||||
language=""
|
language=""
|
||||||
implementationClass="com.intellij.spellchecker.inspections.SpellCheckingInspection"/>
|
implementationClass="com.intellij.spellchecker.inspections.SpellCheckingInspection" dumbAware="true"/>
|
||||||
|
|
||||||
<nameSuggestionProvider id="DictionarySuggestionProvider" implementation="com.intellij.spellchecker.quickfixes.DictionarySuggestionProvider" order="first"/>
|
<nameSuggestionProvider id="DictionarySuggestionProvider" implementation="com.intellij.spellchecker.quickfixes.DictionarySuggestionProvider" order="first"/>
|
||||||
<severitiesProvider implementation="com.intellij.spellchecker.SpellCheckerSeveritiesProvider"/>
|
<severitiesProvider implementation="com.intellij.spellchecker.SpellCheckerSeveritiesProvider"/>
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ import com.intellij.lang.LanguageNamesValidation;
|
|||||||
import com.intellij.lang.injection.InjectedLanguageManager;
|
import com.intellij.lang.injection.InjectedLanguageManager;
|
||||||
import com.intellij.lang.refactoring.NamesValidator;
|
import com.intellij.lang.refactoring.NamesValidator;
|
||||||
import com.intellij.openapi.progress.ProgressManager;
|
import com.intellij.openapi.progress.ProgressManager;
|
||||||
|
import com.intellij.openapi.project.DumbAware;
|
||||||
|
import com.intellij.openapi.project.DumbService;
|
||||||
import com.intellij.openapi.util.TextRange;
|
import com.intellij.openapi.util.TextRange;
|
||||||
import com.intellij.openapi.util.registry.Registry;
|
import com.intellij.openapi.util.registry.Registry;
|
||||||
import com.intellij.psi.PsiElement;
|
import com.intellij.psi.PsiElement;
|
||||||
@@ -29,7 +31,7 @@ import java.util.Set;
|
|||||||
import static com.intellij.codeInspection.options.OptPane.checkbox;
|
import static com.intellij.codeInspection.options.OptPane.checkbox;
|
||||||
import static com.intellij.codeInspection.options.OptPane.pane;
|
import static com.intellij.codeInspection.options.OptPane.pane;
|
||||||
|
|
||||||
public final class SpellCheckingInspection extends LocalInspectionTool {
|
public final class SpellCheckingInspection extends LocalInspectionTool implements DumbAware {
|
||||||
public static final String SPELL_CHECKING_INSPECTION_TOOL_NAME = "SpellCheckingInspection";
|
public static final String SPELL_CHECKING_INSPECTION_TOOL_NAME = "SpellCheckingInspection";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -45,8 +47,9 @@ public final class SpellCheckingInspection extends LocalInspectionTool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static SpellcheckingStrategy getSpellcheckingStrategy(@NotNull PsiElement element, @NotNull Language language) {
|
private static SpellcheckingStrategy getSpellcheckingStrategy(@NotNull PsiElement element, @NotNull Language language) {
|
||||||
|
DumbService dumbService = DumbService.getInstance(element.getProject());
|
||||||
for (SpellcheckingStrategy strategy : LanguageSpellchecking.INSTANCE.allForLanguage(language)) {
|
for (SpellcheckingStrategy strategy : LanguageSpellchecking.INSTANCE.allForLanguage(language)) {
|
||||||
if (strategy.isMyContext(element)) {
|
if (dumbService.isUsableInCurrentContext(strategy) && strategy.isMyContext(element)) {
|
||||||
return strategy;
|
return strategy;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import com.intellij.lang.ParserDefinition;
|
|||||||
import com.intellij.openapi.extensions.ExtensionPointName;
|
import com.intellij.openapi.extensions.ExtensionPointName;
|
||||||
import com.intellij.openapi.fileTypes.FileType;
|
import com.intellij.openapi.fileTypes.FileType;
|
||||||
import com.intellij.openapi.fileTypes.impl.CustomSyntaxTableFileType;
|
import com.intellij.openapi.fileTypes.impl.CustomSyntaxTableFileType;
|
||||||
|
import com.intellij.openapi.project.PossiblyDumbAware;
|
||||||
import com.intellij.openapi.util.TextRange;
|
import com.intellij.openapi.util.TextRange;
|
||||||
import com.intellij.psi.*;
|
import com.intellij.psi.*;
|
||||||
import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil;
|
import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil;
|
||||||
@@ -18,7 +19,7 @@ import com.intellij.spellchecker.DictionaryLayer;
|
|||||||
import com.intellij.spellchecker.DictionaryLayersProvider;
|
import com.intellij.spellchecker.DictionaryLayersProvider;
|
||||||
import com.intellij.spellchecker.inspections.PlainTextSplitter;
|
import com.intellij.spellchecker.inspections.PlainTextSplitter;
|
||||||
import com.intellij.spellchecker.inspections.SpellCheckingInspection;
|
import com.intellij.spellchecker.inspections.SpellCheckingInspection;
|
||||||
import com.intellij.spellchecker.quickfixes.*;
|
import com.intellij.spellchecker.quickfixes.SpellCheckerQuickFixFactory;
|
||||||
import com.intellij.spellchecker.settings.SpellCheckerSettings;
|
import com.intellij.spellchecker.settings.SpellCheckerSettings;
|
||||||
import com.intellij.util.KeyedLazyInstance;
|
import com.intellij.util.KeyedLazyInstance;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
@@ -32,8 +33,10 @@ import java.util.Set;
|
|||||||
* <p>
|
* <p>
|
||||||
* Register via extension point {@code com.intellij.spellchecker.support}
|
* Register via extension point {@code com.intellij.spellchecker.support}
|
||||||
* and override {@link #getTokenizer(PsiElement)} to skip/handle specific elements.
|
* and override {@link #getTokenizer(PsiElement)} to skip/handle specific elements.
|
||||||
|
* <p>
|
||||||
|
* Mark your strategy as {@link com.intellij.openapi.project.DumbAware} if it does not need indexes to perform
|
||||||
*/
|
*/
|
||||||
public class SpellcheckingStrategy {
|
public class SpellcheckingStrategy implements PossiblyDumbAware {
|
||||||
protected final Tokenizer<PsiComment> myCommentTokenizer = new CommentTokenizer();
|
protected final Tokenizer<PsiComment> myCommentTokenizer = new CommentTokenizer();
|
||||||
|
|
||||||
public static final ExtensionPointName<KeyedLazyInstance<SpellcheckingStrategy>> EP_NAME =
|
public static final ExtensionPointName<KeyedLazyInstance<SpellcheckingStrategy>> EP_NAME =
|
||||||
|
|||||||
Reference in New Issue
Block a user