Add icons to VSCode tree view

Viewed 1148

I am trying to set icons to the tree view but it's not working. Here is my code :

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')
    };
}

Is there anything else I need to configure?

enter image description here

1 Answers

I Had the exact same issue, add another '..' to your path join.

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

This is because all the paths are referenced from the out/ directory so you need to go up 1 more to reach your resources.

Related