From a9937c9627e4804623d3e2c3c2f329dc8210f2b0 Mon Sep 17 00:00:00 2001 From: zcf0508 Date: Tue, 6 Aug 2024 17:28:57 +0800 Subject: [PATCH] perf: only request type data when it is visible in the treeView --- .../src/state/stateManager.ts | 6 +++++- .../typescript-explorer-vscode/src/view/views.ts | 12 ++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/packages/typescript-explorer-vscode/src/state/stateManager.ts b/packages/typescript-explorer-vscode/src/state/stateManager.ts index 8c6b648..ac28dbe 100644 --- a/packages/typescript-explorer-vscode/src/state/stateManager.ts +++ b/packages/typescript-explorer-vscode/src/state/stateManager.ts @@ -4,7 +4,7 @@ import { selectionEnabled } from "../config" import { getTypeTreeAtRange } from "../server" import { isDocumentSupported, logError, showError } from "../util" import { TypeTreeItem, TypeTreeProvider } from "../view/typeTreeView" -import { ViewProviders } from "../view/views" +import { ViewProviders, treeView } from "../view/views" export class StateManager { public typeTree: TypeInfo | undefined @@ -157,6 +157,10 @@ export class StateManager { selections: readonly vscode.Range[], ignoreSelectionLock = false ) { + if (!treeView?.visible) { + return + } + if (this.getSelectionLock() && !ignoreSelectionLock) { return } diff --git a/packages/typescript-explorer-vscode/src/view/views.ts b/packages/typescript-explorer-vscode/src/view/views.ts index a5350a2..763caaa 100644 --- a/packages/typescript-explorer-vscode/src/view/views.ts +++ b/packages/typescript-explorer-vscode/src/view/views.ts @@ -1,20 +1,24 @@ import * as vscode from "vscode" import { StateManager } from "../state/stateManager" -import { TypeTreeProvider } from "./typeTreeView" +import { TypeTreeItem, TypeTreeProvider } from "./typeTreeView" export type ViewProviders = { typeTreeProvider: TypeTreeProvider } +export let treeView: vscode.TreeView | undefined + export function createAndRegisterViews( context: vscode.ExtensionContext, stateManager: StateManager ): ViewProviders { const typeTreeProvider = new TypeTreeProvider(stateManager) - context.subscriptions.push( - vscode.window.registerTreeDataProvider("type-tree", typeTreeProvider) - ) + treeView = vscode.window.createTreeView("type-tree", { + treeDataProvider: typeTreeProvider, + }) + + context.subscriptions.push(treeView) return { typeTreeProvider } }