show encoding problem for the whole file, instead of the empty string in the very beginning, for which quickfixes are hard to invoke

GitOrigin-RevId: 21a06256d25ea4cedac5bc812b41628e9fc2d985
This commit is contained in:
Alexey Kudravtsev
2025-02-14 11:42:03 +00:00
committed by intellij-monorepo-bot
parent 59874aa9d7
commit e3895916cf
5 changed files with 7 additions and 7 deletions
@@ -20,7 +20,6 @@ import com.intellij.codeInspection.ProblemsHolder;
import com.intellij.codeInspection.options.OptDropdown;
import com.intellij.codeInspection.options.OptPane;
import com.intellij.openapi.util.NlsSafe;
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.PsiElementVisitor;
import com.jetbrains.python.PyPsiBundle;
import com.jetbrains.python.PythonFileType;
@@ -59,10 +58,9 @@ public final class PyMandatoryEncodingInspection extends PyInspection {
final String charsetString = PythonFileType.getCharsetFromEncodingDeclaration(node);
if (charsetString == null) {
TextRange tr = new TextRange(0, 0);
ProblemsHolder holder = getHolder();
if (holder != null) {
holder.registerProblem(node, tr, PyPsiBundle.message("INSP.mandatory.encoding.no.encoding.specified.for.file"),
holder.registerProblem(node, PyPsiBundle.message("INSP.mandatory.encoding.no.encoding.specified.for.file"),
new AddEncodingQuickFix(myDefaultEncoding, myEncodingFormatIndex));
}
}
+2 -1
View File
@@ -1 +1,2 @@
<warning descr="No encoding specified for file"><caret></warning>c = "string"
<warning descr="No encoding specified for file">c = "string"
</warning>
@@ -1 +1 @@
<warning descr="No encoding specified for file"><caret></warning>#!/usr/bin/env python
<warning descr="No encoding specified for file">#!/usr/bin/env python</warning>
@@ -1 +1 @@
<warning descr="No encoding specified for file"></warning>from typing import Any
<warning descr="No encoding specified for file">from typing import Any</warning>
@@ -1,4 +1,4 @@
<weak_warning descr="Missing docstring"></weak_warning><warning descr="No encoding specified for file"></warning>def <weak_warning descr="Missing docstring">f</weak_warning>(x):
<weak_warning descr="Missing docstring"></weak_warning><warning descr="No encoding specified for file">def <weak_warning descr="Missing docstring">f</weak_warning>(x):
<warning descr="Non-ASCII character 'М' in the file, but no encoding declared"># type: (b'Моноцикл') -> None</warning>
pass
@@ -6,3 +6,4 @@
def <weak_warning descr="Missing docstring">g</weak_warning>():
# type: <error descr="Unexpected tokens">"foo"</error>
pass
</warning>