如何为VsCode扩展编写TreeDataProvider

时间:2017-07-27 07:05:16

标签: javascript visual-studio-code vscode-extensions

参考官方的例子, 我修改了一个提供者,并实现了一个类和所有方法。但它不起作用 请参阅源代码file-structure

class JsonOutlineProvider {

constructor(context) {

    this._onDidChangeTreeData = new vscode.EventEmitter();
    this.onDidChangeTreeData = this._onDidChangeTreeData.event;
    this.editor = null;
    this.tree = null;
    vscode.window.onDidChangeActiveTextEditor(editor => {
        this.parseTree();
        this._onDidChangeTreeData.fire();
    });
    vscode.workspace.onDidChangeTextDocument(e => {
        console.log("text changed !")
    });
    this.parseTree();
}
parseTree() {
    this.tree = null;
    this.editor = vscode.window.activeTextEditor;
    if (this.editor && this.editor.document && this.editor.document.languageId === 'json') {
        this.tree = json.parseTree(this.editor.document.getText());
    }
    console.log("Tree", this.tree);
}

getChildren(node) {
}
getTreeItem(node) {
}

}

module.exports = JsonOutlineProvider;

1 个答案:

答案 0 :(得分:0)

您是否也在package.json中创建了视图?