“折叠所有块注释”命令不适用于具有特定导入安排的文件中的 Python 文档字符串

问题描述 投票:0回答:1

VS Code 的

Fold All Block Comments
命令似乎随机决定是否对我正在编辑的任何给定 python 文件起作用,直到我能够弄清楚文件顶部的 import 语句的数量正在影响命令的行为.

该命令在没有导入的文件上运行良好:

""" This is a docstring that should fold
when VS Code's Fold All Block Comments command
is executed on this file. Lorem ipsum dolor sit amet, consectetur
adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna"""

# This folds

也适用于一次导入的文件:

import math

""" This is a docstring that should fold
when VS Code's Fold All Block Comments command
is executed on this file. Lorem ipsum dolor sit amet, consectetur
adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna"""

# Also folds

但是第二次输入后,它不再随命令折叠...

import math
import tkinter

""" This is a docstring that should fold
when VS Code's Fold All Block Comments command
is executed on this file. Lorem ipsum dolor sit amet, consectetur
adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna"""

# Does not fold with Fold All Block Comments command.

只是为了好玩,如果导入由文档字符串分隔,折叠功能就会返回:

import math

""" This is a docstring that should fold
when VS Code's Fold All Block Comments command
is executed on this file. Lorem ipsum dolor sit amet, consectetur
adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna"""
# I fold!

import tkinter

""" This is a docstring that should fold
when VS Code's Fold All Block Comments command
is executed on this file. Lorem ipsum dolor sit amet, consectetur
adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna"""
# I fold too!

在所有示例中,文档字符串仍被识别为折叠区域,但不会使用命令自动折叠。该怎么办?

python visual-studio-code docstring
1个回答
0
投票

我可以在带有 Python 扩展 v2023.14.0 的 VS Code 1.81.0 上重现此内容。根据 Fold all block comments not work for Python docstrings #20330,这是设计使然,因为文档字符串不是块注释,所以有趣的是

Fold All Block Comments
完全影响文档字符串。

另请参阅此功能请求:添加“折叠所有文档字符串”命令#4677。点赞以表示支持,并订阅以获取讨论和进展通知。请避免发表诸如“+1”/“撞”之类的吵闹评论。

为了供您参考/学习,我通过谷歌搜索“

github vscode python issues "fold all block comments"
”找到了上述问题票。

© www.soinside.com 2019 - 2024. All rights reserved.