Custom view decorations in VSCode extension

2020-02-06 10:40发布

问题:

I'm building a VS Code extension and it uses a TreeDataProvider to create a list of items. The list has nested children and I would like to show a count for these in the parent.

I've looked for examples and tried to understand how the git extension does it but no luck. Perhaps someone can provide an example of how to do this.

回答1:

Support for custom decorations in views appears to be a work-in-progress. There has been an API for it in the "proposed state" for a while, see:

  • Make decoration provider API public (#54938)
  • relevant section in vscode.proposed.d.ts

Source Control and Problem decorations already shown in custom views if TreeView.resourceUri is set.

  • Source Control decorations are managed via the Source Control API - each SourceControlResourceState instance can have decorations attached to it. That would be how the Git extension you mentioned does it.
  • Problem decorations are derived from the "problems" (errors, warnings...) associated with a URI. These are also shown in the Problems panel. Problems can be created using the Diagnostics API or with a problem matcher.