This is an automated email from the ASF dual-hosted git repository.
sdedic pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/netbeans.git
The following commit(s) were added to refs/heads/master by this push:
new 822fd9c Dispose/disconnect tree view after client stop.
new 3ded4d1 Merge pull request #3348 from sdedic/vscode/tree-on-restart
822fd9c is described below
commit 822fd9c72d0a35b2d003526b6065915e684de83b
Author: Svata Dedic <[email protected]>
AuthorDate: Wed Dec 1 14:20:23 2021 +0100
Dispose/disconnect tree view after client stop.
---
java/java.lsp.server/vscode/src/explorer.ts | 36 ++++++++++++++++++++++------
java/java.lsp.server/vscode/src/extension.ts | 8 +++++++
2 files changed, 37 insertions(+), 7 deletions(-)
diff --git a/java/java.lsp.server/vscode/src/explorer.ts
b/java/java.lsp.server/vscode/src/explorer.ts
index 87f7169..1bb537a 100644
--- a/java/java.lsp.server/vscode/src/explorer.ts
+++ b/java/java.lsp.server/vscode/src/explorer.ts
@@ -1,14 +1,17 @@
+import { disconnect } from 'process';
import * as vscode from 'vscode';
import { LanguageClient } from 'vscode-languageclient/node';
import { NbLanguageClient } from './extension';
import { NodeChangedParams, NodeInfoNotification, NodeInfoRequest } from
'./protocol';
-export class TreeViewService {
+export class TreeViewService extends vscode.Disposable {
+ private handler : vscode.Disposable | undefined;
private client : NbLanguageClient;
private trees : Map<string, vscode.TreeView<Visualizer>> = new Map();
private images : Map<number, vscode.Uri> = new Map();
private providers : Map<number, VisualizerProvider> = new Map();
- constructor (c : NbLanguageClient) {
+ constructor (c : NbLanguageClient, disposeFunc : () => void) {
+ super(() => { this.disposeAllViews(); disposeFunc(); });
this.client = c;
}
@@ -16,6 +19,18 @@ export class TreeViewService {
return this.client;
}
+ private disposeAllViews() : void {
+ for (let tree of this.trees.values()) {
+ tree.dispose();
+ }
+ for (let provider of this.providers.values()) {
+ provider.dispose();
+ }
+ this.trees.clear();
+ this.providers.clear();
+ this.handler?.dispose();
+ }
+
public async createView(id : string, title? : string, options? :
Partial<vscode.TreeViewOptions<any>>) : Promise<vscode.TreeView<Visualizer>> {
let tv : vscode.TreeView<Visualizer> | undefined = this.trees.get(id);
if (tv) {
@@ -36,8 +51,9 @@ export class TreeViewService {
opts.showCollapseAll = options.showCollapseAll;
}
let view = vscode.window.createTreeView(id, opts);
+ this.trees.set(id, view);
// this will replace the handler over and over, but never mind
- this.client.onNotification(NodeInfoNotification.type, params =>
this.nodeChanged(params));
+ this.handler = this.client.onNotification(NodeInfoNotification.type,
params => this.nodeChanged(params));
return view;
}
@@ -60,7 +76,7 @@ export class TreeViewService {
}
-class VisualizerProvider implements vscode.TreeDataProvider<Visualizer> {
+class VisualizerProvider extends vscode.Disposable implements
vscode.TreeDataProvider<Visualizer> {
private root: Visualizer;
private treeData : Map<number, Visualizer> = new Map();
@@ -70,12 +86,17 @@ class VisualizerProvider implements
vscode.TreeDataProvider<Visualizer> {
id : string,
rootData : NodeInfoRequest.Data
) {
+ super(() => this.disconnect());
this.root = new Visualizer(rootData, ts.imageUri(rootData));
this.treeData.set(rootData.id, this.root);
}
private _onDidChangeTreeData: vscode.EventEmitter<Visualizer | undefined |
null | void> = new vscode.EventEmitter<Visualizer | undefined | null | void>();
readonly onDidChangeTreeData: vscode.Event<Visualizer | undefined | null |
void> = this._onDidChangeTreeData.event;
+
+ private disconnect() : void {
+ // nothing at the moment.
+ }
refresh(params : NodeChangedParams): void {
if (this.root.data.id === params.rootId) {
@@ -213,15 +234,16 @@ export async function createTreeView<T>(c:
NbLanguageClient, viewId: string, vie
* Registers the treeview service with the language server.
*/
export function createTreeViewService(c : NbLanguageClient): TreeViewService {
- const ts : TreeViewService = new TreeViewService(c);
- vscode.commands.registerCommand("foundProjects.deleteEntry", async
function (this: any, args: any) {
+ const d = vscode.commands.registerCommand("foundProjects.deleteEntry",
async function (this: any, args: any) {
let v = args as Visualizer;
let ok = await c.sendRequest(NodeInfoRequest.destroy, { nodeId :
v.data.id });
if (!ok) {
vscode.window.showErrorMessage('Cannot delete node ' + v.label);
}
});
-
+ const ts : TreeViewService = new TreeViewService(c, () => {
+ d.dispose()
+ });
return ts;
}
diff --git a/java/java.lsp.server/vscode/src/extension.ts
b/java/java.lsp.server/vscode/src/extension.ts
index 57062e8..19446e5 100644
--- a/java/java.lsp.server/vscode/src/extension.ts
+++ b/java/java.lsp.server/vscode/src/extension.ts
@@ -70,6 +70,14 @@ export class NbLanguageClient extends LanguageClient {
findTreeViewService(): TreeViewService {
return this._treeViewService;
}
+
+ stop(): Promise<void> {
+ // stop will be called even in case of external close & client
restart, so OK.
+ const r: Promise<void> = super.stop();
+ this._treeViewService.dispose();
+ return r;
+ }
+
}
function handleLog(log: vscode.OutputChannel, msg: string): void {
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists