Skip to content

Commit

Permalink
perf: only request type data when it is visible in the treeView
Browse files Browse the repository at this point in the history
  • Loading branch information
zcf0508 committed Aug 6, 2024
1 parent 97db8c8 commit a9937c9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -157,6 +157,10 @@ export class StateManager {
selections: readonly vscode.Range[],
ignoreSelectionLock = false
) {
if (!treeView?.visible) {
return
}

if (this.getSelectionLock() && !ignoreSelectionLock) {
return
}
Expand Down
12 changes: 8 additions & 4 deletions packages/typescript-explorer-vscode/src/view/views.ts
Original file line number Diff line number Diff line change
@@ -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<TypeTreeItem> | 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 }
}

0 comments on commit a9937c9

Please sign in to comment.