Skip to content

Commit 4cf1e5c

Browse files
Kartik Rajkimadeline
andauthored
Don't open output panel after each save when rebuilding on save (#9781)
* Added tests * News entry * Update news/2 Fixes/9603.md Co-Authored-By: Kim-Adeline Miguel <51720070+kimadeline@users.noreply.github.com> * Swap back two methods in the constructor Co-authored-by: Kim-Adeline Miguel <51720070+kimadeline@users.noreply.github.com>
1 parent 58ad19c commit 4cf1e5c

3 files changed

Lines changed: 59 additions & 6 deletions

File tree

news/2 Fixes/9603.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Don't open output panel after each save when rebuilding on save.

src/client/workspaceSymbols/main.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ export class WorkspaceSymbols implements Disposable {
7272
private registerCommands() {
7373
this.disposables.push(
7474
this.commandMgr.registerCommand(Commands.Build_Workspace_Symbols, async (rebuild: boolean = true, token?: CancellationToken) => {
75-
const promises = this.buildWorkspaceSymbols(rebuild, token);
75+
const promises = this.buildWorkspaceSymbols(rebuild, token, true);
7676
return Promise.all(promises);
7777
})
7878
);
@@ -88,7 +88,7 @@ export class WorkspaceSymbols implements Disposable {
8888
}
8989

9090
// tslint:disable-next-line:no-any
91-
private buildWorkspaceSymbols(rebuild: boolean = true, token?: CancellationToken): Promise<any>[] {
91+
private buildWorkspaceSymbols(rebuild: boolean = true, token?: CancellationToken, show = false): Promise<any>[] {
9292
if (token && token.isCancellationRequested) {
9393
return [];
9494
}
@@ -114,7 +114,9 @@ export class WorkspaceSymbols implements Disposable {
114114
return;
115115
} catch (error) {
116116
if (!isNotInstalledError(error)) {
117-
this.outputChannel.show();
117+
if (show) {
118+
this.outputChannel.show();
119+
}
118120
return;
119121
}
120122
}

src/test/workspaceSymbols/main.unit.test.ts

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@
44
'use strict';
55

66
import * as assert from 'assert';
7-
import { use } from 'chai';
7+
import { expect, use } from 'chai';
88
import * as chaiAsPromised from 'chai-as-promised';
9-
import { anyString, anything, instance, mock, when } from 'ts-mockito';
9+
import { anyString, anything, instance, mock, reset, verify, when } from 'ts-mockito';
1010
import { EventEmitter, TextDocument, Uri, WorkspaceFolder } from 'vscode';
1111
import { ApplicationShell } from '../../client/common/application/applicationShell';
1212
import { CommandManager } from '../../client/common/application/commandManager';
1313
import { DocumentManager } from '../../client/common/application/documentManager';
1414
import { IApplicationShell, ICommandManager, IDocumentManager, IWorkspaceService } from '../../client/common/application/types';
1515
import { WorkspaceService } from '../../client/common/application/workspace';
1616
import { ConfigurationService } from '../../client/common/configuration/service';
17-
import { STANDARD_OUTPUT_CHANNEL } from '../../client/common/constants';
17+
import { Commands, STANDARD_OUTPUT_CHANNEL } from '../../client/common/constants';
1818
import { FileSystem } from '../../client/common/platform/fileSystem';
1919
import { IFileSystem } from '../../client/common/platform/types';
2020
import { ProcessService } from '../../client/common/process/proc';
@@ -160,6 +160,56 @@ suite('Workspace symbols main', () => {
160160
assert.equal(shellOutput, 'Generating Tags');
161161
});
162162

163+
test('Should not show output channel when rebuilding on save', async () => {
164+
when(workspaceService.workspaceFolders).thenReturn(workspaceFolders);
165+
when(workspaceService.getWorkspaceFolder(anything())).thenReturn(workspaceFolders[0]);
166+
when(configurationService.getSettings(anything())).thenReturn({
167+
workspaceSymbols: {
168+
ctagsPath,
169+
enabled: true,
170+
exclusionPatterns: [],
171+
rebuildOnFileSave: true,
172+
tagFilePath: 'foo'
173+
}
174+
} as any);
175+
reset(applicationShell);
176+
when(applicationShell.setStatusBarMessage(anyString(), anything())).thenThrow(new Error('Generating workspace tags failed with Error'));
177+
178+
workspaceSymbols = new WorkspaceSymbols(instance(serviceContainer));
179+
eventEmitter.fire({ uri: Uri.file('folder') } as any);
180+
await sleep(1);
181+
182+
verify(outputChannel.show()).never();
183+
});
184+
185+
test('Output channel is shown when using Command `Build Workspace symbols`', async () => {
186+
let buildWorkspaceSymbolsHandler!: Function;
187+
when(workspaceService.workspaceFolders).thenReturn(workspaceFolders);
188+
when(workspaceService.getWorkspaceFolder(anything())).thenReturn(workspaceFolders[0]);
189+
when(configurationService.getSettings(anything())).thenReturn({
190+
workspaceSymbols: {
191+
ctagsPath,
192+
enabled: true,
193+
exclusionPatterns: [],
194+
rebuildOnFileSave: true,
195+
tagFilePath: 'foo'
196+
}
197+
} as any);
198+
reset(commandManager);
199+
when(commandManager.registerCommand(anything(), anything())).thenCall((commandID, cb) => {
200+
expect(commandID).to.equal(Commands.Build_Workspace_Symbols);
201+
buildWorkspaceSymbolsHandler = cb;
202+
return mockDisposable;
203+
});
204+
reset(applicationShell);
205+
when(applicationShell.setStatusBarMessage(anyString(), anything())).thenThrow(new Error('Generating workspace tags failed with Error'));
206+
207+
workspaceSymbols = new WorkspaceSymbols(instance(serviceContainer));
208+
await buildWorkspaceSymbolsHandler();
209+
210+
verify(outputChannel.show()).once();
211+
});
212+
163213
test('Should not rebuild on save if the setting is disabled', () => {
164214
when(workspaceService.workspaceFolders).thenReturn(workspaceFolders);
165215
when(configurationService.getSettings(anything())).thenReturn({

0 commit comments

Comments
 (0)