@@ -20,6 +20,7 @@ import {
20
20
commands ,
21
21
Disposable ,
22
22
ExtensionContext ,
23
+ Progress ,
23
24
ProgressLocation ,
24
25
window ,
25
26
} from 'vscode' ;
@@ -115,51 +116,67 @@ export class NxlsClient {
115
116
this . actor . send ( { type : 'STOP' } ) ;
116
117
}
117
118
118
- public async refreshWorkspace ( ) {
119
- await window . withProgress (
120
- {
121
- location : ProgressLocation . Notification ,
122
- title : 'Refreshing Workspace' ,
123
- cancellable : false ,
124
- } ,
125
- async ( progress ) => {
126
- try {
127
- if ( this . actor . getSnapshot ( ) . matches ( 'running' ) ) {
119
+ public async refreshWorkspace ( silent = false ) {
120
+ const refreshLogic = async (
121
+ progress ?: Progress < { message ?: string ; increment ?: number } > ,
122
+ ) => {
123
+ try {
124
+ if ( this . actor . getSnapshot ( ) . matches ( 'running' ) ) {
125
+ if ( progress ) {
128
126
progress . report ( { message : 'Stopping nx daemon' , increment : 10 } ) ;
129
- try {
130
- await this . sendRequest ( NxStopDaemonRequest , undefined ) ;
131
- } catch ( e ) {
132
- // errors while stopping the daemon aren't critical
133
- }
134
-
135
- this . stop ( ) ;
136
127
}
128
+ try {
129
+ await this . sendRequest ( NxStopDaemonRequest , undefined ) ;
130
+ } catch ( e ) {
131
+ // errors while stopping the daemon aren't critical
132
+ }
133
+
134
+ this . stop ( ) ;
135
+ }
136
+ if ( progress ) {
137
137
progress . report ( { increment : 30 } ) ;
138
+ }
138
139
140
+ if ( progress ) {
139
141
progress . report ( { message : 'Restarting language server' } ) ;
140
- await waitFor ( this . actor , ( snapshot ) => snapshot . matches ( 'idle' ) ) ;
141
- this . start ( ) ;
142
+ }
143
+ await waitFor ( this . actor , ( snapshot ) => snapshot . matches ( 'idle' ) ) ;
144
+ this . start ( ) ;
145
+ if ( progress ) {
142
146
progress . report ( { message : 'Refreshing workspace' , increment : 30 } ) ;
147
+ }
143
148
144
- await this . sendNotification ( NxWorkspaceRefreshNotification ) ;
145
-
146
- await new Promise < void > ( ( resolve ) => {
147
- const disposable = this . onNotification (
148
- NxWorkspaceRefreshNotification ,
149
- ( ) => {
150
- disposable . dispose ( ) ;
151
- resolve ( ) ;
152
- } ,
153
- ) ;
154
- } ) ;
155
- } catch ( error ) {
156
- logAndShowError (
157
- "Couldn't refresh workspace. Please view the logs for more information." ,
158
- error ,
149
+ await this . sendNotification ( NxWorkspaceRefreshNotification ) ;
150
+
151
+ await new Promise < void > ( ( resolve ) => {
152
+ const disposable = this . onNotification (
153
+ NxWorkspaceRefreshNotification ,
154
+ ( ) => {
155
+ disposable . dispose ( ) ;
156
+ resolve ( ) ;
157
+ } ,
159
158
) ;
160
- }
161
- } ,
162
- ) ;
159
+ } ) ;
160
+ } catch ( error ) {
161
+ logAndShowError (
162
+ "Couldn't refresh workspace. Please view the logs for more information." ,
163
+ error ,
164
+ ) ;
165
+ }
166
+ } ;
167
+
168
+ if ( silent ) {
169
+ await refreshLogic ( ) ;
170
+ } else {
171
+ await window . withProgress (
172
+ {
173
+ location : ProgressLocation . Notification ,
174
+ title : 'Refreshing Workspace' ,
175
+ cancellable : false ,
176
+ } ,
177
+ refreshLogic ,
178
+ ) ;
179
+ }
163
180
}
164
181
165
182
public async sendRequest < P , R , E > (
@@ -393,7 +410,7 @@ function refreshWorkspaceOnBranchChange(
393
410
`Branch changed from ${ branch } to ${ newBranch } , refreshing workspace` ,
394
411
) ;
395
412
branch = newBranch ;
396
- commands . executeCommand ( 'nxConsole.refreshWorkspace' ) ;
413
+ commands . executeCommand ( 'nxConsole.refreshWorkspace' , true ) ;
397
414
}
398
415
} ) ;
399
416
}
0 commit comments