6
6
commands , Event , EventEmitter , ExtensionContext , ProviderResult ,
7
7
RelativePattern , TreeDataProvider , TreeItem , Uri , window , workspace ,
8
8
} from "vscode" ;
9
- import { instrumentOperation , instrumentOperationAsVsCodeCommand } from "vscode-extension-telemetry-wrapper" ;
9
+ import { instrumentOperationAsVsCodeCommand } from "vscode-extension-telemetry-wrapper" ;
10
10
import { contextManager } from "../../extension.bundle" ;
11
11
import { Commands } from "../commands" ;
12
12
import { Context } from "../constants" ;
@@ -31,13 +31,24 @@ export class DependencyDataProvider implements TreeDataProvider<ExplorerNode> {
31
31
32
32
private _rootItems : ExplorerNode [ ] | undefined = undefined ;
33
33
private _refreshDelayTrigger : _ . DebouncedFunc < ( ( element ?: ExplorerNode ) => void ) > ;
34
+ /**
35
+ * The element which is pending to be refreshed.
36
+ * `undefined` denotes to root node.
37
+ * `null` means no node is pending.
38
+ */
39
+ private pendingRefreshElement : ExplorerNode | undefined | null ;
34
40
35
41
constructor ( public readonly context : ExtensionContext ) {
36
- context . subscriptions . push ( commands . registerCommand ( Commands . VIEW_PACKAGE_REFRESH , ( debounce ?: boolean , element ?: ExplorerNode ) =>
37
- this . refreshWithLog ( debounce , element ) ) ) ;
42
+ // commands that do not send back telemetry
43
+ context . subscriptions . push ( commands . registerCommand ( Commands . VIEW_PACKAGE_INTERNAL_REFRESH , ( debounce ?: boolean , element ?: ExplorerNode ) =>
44
+ this . refresh ( debounce , element ) ) ) ;
38
45
context . subscriptions . push ( commands . registerCommand ( Commands . EXPORT_JAR_REPORT , ( terminalId : string , message : string ) => {
39
46
appendOutput ( terminalId , message ) ;
40
47
} ) ) ;
48
+
49
+ // normal commands
50
+ context . subscriptions . push ( instrumentOperationAsVsCodeCommand ( Commands . VIEW_PACKAGE_REFRESH , ( debounce ?: boolean , element ?: ExplorerNode ) =>
51
+ this . refresh ( debounce , element ) ) ) ;
41
52
context . subscriptions . push ( instrumentOperationAsVsCodeCommand ( Commands . VIEW_PACKAGE_EXPORT_JAR , async ( node : INodeData ) => {
42
53
executeExportJarTask ( node ) ;
43
54
} ) ) ;
@@ -61,28 +72,33 @@ export class DependencyDataProvider implements TreeDataProvider<ExplorerNode> {
61
72
62
73
Settings . registerConfigurationListener ( ( updatedConfig , oldConfig ) => {
63
74
if ( updatedConfig . refreshDelay !== oldConfig . refreshDelay ) {
64
- this . setRefreshDelay ( updatedConfig . refreshDelay ) ;
75
+ this . setRefreshDebounceFunc ( updatedConfig . refreshDelay ) ;
65
76
}
66
77
} ) ;
67
- this . setRefreshDelay ( ) ;
78
+ this . setRefreshDebounceFunc ( ) ;
68
79
}
69
80
70
- public refreshWithLog ( debounce ?: boolean , element ?: ExplorerNode ) {
71
- if ( Settings . autoRefresh ( ) ) {
72
- this . refresh ( debounce , element ) ;
81
+ public refresh ( debounce = false , element ?: ExplorerNode ) {
82
+ if ( element === undefined || this . pendingRefreshElement === undefined ) {
83
+ this . _refreshDelayTrigger ( undefined ) ;
84
+ this . pendingRefreshElement = undefined ;
85
+ } else if ( this . pendingRefreshElement === null
86
+ || element . isItselfOrAncestorOf ( this . pendingRefreshElement ) ) {
87
+ this . _refreshDelayTrigger ( element ) ;
88
+ this . pendingRefreshElement = element ;
89
+ } else if ( this . pendingRefreshElement . isItselfOrAncestorOf ( element ) ) {
90
+ this . _refreshDelayTrigger ( this . pendingRefreshElement ) ;
73
91
} else {
74
- instrumentOperation ( Commands . VIEW_PACKAGE_REFRESH , ( ) => this . refresh ( debounce , element ) ) ( ) ;
92
+ this . _refreshDelayTrigger . flush ( ) ;
93
+ this . _refreshDelayTrigger ( element ) ;
94
+ this . pendingRefreshElement = element ;
75
95
}
76
- }
77
-
78
- public refresh ( debounce = false , element ?: ExplorerNode ) {
79
- this . _refreshDelayTrigger ( element ) ;
80
96
if ( ! debounce ) { // Immediately refresh
81
97
this . _refreshDelayTrigger . flush ( ) ;
82
98
}
83
99
}
84
100
85
- public setRefreshDelay ( wait ?: number ) {
101
+ public setRefreshDebounceFunc ( wait ?: number ) {
86
102
if ( ! wait ) {
87
103
wait = Settings . refreshDelay ( ) ;
88
104
}
@@ -142,6 +158,7 @@ export class DependencyDataProvider implements TreeDataProvider<ExplorerNode> {
142
158
}
143
159
explorerNodeCache . removeNodeChildren ( element ) ;
144
160
this . _onDidChangeTreeData . fire ( element ) ;
161
+ this . pendingRefreshElement = null ;
145
162
}
146
163
147
164
private async getRootNodes ( ) : Promise < ExplorerNode [ ] > {
0 commit comments