diff --git a/python/src/com/jetbrains/python/spellchecker/PythonSpellcheckerStrategy.java b/python/src/com/jetbrains/python/spellchecker/PythonSpellcheckerStrategy.java index e335bf20af0c..8162a81df75c 100644 --- a/python/src/com/jetbrains/python/spellchecker/PythonSpellcheckerStrategy.java +++ b/python/src/com/jetbrains/python/spellchecker/PythonSpellcheckerStrategy.java @@ -15,6 +15,7 @@ */ package com.jetbrains.python.spellchecker; +import com.intellij.lang.injection.InjectedLanguageManager; import com.intellij.openapi.util.TextRange; import com.intellij.psi.PsiElement; import com.intellij.spellchecker.inspections.PlainTextSplitter; @@ -94,6 +95,10 @@ public class PythonSpellcheckerStrategy extends SpellcheckingStrategy { @Override public Tokenizer getTokenizer(PsiElement element) { if (element instanceof PyStringLiteralExpression) { + final InjectedLanguageManager injectionManager = InjectedLanguageManager.getInstance(element.getProject()); + if (element.getTextLength() >= 2 && injectionManager.getInjectedPsiFiles(element) != null) { + return EMPTY_TOKENIZER; + } PsiElement parent = element.getParent(); if (parent instanceof PyBinaryExpression) { PyBinaryExpression binaryExpression = (PyBinaryExpression)parent; diff --git a/python/testData/inspections/spelling/typosInDoctestsReportedOnce.py b/python/testData/inspections/spelling/typosInDoctestsReportedOnce.py new file mode 100644 index 000000000000..9041a40a92df --- /dev/null +++ b/python/testData/inspections/spelling/typosInDoctestsReportedOnce.py @@ -0,0 +1,3 @@ +""" +>>> 'There are also always two inspection messags.' +""" \ No newline at end of file diff --git a/python/testData/inspections/spelling/typosInInjectedPythonStringsReportedOnce.py b/python/testData/inspections/spelling/typosInInjectedPythonStringsReportedOnce.py new file mode 100644 index 000000000000..99e9e217d6d9 --- /dev/null +++ b/python/testData/inspections/spelling/typosInInjectedPythonStringsReportedOnce.py @@ -0,0 +1,2 @@ +# language=Python +s = '"mstyped"' \ No newline at end of file diff --git a/python/testData/inspections/spelling/typosInRegexIgnored.py b/python/testData/inspections/spelling/typosInRegexIgnored.py new file mode 100644 index 000000000000..0053805b4686 --- /dev/null +++ b/python/testData/inspections/spelling/typosInRegexIgnored.py @@ -0,0 +1,2 @@ +import re +re_sth = re.compile(r'(\w+)\stells\syou') diff --git a/python/testSrc/com/jetbrains/python/PySpellCheckerTest.java b/python/testSrc/com/jetbrains/python/PySpellCheckerTest.java index 356aec5e156f..3f2a3927d7c3 100644 --- a/python/testSrc/com/jetbrains/python/PySpellCheckerTest.java +++ b/python/testSrc/com/jetbrains/python/PySpellCheckerTest.java @@ -66,6 +66,20 @@ public class PySpellCheckerTest extends PyTestCase { doTest(); } + public void testTyposInInjectedPythonStringsReportedOnce() { + doTest(); + } + + // PY-36912 + public void testTyposInDoctestsReportedOnce() { + doTest(); + } + + // PY-7711 + public void testTyposInRegexIgnored() { + doTest(); + } + private void doTest() { myFixture.enableInspections(SpellCheckingInspection.class); myFixture.configureByFile("inspections/spelling/" + getTestName(true) + ".py");