mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[python] PY-79930 don't fold __future__ imports
Merge-request: IJ-MR-171486 Merged-by: Morgan Bartholomew <morgan.bartholomew@jetbrains.com> GitOrigin-RevId: 968e8d7c03dd7e46ff55316cffd07e7e2a9c7b54
This commit is contained in:
committed by
intellij-monorepo-bot
parent
787d1f6d6c
commit
5b3cb745e0
@@ -110,9 +110,10 @@ open class PythonFoldingBuilder : CustomFoldingBuilder(), DumbAware {
|
||||
val elementType = node.elementType
|
||||
if (node.psi is PyAstFile) {
|
||||
val imports = (node.psi as PyAstFile).importBlock
|
||||
if (imports.size > 1) {
|
||||
val firstImport: PyAstImportStatementBase = imports[0]
|
||||
val lastImport: PyAstImportStatementBase = imports[imports.size - 1]
|
||||
val firstIndex = imports.takeWhile { (it as? PyAstFromImportStatement)?.isFromFuture == true }.size
|
||||
if (imports.size - firstIndex > 1) {
|
||||
val firstImport: PyAstImportStatementBase = imports[firstIndex]
|
||||
val lastImport: PyAstImportStatementBase = imports.last()
|
||||
descriptors.add(FoldingDescriptor(firstImport, TextRange(firstImport.textRange.startOffset,
|
||||
lastImport.textRange.endOffset)))
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
"""This is a module-level docstring."""
|
||||
|
||||
from __future__ import annotations
|
||||
from __future__ import another_one
|
||||
|
||||
<fold text='import ...'>import os
|
||||
import sys</fold>
|
||||
|
||||
print(os, sys)
|
||||
@@ -0,0 +1,7 @@
|
||||
"""This is a module-level docstring."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
|
||||
print(os.path)
|
||||
@@ -245,4 +245,14 @@ public class PyFoldingTest extends PyTestCase {
|
||||
public void testMatchFolding() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
// PY-79930
|
||||
public void testFutureImport() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
// PY-79930
|
||||
public void testFutureImportWithOneImport() {
|
||||
doTest();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user