在VSCode树视图中添加图标

3

我正在尝试为树形视图设置图标,但不起作用。这是我的代码:

export class MyClass extends vscode.TreeItem {
    constructor(
    public readonly label: string,
    private version: string,
    public readonly collapsibleState: vscode.TreeItemCollapsibleState,
    public readonly command?: vscode.Command) 
    {
      super(label, collapsibleState);
    }

 get tooltip(): string {
        return `tooltip works`;
    }

  iconPath = {
        light: path.join(__filename, '..', 'resources', 'light', 'dependency.svg'),
        dark: path.join(__filename, '..', 'resources', 'dark', 'dependency.svg')
    };
}

还有什么需要配置的吗?

在此输入图片描述

1个回答

1
我遇到了完全相同的问题,需要在路径连接中再添加一个'..'
iconPath = {
        light: path.join(__filename, '..', '..', 'resources', 'light', 'dependency.svg'),
        dark: path.join(__filename, '..', '..', 'resources', 'dark', 'dependency.svg')
    };

这是因为所有路径都是从out/目录引用的,所以您需要再向上一级才能到达您的资源。

谢谢。它有效了。"所有路径都是从输出目录引用的"完全解释了为什么它之前没有工作。 - undefined

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接