【问题标题】:VSCode fold docstrings Python MacOSVSCode 折叠文档字符串 Python MacOS
【发布时间】:2019-11-10 12:58:51
【问题描述】:

我试过使用命令:

>Fold Level 2 导致折叠过多。

还有

>Fold Level 3 不折叠方法的文档字符串。

我的主要目标是折叠文档字符串,仅此而已。

def test(a, b, c):
    """A lot of multiline
    docstrings here
    that dont get folded
    """
    return ...

会变成:

def test(a, b, c):
    return ...

有没有办法做到这一点?

【问题讨论】:

    标签: python macos visual-studio-code


    【解决方案1】:

    暂时没有。如果您希望看到此支持,请投票feature request

    【讨论】:

      【解决方案2】:

      By default VS Code's cold folding is indentation-based, unaware of the programming language used。除了 Brett 的回答之外,还有一个技巧是缩进文档字符串。

      def test(a, b, c):
          """[short summary]
      
              [indented long summary parameters returns etc.]
          ^^^^
          """
      
          return ...
      

      这对于任何专业人士来说显然都是个坏主意,但它确实有效。


      Towards the end of Brett's link 可以找到允许 Python 扩展正确折叠文档字符串的新注释。该评论包含 MacOS 的说明。在我的 Ubuntu 20.04.1 LTS 机器上,我改为执行以下操作:

      1. 运行which code。我收到了/usr/bin/code,但它与/usr/share/code/bin/code 相关联。
      2. 将目录/usr/share/code/resources/app/extensions/python复制到~/.vscode/extensions
      3. 将下面的正则表达式添加到~/.vscode/extensions/python/language-configuration.json
      {
        "folding": {
          "offSide": true,
          "markers": {
            "start": "^\\s*#\\s*region\\b|^\\ *\"{3}(?!.*\"{3}).+",
            "end": "^\\s*#\\s*endregion\\b|^\\ *\"{3}$"
          }
        }
      }
      

      【讨论】:

        猜你喜欢
        • 2020-12-24
        • 2020-05-17
        • 2022-11-22
        • 2015-03-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-07-12
        • 1970-01-01
        相关资源
        最近更新 更多