diff --git a/tree-view-sample/src/jsonOutline.ts b/tree-view-sample/src/jsonOutline.ts index f33634a2..2aed10f5 100644 --- a/tree-view-sample/src/jsonOutline.ts +++ b/tree-view-sample/src/jsonOutline.ts @@ -3,10 +3,10 @@ import * as json from 'jsonc-parser'; import * as path from 'path'; import { isNumber } from 'util'; -export class JsonOutlineProvider implements vscode.TreeDataProvider { +export class JsonOutlineProvider implements vscode.TreeDataProvider { - private _onDidChangeTreeData: vscode.EventEmitter = new vscode.EventEmitter(); - readonly onDidChangeTreeData: vscode.Event = this._onDidChangeTreeData.event; + private _onDidChangeTreeData: vscode.EventEmitter = new vscode.EventEmitter(); + readonly onDidChangeTreeData: vscode.Event = this._onDidChangeTreeData.event; private tree: json.Node; private text: string; @@ -24,7 +24,7 @@ export class JsonOutlineProvider implements vscode.TreeDataProvider { this.onActiveEditorChanged(); } - refresh(offset?: string): void { + refresh(offset?: number): void { this.parseTree(); if (offset) { this._onDidChangeTreeData.fire(offset); @@ -33,12 +33,12 @@ export class JsonOutlineProvider implements vscode.TreeDataProvider { } } - rename(offset: string): void { + rename(offset: number): void { vscode.window.showInputBox({ placeHolder: 'Enter the new label' }) .then(value => { if (value !== null && value !== undefined) { this.editor.edit(editBuilder => { - const path = json.getLocation(this.text, parseInt(offset)).path + const path = json.getLocation(this.text, offset).path let propertyNode = json.findNodeAtLocation(this.tree, path); if (propertyNode.parent.type !== 'array') { propertyNode = propertyNode.parent.children[0]; @@ -75,7 +75,7 @@ export class JsonOutlineProvider implements vscode.TreeDataProvider { path.pop(); const node = path.length ? json.findNodeAtLocation(this.tree, path) : void 0; this.parseTree(); - this._onDidChangeTreeData.fire(node ? `${node.offset}` : void 0); + this._onDidChangeTreeData.fire(node ? node.offset : void 0); } } } @@ -90,9 +90,9 @@ export class JsonOutlineProvider implements vscode.TreeDataProvider { } } - getChildren(offset?: string): Thenable { + getChildren(offset?: number): Thenable { if (offset) { - const path = json.getLocation(this.text, parseInt(offset)).path + const path = json.getLocation(this.text, offset).path const node = json.findNodeAtLocation(this.tree, path); return Promise.resolve(this.getChildrenOffsets(node)); } else { @@ -100,20 +100,20 @@ export class JsonOutlineProvider implements vscode.TreeDataProvider { } } - private getChildrenOffsets(node: json.Node): string[] { - const offsets = []; + private getChildrenOffsets(node: json.Node): number[] { + const offsets: number[] = []; for (const child of node.children) { const childPath = json.getLocation(this.text, child.offset).path const childNode = json.findNodeAtLocation(this.tree, childPath); if (childNode) { - offsets.push(childNode.offset.toString()); + offsets.push(childNode.offset); } } return offsets; } - getTreeItem(offset: string): vscode.TreeItem { - const path = json.getLocation(this.text, parseInt(offset)).path + getTreeItem(offset: number): vscode.TreeItem { + const path = json.getLocation(this.text, offset).path const valueNode = json.findNodeAtLocation(this.tree, path); if (valueNode) { let hasChildren = valueNode.type === 'object' || valueNode.type === 'array';