[grazie] IJPL-211382 GrazieSpellCheckingInspection throws INRE in dumb mode

Merge-request: IJ-MR-177658
Merged-by: Ilia Permiashkin <ilia.permiashkin@jetbrains.com>

GitOrigin-RevId: 487a202322628724de8f61ee186e490c5f80333c
This commit is contained in:
Ilia Permiashkin
2025-10-06 17:44:09 +00:00
committed by intellij-monorepo-bot
parent 2df4ef188f
commit 442f8b7ad1
6 changed files with 32 additions and 2 deletions
@@ -37,6 +37,8 @@ import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import com.intellij.openapi.project.DumbService;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.regex.Pattern;
@@ -325,6 +327,19 @@ public final class GrazieSpellCheckingInspection extends SpellCheckingInspection
return false;
}
if (DumbService.isDumb(file.getProject())) {
for (int occurrence : occurrences) {
PsiElement element = file.findElementAt(occurrence);
if (element != null) {
SpellcheckingStrategy strategy = getSpellcheckingStrategy(element);
if (strategy != null && !strategy.elementFitsScope(element, Set.of(SpellCheckingScope.Comments))) {
return true;
}
}
}
return false;
}
for (int occurrence : occurrences) {
PsiReference reference = file.findReferenceAt(occurrence);
PsiElement resolvedReference = reference != null ? reference.resolve() : null;
+1
View File
@@ -25,6 +25,7 @@ jvm_library(
"//platform/core-ui",
"//platform/editor-ui-api:editor-ui",
"//platform/projectModel-api:projectModel",
"//platform/util/jdom",
"//spellchecker",
"//spellchecker:spellchecker_test_lib",
"//plugins/grazie",
@@ -13,6 +13,7 @@
<orderEntry type="module" module-name="intellij.platform.core.ui" scope="TEST" />
<orderEntry type="module" module-name="intellij.platform.editor.ui" scope="TEST" />
<orderEntry type="module" module-name="intellij.platform.projectModel" scope="TEST" />
<orderEntry type="module" module-name="intellij.platform.util.jdom" scope="TEST" />
<orderEntry type="module" module-name="intellij.spellchecker" />
<orderEntry type="module" module-name="intellij.grazie" exported="" />
<orderEntry type="module" module-name="intellij.grazie.core" scope="TEST" />
@@ -1,15 +1,17 @@
// 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.ide.language
import com.intellij.codeInsight.daemon.DaemonCodeAnalyzer
import com.intellij.codeInsight.daemon.impl.DaemonCodeAnalyzerImpl
import com.intellij.grazie.GrazieTestBase
import com.intellij.grazie.jlanguage.Lang
import com.intellij.grazie.spellcheck.engine.GrazieSpellCheckerEngine
import com.intellij.openapi.components.service
import com.intellij.openapi.util.Disposer
import com.intellij.spellchecker.ProjectDictionaryLayer
import com.intellij.spellchecker.SpellCheckerManager
import com.intellij.spellchecker.dictionary.Loader
import com.intellij.spellchecker.settings.SpellCheckerSettings
import com.intellij.testFramework.DumbModeTestUtils.runInDumbModeSynchronously
import com.intellij.testFramework.LightProjectDescriptor
import com.intellij.testFramework.fixtures.LightJavaCodeInsightFixtureTestCase
import com.intellij.tools.ide.metrics.benchmark.Benchmark
@@ -69,6 +71,9 @@ class JavaSupportTest : GrazieTestBase() {
fun testCommentIsNotHighlightedIfThereIsReference() {
runHighlightTestForFile("ide/language/java/VectorablexxClass.java")
(DaemonCodeAnalyzer.getInstance(project) as DaemonCodeAnalyzerImpl).mustWaitForSmartMode(false, testRootDisposable)
runInDumbModeSynchronously(project) { runHighlightTestForFile("ide/language/java/VectorablexxClass.java") }
}
fun `test spellchecking normalization`() {
@@ -0,0 +1,7 @@
import org.jetbrains.annotations.NonNls;
class Test {
void m() {
@NonNls String s = "CONASTANT"; // CONASTANT comment
}
}
@@ -49,7 +49,8 @@ public class JavaSpellcheckerInspectionTest extends LightJavaCodeInsightFixtureT
public void testNonNlsField() { doTestInAllModes(); }
public void testNonNlsField2() { doTestInAllModes(); }
public void testNonNlsLocalVariable() { doTestInAllModes(); }
public void testNonNlsLocalVariableAndComment() { doTestInAllModes(); }
public void testNonNlsLocalVariableAndComment() { doTest(false); }
public void testNonNlsLocalVariableAndCommentDumb() { doTest(true); }
public void testFieldComment() { doTestInAllModes(); }
public void testDoNotCheckDerivedNames() { doTestInAllModes(); }
public void testSkipDateTime() { doTestInAllModes(); }