Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import stripAnsi from 'strip-ansi';
import { OutputChannel, window } from 'vscode';
import { CommandExecution } from '../cli';
import { nls } from '../messages';
import { SfdxSettingsService } from '../settings';

export class ChannelService {
private readonly channel: OutputChannel;
Expand Down Expand Up @@ -37,6 +38,9 @@ export class ChannelService {
}

public streamCommandStartStop(execution: CommandExecution) {
if (SfdxSettingsService.getEnableClearOutputBeforeEachCommand()) {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The channel service is my first choice to attempt to handle this preference in one central location. Unfortunately, the way the channel service is used throughout the app is very inconsistent. This "streamCommandStartStop()" is used by some of the abstract executors ( SfdxCommandletExecutor, LibraryExectutor ) that are exported from salesforcedx-utils-vscode.

this.clear();
}
this.channel.append(nls.localize('channel_starting_message'));
this.channel.appendLine(execution.command.toString());
this.channel.appendLine('');
Expand Down Expand Up @@ -101,4 +105,8 @@ export class ChannelService {
public appendLine(text: string) {
this.channel.appendLine(text);
}

public clear() {
this.channel.clear();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
TelemetryService
} from '../index';
import { nls } from '../messages';
import { SfdxSettingsService } from '../settings';
import { CommandletExecutor, ContinueResponse } from '../types';
import { getRootWorkspacePath } from '../workspaces';
import { ChannelService } from './channelService';
Expand Down Expand Up @@ -161,6 +162,9 @@ export abstract class LibraryCommandletExecutor<T>
const startTime = process.hrtime();
const channelService = new ChannelService(this.outputChannel);
const telemetryService = TelemetryService.getInstance();
if (SfdxSettingsService.getEnableClearOutputBeforeEachCommand()) {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The LibraryCommandletExecutor is exported from salesforcedx-utils-vscode and is another place that I found to check and clear the output log.

channelService.clear();
}

channelService.showCommandWithTimestamp(
`${nls.localize('channel_starting_message')}${this.executionName}\n`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import { Observable } from 'rxjs/Observable';
import * as vscode from 'vscode';
import { CommandExecution } from '../cli';
import { SFDX_CORE_CONFIGURATION_NAME } from '../constants';
import { nls } from '../messages';
import { ChannelService } from './index';

Expand Down Expand Up @@ -111,9 +112,8 @@ export class NotificationService {
'notification_successful_execution_text',
executionName
);
const showCLISuccessMsg = vscode.workspace
.getConfiguration('salesforcedx-vscode-core')
.get<boolean>('show-cli-success-msg', true);
const coreConfigurationName = vscode.workspace.getConfiguration(SFDX_CORE_CONFIGURATION_NAME);
const showCLISuccessMsg = coreConfigurationName.get<boolean>('show-cli-success-msg', true);
if (showCLISuccessMsg) {
const showButtonText = nls.localize('notification_show_button_text');
const showOnlyStatusBarButtonText = nls.localize(
Expand All @@ -128,9 +128,7 @@ export class NotificationService {
if (selection === showButtonText && channelService) {
channelService.showChannelOutput();
} else if (selection === showOnlyStatusBarButtonText) {
await vscode.workspace
.getConfiguration('salesforcedx-vscode-core')
.update('show-cli-success-msg', false);
await coreConfigurationName.update('show-cli-success-msg', false);
}
}
} else {
Expand Down
3 changes: 3 additions & 0 deletions packages/salesforcedx-utils-vscode/src/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const SETTING_CLEAR_OUTPUT_TAB = 'clearOutputTab';
Copy link
Copy Markdown
Contributor Author

@dehru dehru Jul 25, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are now all exported by salesforcedx-utils-vscode and consumed in other modules so that the string 'salesforcedx-vscode-core' is not in 20 places in various modules of the mono-repo.

export const SFDX_CORE_CONFIGURATION_NAME = 'salesforcedx-vscode-core';
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's your thought here having these two identical strings with different names?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I decided that since they represent 2 different things, that we should have 2 constants, even though they are the same string.

I wanted anyone changing these in the future to be more aware of what this constant represents.

export const SFDX_CORE_EXTENSION_NAME = 'salesforcedx-vscode-core';
5 changes: 5 additions & 0 deletions packages/salesforcedx-utils-vscode/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ export {
} from './commands/commandletExecutors';
export { SfdxCommandlet } from './commands/sfdxCommandlet';
export { ConfigSource, ConfigUtil } from './config/configUtil';
export {
SETTING_CLEAR_OUTPUT_TAB,
SFDX_CORE_CONFIGURATION_NAME,
SFDX_CORE_EXTENSION_NAME
} from './constants';
export { OrgInfo, WorkspaceContextUtil, getLogDirPath } from './context/workspaceContextUtil';
export {
TelemetryService,
Expand Down
1 change: 1 addition & 0 deletions packages/salesforcedx-utils-vscode/src/settings/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './sfdxSettingsService';
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import * as vscode from 'vscode';
import { SETTING_CLEAR_OUTPUT_TAB, SFDX_CORE_CONFIGURATION_NAME } from '../constants';

export class SfdxSettingsService {
public static getEnableClearOutputBeforeEachCommand(): boolean {
return vscode.workspace
.getConfiguration(SFDX_CORE_CONFIGURATION_NAME)
.get<boolean>(SETTING_CLEAR_OUTPUT_TAB, false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import * as util from 'util';
import { env, ExtensionContext, workspace } from 'vscode';
import { SFDX_CORE_CONFIGURATION_NAME } from '../constants';
import { disableCLITelemetry, isCLITelemetryAllowed } from './cliConfiguration';
import { TelemetryReporter } from './telemetryReporter';

Expand Down Expand Up @@ -140,7 +141,7 @@ export class TelemetryService {
.getConfiguration('telemetry')
.get<boolean>('enableTelemetry', true) &&
workspace
.getConfiguration('salesforcedx-vscode-core')
.getConfiguration(SFDX_CORE_CONFIGURATION_NAME)
.get<boolean>('telemetry.enabled', true)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,27 @@ describe('Channel Service', () => {
channelService.streamCommandOutput(execution);
expect(ensureDoubleDigitsStub.called).equals(true);
});

it('should clear channel', async () => {
const clearStub = sb.stub(mChannel, 'clear');
sb.stub(vscodeStub.window, 'createOutputChannel').returns(mChannel);
// @ts-ignore
channelService.clear();
expect(clearStub.called).equals(true);
});

it('should clear channel when streamCommandStartStop is executed', () => {
const clearStub = sb.stub(mChannel, 'clear');
sb.stub(vscodeStub.window, 'createOutputChannel').returns(mChannel);
const execution = new CliCommandExecutor(
new SfdxCommandBuilder()
.withArg('force')
.withArg('--help')
.build(),
{}
).execute();
// @ts-ignore
channelService.streamCommandStartStop(execution);
expect(clearStub.called).equals(true);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,24 @@ describe('LibraryCommandletExecutor', () => {
expect(showInfoStub.called).to.be.true;
});

it('should clear channel output if preference set', async () => {
sb.stub(vscodeStub.workspace, 'getConfiguration').returns({
get: () => true
});
const clearStub = sb.stub(MockChannel.prototype, 'clear');
await executor.execute({ data: { success: false }, type: 'CONTINUE' });
expect(clearStub.called).to.be.true;
});

it('should NOT clear channel output if preference NOT set', async () => {
sb.stub(vscodeStub.workspace, 'getConfiguration').returns({
get: () => false
});
const clearStub = sb.stub(MockChannel.prototype, 'clear');
await executor.execute({ data: { success: false }, type: 'CONTINUE' });
expect(clearStub.called).not.to.be.true;
});

it('should show failed execution notification if run returns false', async () => {
const showErrStub = sb
.stub(vscodeStub.window, 'showErrorMessage')
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { expect } from 'chai';
import * as proxyquire from 'proxyquire';
import { createSandbox, SinonSandbox } from 'sinon';
import { vscodeStub } from '../commands/mocks';

const { SfdxSettingsService } = proxyquire.noCallThru()(
'../../../src/settings/index',
{
vscode: vscodeStub
}
);

describe('SfdxSettingsService', () => {
let sb: SinonSandbox;
beforeEach(() => {
sb = createSandbox();
});
afterEach(() => {
sb.restore();
});
describe('when reading workspace preference for clearing output', () => {
it('should return true when underlying workspace configuration for preference', () => {
sb.stub(vscodeStub.workspace, 'getConfiguration').returns({
get: () => true
});
expect(SfdxSettingsService.getEnableClearOutputBeforeEachCommand()).equals(true);
});
it('should return false if underlying configuration is false', () => {
sb.stub(vscodeStub.workspace, 'getConfiguration').returns({
get: () => false
});
expect(SfdxSettingsService.getEnableClearOutputBeforeEachCommand()).equals(false);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/

import { SFDX_CORE_CONFIGURATION_NAME } from '@salesforce/salesforcedx-utils-vscode/out/src';
import * as vscode from 'vscode';

export function retrieveTestCodeCoverage(): boolean {
return vscode.workspace
.getConfiguration('salesforcedx-vscode-core')
.getConfiguration(SFDX_CORE_CONFIGURATION_NAME)
.get<boolean>('retrieve-test-code-coverage', false);
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ describe('Quick launch apex tests', () => {
sb = createSandbox();
settingStub = sb.stub();
sb.stub(vscode.workspace, 'getConfiguration')
.withArgs('salesforcedx-vscode-core')
.withArgs(utils.SFDX_CORE_CONFIGURATION_NAME)
.returns({
get: settingStub
});
Expand Down
3 changes: 2 additions & 1 deletion packages/salesforcedx-vscode-apex/src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/

import { SFDX_CORE_CONFIGURATION_NAME } from '@salesforce/salesforcedx-utils-vscode/out/src';
import * as vscode from 'vscode';

export function retrieveTestCodeCoverage(): boolean {
return vscode.workspace
.getConfiguration('salesforcedx-vscode-core')
.getConfiguration(SFDX_CORE_CONFIGURATION_NAME)
.get<boolean>('retrieve-test-code-coverage', false);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import { ExecuteService } from '@salesforce/apex-node';
import { AuthInfo, ConfigAggregator, Connection } from '@salesforce/core';
import { MockTestOrgData, testSetup } from '@salesforce/core/lib/testSetup';
import { getRootWorkspacePath } from '@salesforce/salesforcedx-utils-vscode/out/src';
import { getRootWorkspacePath, SFDX_CORE_CONFIGURATION_NAME } from '@salesforce/salesforcedx-utils-vscode/out/src';
import { ChannelService } from '@salesforce/salesforcedx-utils-vscode/out/src/commands';
import { TraceFlags } from '@salesforce/salesforcedx-utils-vscode/out/src/helpers';
import { ContinueResponse } from '@salesforce/salesforcedx-utils-vscode/out/src/types';
Expand Down Expand Up @@ -40,7 +40,7 @@ describe('Force Apex Execute', () => {
sb = createSandbox();
settingStub = sb.stub();
sb.stub(vscode.workspace, 'getConfiguration')
.withArgs('salesforcedx-vscode-core')
.withArgs(SFDX_CORE_CONFIGURATION_NAME)
.returns({
get: settingStub
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* Licensed under the BSD 3-Clause license.
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
import { SFDX_CORE_CONFIGURATION_NAME } from '@salesforce/salesforcedx-utils-vscode/out/src';
import { expect } from 'chai';
import { createSandbox, SinonStub } from 'sinon';
import * as vscode from 'vscode';
Expand All @@ -18,7 +19,7 @@ describe('Settings', () => {
settingStub = sandbox.stub();
sandbox
.stub(vscode.workspace, 'getConfiguration')
.withArgs('salesforcedx-vscode-core')
.withArgs(SFDX_CORE_CONFIGURATION_NAME)
.returns({
get: settingStub
});
Expand Down
7 changes: 6 additions & 1 deletion packages/salesforcedx-vscode-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -954,8 +954,13 @@
],
"configuration": {
"type": "object",
"title": "%feature_previews_title%",
"title": "%core_settings_title%",
"properties": {
"salesforcedx-vscode-core.clearOutputTab": {
"type": "boolean",
"default": false,
"description": "%setting_clear_output_tab_description%"
},
"salesforcedx-vscode-core.push-or-deploy-on-save.overrideConflictsOnPush": {
"type": "boolean",
"default": false,
Expand Down
2 changes: 1 addition & 1 deletion packages/salesforcedx-vscode-core/package.nls.ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"force_data_soql_query_input_text": "SFDX: SOQL クエリを実行...",
"force_data_soql_query_selection_text": "SFDX: 現在選択されているテキストを使用して SOQL クエリを実行",
"force_package_install_text": "SFDX: パッケージをインストール",
"feature_previews_title": "Salesforce 機能のプレビュー",
"core_settings_title": "Salesforce 機能のプレビュー",
"force_project_create_text": "SFDX: プロジェクトを作成",
"force_project_with_manifest_create_text": "SFDX: マニフェストファイルを使用してプロジェクトを作成",
"force_apex_trigger_create_text": "SFDX: Apex トリガを作成",
Expand Down
5 changes: 3 additions & 2 deletions packages/salesforcedx-vscode-core/package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"force_data_soql_query_input_text": "SFDX: Execute SOQL Query...",
"force_data_soql_query_selection_text": "SFDX: Execute SOQL Query with Currently Selected Text",
"force_package_install_text": "SFDX: Install Package",
"feature_previews_title": "Salesforce Feature Previews",
"core_settings_title": "Salesforce Core Configuration",
"force_project_create_text": "SFDX: Create Project",
"force_project_with_manifest_create_text": "SFDX: Create Project with Manifest",
"force_apex_trigger_create_text": "SFDX: Create Apex Trigger",
Expand Down Expand Up @@ -82,5 +82,6 @@
"force_function_stop": "SFDX: Stop Function",
"force_sobjects_refresh": "SFDX: Refresh SObject Definitions",
"enable_sobject_refresh_on_startup_description": "If a project has no sObject definitions, specifies whether to automatically refresh sObject definitions on extension activation (true) or not (false).",
"force_launch_apex_replay_debugger_with_current_file": "SFDX: Launch Apex Replay Debugger with Current File"
"force_launch_apex_replay_debugger_with_current_file": "SFDX: Launch Apex Replay Debugger with Current File",
"setting_clear_output_tab_description": "When a new command is run, clear the output content from the previous command."
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import * as vscode from 'vscode';
import { EmptyPostChecker } from '.';
import { channelService } from '../../channels';
import { notificationService, ProgressNotification } from '../../notifications';
import { sfdxCoreSettings } from '../../settings';
import { taskViewService } from '../../statuses';
import { telemetryService } from '../../telemetry';
import { getRootWorkspacePath } from '../../util';
Expand Down Expand Up @@ -165,6 +166,9 @@ export class SfdxCommandlet<T> {
}

public async run(): Promise<void> {
if (sfdxCoreSettings.getEnableClearOutputBeforeEachCommand()) {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding this to the run() method here basically adds this feature to all the commands that extend SfdxCommandlet in the salesforcedx-vscode-core extension. I wish there was an elegant single cut-point elsewhere in the salesforcedx-utils-vscode module like this, but there was not.

channelService.clear();
}
if (await this.prechecker.check()) {
let inputs = await this.gatherer.gather();
inputs = await this.postchecker.check(inputs);
Expand Down
1 change: 0 additions & 1 deletion packages/salesforcedx-vscode-core/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ export const INTERNAL_DEVELOPMENT_FLAG = 'internal-development';
export const PUSH_OR_DEPLOY_ON_SAVE_ENABLED = 'push-or-deploy-on-save.enabled';
export const PUSH_OR_DEPLOY_ON_SAVE_OVERRIDE_CONFLICTS = 'push-or-deploy-on-save.overrideConflictsOnPush';
export const RETRIEVE_TEST_CODE_COVERAGE = 'retrieve-test-code-coverage';
export const SFDX_CORE_CONFIGURATION_NAME = 'salesforcedx-vscode-core';
export const SHOW_CLI_SUCCESS_INFO_MSG = 'show-cli-success-msg';
export const TELEMETRY_ENABLED = 'telemetry.enabled';
export const ENABLE_SOBJECT_REFRESH_ON_STARTUP =
Expand Down
4 changes: 2 additions & 2 deletions packages/salesforcedx-vscode-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* Licensed under the BSD 3-Clause license.
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
import { SFDX_CORE_CONFIGURATION_NAME } from '@salesforce/salesforcedx-utils-vscode/out/src';
import * as vscode from 'vscode';
import { channelService } from './channels';
import {
Expand Down Expand Up @@ -91,8 +92,7 @@ import {
setupConflictView
} from './conflict';
import {
ENABLE_SOBJECT_REFRESH_ON_STARTUP,
SFDX_CORE_CONFIGURATION_NAME
ENABLE_SOBJECT_REFRESH_ON_STARTUP
} from './constants';
import { getDefaultUsernameOrAlias } from './context';
import { workspaceContext } from './context';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/

import { SETTING_CLEAR_OUTPUT_TAB, SFDX_CORE_CONFIGURATION_NAME } from '@salesforce/salesforcedx-utils-vscode/out/src';
import * as vscode from 'vscode';
import {
BETA_DEPLOY_RETRIEVE,
CONFLICT_DETECTION_ENABLED,
INTERNAL_DEVELOPMENT_FLAG,
PUSH_OR_DEPLOY_ON_SAVE_ENABLED,
PUSH_OR_DEPLOY_ON_SAVE_OVERRIDE_CONFLICTS,
RETRIEVE_TEST_CODE_COVERAGE,
SFDX_CORE_CONFIGURATION_NAME,
SHOW_CLI_SUCCESS_INFO_MSG,
TELEMETRY_ENABLED
} from '../constants';
Expand Down Expand Up @@ -75,6 +74,10 @@ export class SfdxCoreSettings {
return this.getConfigValue(CONFLICT_DETECTION_ENABLED, false);
}

public getEnableClearOutputBeforeEachCommand(): boolean {
return this.getConfigValue(SETTING_CLEAR_OUTPUT_TAB, false);
}
Copy link
Copy Markdown
Contributor

@jeffb-sfdc jeffb-sfdc Jul 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit pick: please add an extra carriage return after the closing curly brace.


private getConfigValue<T>(key: string, defaultValue: T): T {
return this.getConfiguration().get<T>(key, defaultValue);
}
Expand Down
Loading