如何编写 VS Code 扩展来折叠特定区域并呈现折叠区域的内联摘要?

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

在我正在开发的这个项目的源代码中,我们有大量的 JSX 来本地化字符串,所以不要使用例如:

<section>
  lore impsum sit amet
</section>

我们有:

<section>
  <SomeCustomWrapper props="X">
    <AnotherWrapper
      message="lorem impsum sit amet"
      description={{
        text: "description for lore impsum sit amet",
        someMoreProps: "X"
      }}
    />
  </SomeCustomWrapper>
</section>

我想编写一个 VS code 插件来“折叠/展开”那些 SomeCustomWrappers,以便编辑器在折叠时显示这些标签,例如:

<section>
  <string: "lorem impsum sit amet">
</section>

但是我不确定 VS Code API 是否可以实现,如果可以的话,您对如何实现它有任何提示吗?

visual-studio-code vscode-extensions
1个回答
0
投票

要定义折叠范围,请定义并注册

FoldingRangeProvider

至于以编程方式切换提供的折叠区域,我认为您可以使用

editor.fold
命令(另请参阅
FoldingArguments
的定义)和
executeCommand
来完成此操作。

要渲染摘要文本,请使用文本编辑器装饰 API。

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