Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Really convert IDs to numbers to use with Map. Re-fetch items that have been marked as changed. #3376

Merged
merged 2 commits into from Dec 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
47 changes: 33 additions & 14 deletions java/java.lsp.server/vscode/src/explorer.ts
Expand Up @@ -92,6 +92,7 @@ class VisualizerProvider extends vscode.Disposable implements CustomizableTreeDa
private root: Visualizer;
private treeData : Map<number, Visualizer> = new Map();
private decorators : TreeItemDecorator<Visualizer>[] = [];
private pendingRefresh : Set<number> = new Set();

constructor(
private client: LanguageClient,
Expand Down Expand Up @@ -139,6 +140,7 @@ class VisualizerProvider extends vscode.Disposable implements CustomizableTreeDa
if (this.root.data.id == params.nodeId || !params.nodeId) {
this._onDidChangeTreeData.fire();
} else {
this.pendingRefresh.add(params.nodeId);
let v : Visualizer | undefined = this.treeData.get(params.nodeId);
if (v) {
this._onDidChangeTreeData.fire(v);
Expand All @@ -152,6 +154,13 @@ class VisualizerProvider extends vscode.Disposable implements CustomizableTreeDa
}

getTreeItem(element: Visualizer): vscode.TreeItem | Thenable<vscode.TreeItem> {
const n = Number(element.id);
if (this.pendingRefresh.delete(n)) {
return this.fetchItem(n).then((newV) => {
element.update(newV);
return element;
});
}
if (this.decorators.length == 0) {
return element;
}
Expand All @@ -173,28 +182,38 @@ class VisualizerProvider extends vscode.Disposable implements CustomizableTreeDa
return f(element.copy());
}

async fetchItem(n : number) : Promise<Visualizer> {
let d = await this.client.sendRequest(NodeInfoRequest.info, { nodeId : n });
if (this.pendingRefresh.delete(n)) {
// and again
return this.fetchItem(n);
}
let v = new Visualizer(d, this.ts.imageUri(d));
// console.log('Nodeid ' + d.id + ': visualizer ' + v.visId);
if (d.command) {
// PENDING: provide an API to register command (+ parameters) -> command translators.
if (d.command === 'vscode.open') {
v.command = { command : d.command, title: '', arguments: [v.resourceUri]};
} else {
v.command = { command : d.command, title: '', arguments: [v]};
}
}
return v;
}

getChildren(e?: Visualizer): Thenable<Visualizer[]> {
const self = this;
async function collectResults(arr: any, element: Visualizer): Promise<Visualizer[]> {
let res : Visualizer[] = [];
let refreshAgain : Visualizer[] = [];
for (let i = 0; i < arr.length; i++) {
let d = await self.client.sendRequest(NodeInfoRequest.info, { nodeId : arr[i] });
let v = new Visualizer(d, self.ts.imageUri(d));
// console.log('Nodeid ' + d.id + ': visualizer ' + v.visId);
if (d.command) {
// PENDING: provide an API to register command (+ parameters) -> command translators.
if (d.command === 'vscode.open') {
v.command = { command : d.command, title: '', arguments: [v.resourceUri]};
} else {
v.command = { command : d.command, title: '', arguments: [v]};
}
}
res.push(v);
res.push(await self.fetchItem(arr[i]));
}
const now : Visualizer[] = element.updateChildren(res, self);
for (let i = 0; i < arr.length; i++) {
const v = res[i];
self.treeData.set((v.id || -1) as number, v);
const n : number = Number(v.id || -1);
self.treeData.set(n, v);
v.parent = element;
}
return now;
Expand Down Expand Up @@ -288,7 +307,7 @@ export class Visualizer extends vscode.TreeItem {

for (let i = 0; i < newChildren.length; i++) {
let c = newChildren[i];
const n : number = (c.id || -1) as number;
const n : number = Number(c.id || -1);
const v : Visualizer | undefined = this.children?.get(n);
if (v) {
v.update(c);
Expand Down
2 changes: 1 addition & 1 deletion java/java.lsp.server/vscode/src/extension.ts
Expand Up @@ -478,7 +478,7 @@ export function activate(context: ExtensionContext): VSNetBeansAPI {
context.subscriptions.push(commands.registerCommand('java.project.debug', async (node, launchConfiguration?) => {
return runDebug(false, false, contextUri(node)?.toString() || '', undefined, launchConfiguration, true);
}));
context.subscriptions.push(commands.registerCommand('java.project.tet', async (node, launchConfiguration?) => {
context.subscriptions.push(commands.registerCommand('java.project.test', async (node, launchConfiguration?) => {
return runDebug(true, true, contextUri(node)?.toString() || '', undefined, launchConfiguration, true);
}));
context.subscriptions.push(commands.registerCommand('java.package.test', async (uri, launchConfiguration?) => {
Expand Down