IJPL-155874 Make most of the spellchecking strategies dumb aware

If you see any problems with your spellchecking strategy, please feel free to remove DumbAware from it. Or, you can make it dumb-aware by avoiding using indexes in dumb mode

The only strategies that are not DumbAware at the moment are:
- JavaSpellcheckingStrategy
- JSSpellCheckingStrategy

GitOrigin-RevId: 74781cf1ebd9b58669396bf7b1c03a839019f12b
This commit is contained in:
Max Medvedev
2024-08-02 22:48:21 +02:00
committed by intellij-monorepo-bot
parent 0c64030e25
commit c795cec244
15 changed files with 39 additions and 52 deletions

View File

@@ -1,7 +1,8 @@
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.json;
import com.intellij.json.psi.JsonStringLiteral;
import com.intellij.openapi.project.DumbAware;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.PsiElement;
@@ -16,7 +17,7 @@ import java.util.List;
/**
* @author Mikhail Golubev
*/
public class JsonSpellcheckerStrategy extends SpellcheckingStrategy {
public class JsonSpellcheckerStrategy extends SpellcheckingStrategy implements DumbAware {
private final Tokenizer<JsonStringLiteral> ourStringLiteralTokenizer = new Tokenizer<>() {
@Override
public void tokenize(@NotNull JsonStringLiteral element, @NotNull TokenConsumer consumer) {

View File

@@ -1,12 +1,13 @@
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package org.jetbrains.idea.devkit.themes;
import com.intellij.openapi.project.DumbAware;
import com.intellij.psi.PsiElement;
import com.intellij.spellchecker.tokenizer.SpellcheckingStrategy;
import com.intellij.spellchecker.tokenizer.Tokenizer;
import org.jetbrains.annotations.NotNull;
final class ThemeSpellcheckingStrategy extends SpellcheckingStrategy {
final class ThemeSpellcheckingStrategy extends SpellcheckingStrategy implements DumbAware {
@NotNull
@Override

View File

@@ -1,6 +1,7 @@
// Copyright 2000-2018 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-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package org.editorconfig.language.spellchecker
import com.intellij.openapi.project.DumbAware
import com.intellij.psi.PsiComment
import com.intellij.psi.PsiElement
import com.intellij.spellchecker.tokenizer.SpellcheckingStrategy
@@ -10,7 +11,7 @@ import org.editorconfig.language.psi.interfaces.EditorConfigDescribableElement
import org.editorconfig.language.psi.interfaces.EditorConfigHeaderElement
import org.editorconfig.language.schema.descriptors.impl.EditorConfigDeclarationDescriptor
class EditorConfigSpellcheckerStrategy : SpellcheckingStrategy() {
class EditorConfigSpellcheckerStrategy : SpellcheckingStrategy(), DumbAware {
override fun getTokenizer(element: PsiElement): Tokenizer<*> {
if (element is PsiComment) return super.getTokenizer(element)
if (element is EditorConfigCharClassPattern) return EMPTY_TOKENIZER

View File

@@ -1,20 +1,7 @@
/*
* Copyright 2000-2011 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package org.jetbrains.plugins.groovy.codeInspection.spellchecker;
import com.intellij.openapi.project.DumbAware;
import com.intellij.psi.PsiElement;
import com.intellij.psi.javadoc.PsiDocComment;
import com.intellij.spellchecker.inspections.PlainTextSplitter;
@@ -27,7 +14,7 @@ import org.jetbrains.plugins.groovy.lang.lexer.TokenSets;
import org.jetbrains.plugins.groovy.lang.psi.GrNamedElement;
import org.jetbrains.plugins.groovy.lang.psi.util.GrStringUtil;
public class GroovySpellcheckingStrategy extends SpellcheckingStrategy {
public class GroovySpellcheckingStrategy extends SpellcheckingStrategy implements DumbAware {
private final GrDocCommentTokenizer myDocCommentTokenizer = new GrDocCommentTokenizer();
private final Tokenizer<PsiElement> myStringTokenizer = new EscapeSequenceTokenizer<>() {
@Override

View File

@@ -1,9 +1,10 @@
// Copyright 2000-2021 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-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.jsonpath;
import com.intellij.jsonpath.psi.JsonPathId;
import com.intellij.jsonpath.psi.JsonPathIdSegment;
import com.intellij.jsonpath.psi.JsonPathStringLiteral;
import com.intellij.openapi.project.DumbAware;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.PsiElement;
@@ -15,7 +16,7 @@ import org.jetbrains.annotations.NotNull;
import java.util.List;
public final class JsonPathSpellcheckerStrategy extends SpellcheckingStrategy {
public final class JsonPathSpellcheckerStrategy extends SpellcheckingStrategy implements DumbAware {
private final Tokenizer<JsonPathStringLiteral> ourStringLiteralTokenizer = new Tokenizer<>() {
@Override

View File

@@ -1,7 +1,8 @@
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package org.jetbrains.kotlin.idea.spellchecker
import com.intellij.openapi.project.DumbAware
import com.intellij.psi.PsiComment
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiNameIdentifierOwner
@@ -12,7 +13,7 @@ import com.intellij.spellchecker.tokenizer.TokenizerBase
import org.jetbrains.kotlin.lexer.KtTokens
import org.jetbrains.kotlin.psi.*
internal class KotlinSpellcheckingStrategy : SpellcheckingStrategy() {
internal class KotlinSpellcheckingStrategy : SpellcheckingStrategy(), DumbAware {
private val plainTextTokenizer: Tokenizer<PsiElement> = TokenizerBase(PlainTextSplitter.getInstance())
private val emptyTokenizer: Tokenizer<PsiElement> = EMPTY_TOKENIZER

View File

@@ -1,6 +1,7 @@
package org.intellij.plugins.markdown.spellchecker;
import com.intellij.lang.ASTNode;
import com.intellij.openapi.project.DumbAware;
import com.intellij.psi.PsiElement;
import com.intellij.psi.impl.source.tree.TreeUtil;
import com.intellij.psi.tree.TokenSet;
@@ -10,7 +11,7 @@ import org.intellij.plugins.markdown.lang.MarkdownElementTypes;
import org.intellij.plugins.markdown.lang.MarkdownTokenTypes;
import org.jetbrains.annotations.NotNull;
public class MarkdownSpellcheckingStrategy extends SpellcheckingStrategy {
public class MarkdownSpellcheckingStrategy extends SpellcheckingStrategy implements DumbAware {
public static final TokenSet NO_SPELLCHECKING_TYPES = TokenSet.create(MarkdownElementTypes.CODE_BLOCK,
MarkdownElementTypes.CODE_FENCE,

View File

@@ -1,23 +1,10 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.lang.properties.spellchecker;
import com.intellij.lang.properties.psi.Property;
import com.intellij.lang.properties.psi.impl.PropertyKeyImpl;
import com.intellij.lang.properties.psi.impl.PropertyValueImpl;
import com.intellij.openapi.project.DumbAware;
import com.intellij.psi.PsiElement;
import com.intellij.spellchecker.inspections.PlainTextSplitter;
import com.intellij.spellchecker.inspections.PropertiesSplitter;
@@ -27,7 +14,7 @@ import com.intellij.spellchecker.tokenizer.TokenizerBase;
import org.jetbrains.annotations.NotNull;
public class PropertiesSpellcheckingStrategy extends SpellcheckingStrategy {
public class PropertiesSpellcheckingStrategy extends SpellcheckingStrategy implements DumbAware {
private final Tokenizer<PropertyValueImpl> myPropertyValueTokenizer = TokenizerBase.create(PlainTextSplitter.getInstance());
private final Tokenizer<PropertyKeyImpl> myPropertyTokenizer = TokenizerBase.create(PropertiesSplitter.getInstance());

View File

@@ -1,6 +1,7 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.restructuredtext.spellchecker;
import com.intellij.openapi.project.DumbAware;
import com.intellij.psi.PsiElement;
import com.intellij.psi.impl.source.tree.LeafPsiElement;
import com.intellij.psi.tree.IElementType;
@@ -13,7 +14,7 @@ import com.intellij.spellchecker.tokenizer.Tokenizer;
import org.jetbrains.annotations.NotNull;
public class RestSpellcheckerStrategy extends SpellcheckingStrategy {
public class RestSpellcheckerStrategy extends SpellcheckingStrategy implements DumbAware {
private static final Tokenizer<PsiElement> REST_ELEMENT_TOKENIZER = new Tokenizer<>() {
@Override
public void tokenize(@NotNull PsiElement element, @NotNull TokenConsumer consumer) {

View File

@@ -2,6 +2,7 @@
package com.intellij.sh.spellchecker;
import com.intellij.lang.ASTNode;
import com.intellij.openapi.project.DumbAware;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiNameIdentifierOwner;
import com.intellij.psi.tree.TokenSet;
@@ -12,7 +13,7 @@ import org.jetbrains.annotations.NotNull;
import static com.intellij.sh.ShTypes.*;
import static com.intellij.sh.lexer.ShTokenTypes.COMMENT;
public class ShSpellcheckingStrategy extends SpellcheckingStrategy {
public class ShSpellcheckingStrategy extends SpellcheckingStrategy implements DumbAware {
private static final TokenSet TOKENS_WITH_TEXT = TokenSet.create(STRING_CONTENT, RAW_STRING, HEREDOC_CONTENT, COMMENT);
@NotNull

View File

@@ -1,11 +1,12 @@
package org.jetbrains.plugins.textmate.spellchecker;
import com.intellij.openapi.project.DumbAware;
import com.intellij.psi.PsiElement;
import com.intellij.spellchecker.tokenizer.SpellcheckingStrategy;
import com.intellij.spellchecker.tokenizer.Tokenizer;
import org.jetbrains.annotations.NotNull;
public class TextMateSpellingStrategy extends SpellcheckingStrategy {
public class TextMateSpellingStrategy extends SpellcheckingStrategy implements DumbAware {
@NotNull
@Override
public Tokenizer getTokenizer(PsiElement element) {

View File

@@ -3,6 +3,7 @@ package org.jetbrains.yaml;
import com.intellij.json.JsonSchemaSpellcheckerClient;
import com.intellij.lang.ASTNode;
import com.intellij.openapi.project.DumbAware;
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.ElementManipulators;
import com.intellij.psi.PsiElement;
@@ -19,7 +20,7 @@ import org.jetbrains.yaml.psi.YAMLKeyValue;
import org.jetbrains.yaml.psi.YAMLQuotedText;
import org.jetbrains.yaml.psi.YAMLScalar;
final class YAMLSpellcheckerStrategy extends SpellcheckingStrategy {
final class YAMLSpellcheckerStrategy extends SpellcheckingStrategy implements DumbAware {
private final Tokenizer<YAMLQuotedText> myQuotedTextTokenizer = new Tokenizer<>() {
@Override

View File

@@ -2,6 +2,7 @@
package com.jetbrains.python.spellchecker;
import com.intellij.lang.injection.InjectedLanguageManager;
import com.intellij.openapi.project.DumbAware;
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.PsiElement;
import com.intellij.spellchecker.inspections.PlainTextSplitter;
@@ -23,7 +24,7 @@ import java.util.Collections;
import java.util.List;
public final class PythonSpellcheckerStrategy extends SpellcheckingStrategy {
public final class PythonSpellcheckerStrategy extends SpellcheckingStrategy implements DumbAware {
private static class StringLiteralTokenizer extends Tokenizer<PyStringLiteralExpression> {
@Override
public void tokenize(@NotNull PyStringLiteralExpression element, @NotNull TokenConsumer consumer) {

View File

@@ -1,7 +1,8 @@
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.spellchecker.xml;
import com.intellij.codeInsight.completion.HtmlCompletionContributor;
import com.intellij.openapi.project.DumbAware;
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.ElementManipulators;
import com.intellij.psi.PsiElement;
@@ -18,7 +19,7 @@ import org.jetbrains.annotations.NotNull;
import java.util.List;
public class HtmlSpellcheckingStrategy extends XmlSpellcheckingStrategy {
public class HtmlSpellcheckingStrategy extends XmlSpellcheckingStrategy implements DumbAware {
private final Tokenizer<? extends PsiElement> myDocumentTextTokenizer = createDocumentTextTokenizer();
@Override

View File

@@ -1,7 +1,8 @@
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.spellchecker.xml;
import com.intellij.codeInspection.SuppressQuickFix;
import com.intellij.openapi.project.DumbAware;
import com.intellij.openapi.util.TextRange;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.*;
@@ -28,7 +29,7 @@ import java.util.List;
import static java.util.Collections.emptyList;
import static java.util.Collections.singletonList;
public class XmlSpellcheckingStrategy extends SuppressibleSpellcheckingStrategy {
public class XmlSpellcheckingStrategy extends SuppressibleSpellcheckingStrategy implements DumbAware {
private final Tokenizer<? extends PsiElement> myXmlTextTokenizer = createTextTokenizer();