Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mz/w 14720788/diff refresh to sf #5418

Merged
merged 5 commits into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
24 changes: 12 additions & 12 deletions packages/salesforcedx-vscode-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@
"when": "sfdx:project_opened && resourceLangId != 'forcesourcemanifest' && sfdx:has_default_username"
},
{
"command": "sfdx.force.diff",
"command": "sfdx.diff",
"when": "!explorerResourceIsFolder && sfdx:project_opened && resourceLangId != 'forcesourcemanifest' && sfdx:has_default_username"
},
{
Expand All @@ -254,7 +254,7 @@
"when": "explorerResourceIsFolder && resourcePath =~ /classes/ && sfdx:project_opened"
},
{
"command": "sfdx.force.folder.diff",
"command": "sfdx.folder.diff",
"when": "explorerResourceIsFolder && sfdx:project_opened && sfdx:has_default_username"
},
{
Expand Down Expand Up @@ -306,7 +306,7 @@
"when": "explorerResourceIsFolder && resourceFilename == triggers && sfdx:project_opened"
},
{
"command": "sfdx.force.diff",
"command": "sfdx.diff",
"when": "!explorerResourceIsFolder && sfdx:project_opened && resourceLangId != 'forcesourcemanifest' && sfdx:has_default_username"
},
{
Expand Down Expand Up @@ -588,19 +588,19 @@
"when": "false"
},
{
"command": "sfdx.force.diff",
"command": "sfdx.diff",
"when": "false"
},
{
"command": "sfdx.force.folder.diff",
"command": "sfdx.folder.diff",
"when": "false"
},
{
"command": "sfdx.force.conflict.open",
"when": "false"
},
{
"command": "sfdx.force.internal.refreshsobjects",
"command": "sfdx.internal.refreshsobjects",
"when": "sfdx:project_opened && sfdx:has_default_username"
},
{
Expand Down Expand Up @@ -887,12 +887,12 @@
"title": "%project_generate_manifest%"
},
{
"command": "sfdx.force.diff",
"title": "%force_diff_against_org%"
"command": "sfdx.diff",
"title": "%diff_against_org%"
},
{
"command": "sfdx.force.folder.diff",
"title": "%force_diff_folder_against_org%"
"command": "sfdx.folder.diff",
"title": "%diff_folder_against_org%"
},
{
"command": "sfdx.force.conflict.open",
Expand All @@ -903,8 +903,8 @@
}
},
{
"command": "sfdx.force.internal.refreshsobjects",
"title": "%force_sobjects_refresh%"
"command": "sfdx.internal.refreshsobjects",
"title": "%sobjects_refresh%"
},
{
"command": "sfdx.force.launch.apex.replay.debugger.with.current.file",
Expand Down
6 changes: 3 additions & 3 deletions packages/salesforcedx-vscode-core/package.nls.ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
"delete_source_this_source_text": "SFDX: このソースをプロジェクトと組織から削除",
"enable_sobject_refresh_on_startup_description": "プロジェクトに sObject 定義がない場合、拡張機能が有効化される際に自動的に sObject 定義を更新するかどうかを指定します。",
"org_login_access_token_text": "SFDX: Authorize an Org using Session ID",
"force_diff_against_org": "SFDX: ファイルと組織の差分を表示",
"force_diff_folder_against_org": "SFDX: フォルダと組織の差分を表示",
"diff_against_org": "SFDX: ファイルと組織の差分を表示",
"diff_folder_against_org": "SFDX: フォルダと組織の差分を表示",
"force_lightning_lwc_test_create_text": "SFDX: Lightning Web コンポーネントのテストを作成",
"force_manifest_editor_show_text": "SFDX: パッケージマニフェストエディタを表示",
"force_package_install_text": "SFDX: パッケージをインストール",
"force_sobjects_refresh": "SFDX: SObject 定義を更新",
"sobjects_refresh": "SFDX: SObject 定義を更新",
"force_source_deploy_in_manifest_text": "SFDX: マニフェストファイルのソースを組織へデプロイ",
"force_source_deploy_text": "SFDX: 組織へソースをデプロイ",
"force_source_deploy_this_source_text": "SFDX: このソースを組織へデプロイ",
Expand Down
6 changes: 3 additions & 3 deletions packages/salesforcedx-vscode-core/package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@
"enable_source_tracking_for_deploy_and_retrieve": "Specifies whether source-tracking is enabled for deploy or retrieve operations in a source-tracked org. Disable source-tracking if you are experiencing performance issues using deploy or retrieve commands on your source-tracked orgs.",
"org_login_access_token_text": "SFDX: Authorize an Org using Session ID",
"project_generate_manifest": "SFDX: Generate Manifest File",
"force_diff_against_org": "SFDX: Diff File Against Org",
"force_diff_folder_against_org": "SFDX: Diff Folder Against Org",
"diff_against_org": "SFDX: Diff File Against Org",
"diff_folder_against_org": "SFDX: Diff Folder Against Org",
"force_launch_apex_replay_debugger_with_current_file": "SFDX: Launch Apex Replay Debugger with Current File",
"force_lightning_lwc_test_create_text": "SFDX: Create Lightning Web Component Test",
"rename_lightning_component_text": "SFDX: Rename Component",
"force_manifest_editor_show_text": "SFDX: Show Package Manifest Editor",
"force_package_install_text": "SFDX: Install Package",
"force_sobjects_refresh": "SFDX: Refresh SObject Definitions",
"sobjects_refresh": "SFDX: Refresh SObject Definitions",
"force_source_deploy_in_manifest_text": "SFDX: Deploy Source in Manifest to Org",
"force_source_deploy_text": "SFDX: Deploy Source to Org",
"force_source_deploy_this_source_text": "SFDX: Deploy This Source to Org",
Expand Down
12 changes: 4 additions & 8 deletions packages/salesforcedx-vscode-core/src/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,22 +60,18 @@ export {
forcePackageInstall
} from './forcePackageInstall';
export {
ForceRefreshSObjectsExecutor,
RefreshSObjectsExecutor,
checkSObjectsAndRefresh,
forceRefreshSObjects,
refreshSObjects,
initSObjectDefinitions
} from './forceRefreshSObjects';
} from './refreshSObjects';
export { renameLightningComponent } from './renameLightningComponent';
export { forceSourceDeployManifest } from './forceSourceDeployManifest';
export {
LibraryDeploySourcePathExecutor,
forceSourceDeploySourcePaths
} from './forceSourceDeploySourcePath';
export {
forceSourceDiff,
forceSourceFolderDiff,
handleCacheResults
} from './forceSourceDiff';
export { sourceDiff, sourceFolderDiff, handleCacheResults } from './sourceDiff';
export { forceSourceRetrieveManifest } from './forceSourceRetrieveManifest';
export { forceSourceRetrieveCmp } from './forceSourceRetrieveMetadata';
export {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ export type RefreshSelection = {
};

export class SObjectRefreshGatherer
implements ParametersGatherer<RefreshSelection> {
implements ParametersGatherer<RefreshSelection>
{
private source?: SObjectRefreshSource;

public constructor(source?: SObjectRefreshSource) {
Expand Down Expand Up @@ -82,12 +83,12 @@ export class SObjectRefreshGatherer
}
}

export class ForceRefreshSObjectsExecutor extends SfdxCommandletExecutor<{}> {
export class RefreshSObjectsExecutor extends SfdxCommandletExecutor<{}> {
private static isActive = false;
// eslint-disable-next-line @typescript-eslint/no-unused-vars
public build(data: {}): Command {
return new SfdxCommandBuilder()
.withDescription(nls.localize('force_sobjects_refresh'))
.withDescription(nls.localize('sobjects_refresh'))
.withArg('sobject definitions refresh')
.withLogName('force_generate_faux_classes_create')
.build();
Expand All @@ -96,14 +97,14 @@ export class ForceRefreshSObjectsExecutor extends SfdxCommandletExecutor<{}> {
public async execute(
response: ContinueResponse<RefreshSelection>
): Promise<void> {
if (ForceRefreshSObjectsExecutor.isActive) {
vscode.window.showErrorMessage(
nls.localize('force_sobjects_no_refresh_if_already_active_error_text')
if (RefreshSObjectsExecutor.isActive) {
await vscode.window.showErrorMessage(
nls.localize('sobjects_no_refresh_if_already_active_error_text')
);
return;
}
const startTime = process.hrtime();
ForceRefreshSObjectsExecutor.isActive = true;
RefreshSObjectsExecutor.isActive = true;
const cancellationTokenSource = new vscode.CancellationTokenSource();
const cancellationToken = cancellationTokenSource.token;
const execution = new LocalCommandExecution(this.build(response.data));
Expand Down Expand Up @@ -169,31 +170,31 @@ export class ForceRefreshSObjectsExecutor extends SfdxCommandletExecutor<{}> {
} catch (error) {
console.log('Generate error ' + error.error);
telemetryService.sendException(error.name, error.error);
ForceRefreshSObjectsExecutor.isActive = false;
RefreshSObjectsExecutor.isActive = false;

throw error;
}

ForceRefreshSObjectsExecutor.isActive = false;
RefreshSObjectsExecutor.isActive = false;
return;
}
}

const workspaceChecker = new SfdxWorkspaceChecker();

export async function forceRefreshSObjects(source?: SObjectRefreshSource) {
export const refreshSObjects = async (source?: SObjectRefreshSource) => {
const parameterGatherer = new SObjectRefreshGatherer(source);
const commandlet = new SfdxCommandlet(
workspaceChecker,
parameterGatherer,
new ForceRefreshSObjectsExecutor()
new RefreshSObjectsExecutor()
);
await commandlet.run();
}
};

export async function verifyUsernameAndInitSObjectDefinitions(
export const verifyUsernameAndInitSObjectDefinitions = async (
projectPath: string
) {
) => {
const hasDefaultUsernameSet =
(await WorkspaceContext.getInstance().getConnection()).getUsername() !==
undefined;
Expand All @@ -202,9 +203,9 @@ export async function verifyUsernameAndInitSObjectDefinitions(
telemetryService.sendException(e.name, e.message)
);
}
}
};

export async function initSObjectDefinitions(projectPath: string) {
export const initSObjectDefinitions = async (projectPath: string) => {
if (projectPath) {
const sobjectFolder = getSObjectsDirectory();
if (!fs.existsSync(sobjectFolder)) {
Expand All @@ -213,37 +214,40 @@ export async function initSObjectDefinitions(projectPath: string) {
{ type: SObjectRefreshSource.Startup },
undefined
);
forceRefreshSObjects(SObjectRefreshSource.Startup).catch(e => {
try {
await refreshSObjects(SObjectRefreshSource.Startup);
} catch (e) {
telemetryService.sendException(e.name, e.message);
throw e;
});
}
}
}
}
};

function getSObjectsDirectory() {
const getSObjectsDirectory = () => {
return path.join(projectPaths.toolsFolder(), SOBJECTS_DIR);
}
};

function getStandardSObjectsDirectory() {
const getStandardSObjectsDirectory = () => {
return path.join(
projectPaths.toolsFolder(),
SOBJECTS_DIR,
STANDARDOBJECTS_DIR
);
}
};

export async function checkSObjectsAndRefresh(projectPath: string) {
export const checkSObjectsAndRefresh = async (projectPath: string) => {
if (projectPath && !fs.existsSync(getStandardSObjectsDirectory())) {
telemetryService.sendEventData(
'sObjectRefreshNotification',
{ type: SObjectRefreshSource.StartupMin },
undefined
);
try {
await forceRefreshSObjects(SObjectRefreshSource.StartupMin);
await refreshSObjects(SObjectRefreshSource.StartupMin);
} catch (e) {
telemetryService.sendException(e.name, e.message);
throw e;
}
}
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ import { FilePathGatherer, SfdxCommandlet, SfdxWorkspaceChecker } from './util';

const workspaceChecker = new SfdxWorkspaceChecker();

export async function forceSourceDiff(sourceUri?: vscode.Uri) {
export const sourceDiff = async (sourceUri?: vscode.Uri) => {
if (!sourceUri) {
const editor = vscode.window.activeTextEditor;
if (editor && editor.document.languageId !== 'forcesourcemanifest') {
sourceUri = editor.document.uri;
} else {
const errorMessage = nls.localize('force_source_diff_unsupported_type');
const errorMessage = nls.localize('source_diff_unsupported_type');
telemetryService.sendException('unsupported_type_on_diff', errorMessage);
notificationService.showErrorMessage(errorMessage);
await notificationService.showErrorMessage(errorMessage);
Copy link
Contributor

Choose a reason for hiding this comment

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

same here

channelService.appendLine(errorMessage);
channelService.showChannelOutput();
return;
Expand All @@ -38,13 +38,15 @@ export async function forceSourceDiff(sourceUri?: vscode.Uri) {

const defaultUsernameorAlias = WorkspaceContext.getInstance().username;
if (!defaultUsernameorAlias) {
notificationService.showErrorMessage(nls.localize('missing_default_org'));
await notificationService.showErrorMessage(
Copy link
Contributor

Choose a reason for hiding this comment

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

and here

nls.localize('missing_default_org')
);
return;
}
const executor = new MetadataCacheExecutor(
defaultUsernameorAlias,
nls.localize('force_source_diff_text'),
'force_source_diff',
nls.localize('source_diff_text'),
'source_diff',
handleCacheResults
);
const commandlet = new SfdxCommandlet(
Expand All @@ -53,17 +55,17 @@ export async function forceSourceDiff(sourceUri?: vscode.Uri) {
executor
);
await commandlet.run();
}
};

export async function forceSourceFolderDiff(explorerPath: vscode.Uri) {
export const sourceFolderDiff = async (explorerPath: vscode.Uri) => {
if (!explorerPath) {
const editor = vscode.window.activeTextEditor;
if (editor && editor.document.languageId !== 'forcesourcemanifest') {
explorerPath = editor.document.uri;
} else {
const errorMessage = nls.localize('force_source_diff_unsupported_type');
const errorMessage = nls.localize('source_diff_unsupported_type');
telemetryService.sendException('unsupported_type_on_diff', errorMessage);
notificationService.showErrorMessage(errorMessage);
await notificationService.showErrorMessage(errorMessage);
Copy link
Contributor

Choose a reason for hiding this comment

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

and here

channelService.appendLine(errorMessage);
channelService.showChannelOutput();
return;
Expand All @@ -72,7 +74,9 @@ export async function forceSourceFolderDiff(explorerPath: vscode.Uri) {

const username = WorkspaceContext.getInstance().username;
if (!username) {
notificationService.showErrorMessage(nls.localize('missing_default_org'));
await notificationService.showErrorMessage(
Copy link
Contributor

Choose a reason for hiding this comment

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

and here (?

nls.localize('missing_default_org')
);
return;
}

Expand All @@ -87,12 +91,12 @@ export async function forceSourceFolderDiff(explorerPath: vscode.Uri) {
)
);
await commandlet.run();
}
};

export async function handleCacheResults(
export const handleCacheResults = async (
username: string,
cache?: MetadataCacheResult
): Promise<void> {
): Promise<void> => {
if (cache) {
if (cache.selectedType === PathType.Individual && cache.cache.components) {
await differ.diffOneFile(
Expand All @@ -104,8 +108,8 @@ export async function handleCacheResults(
await differ.diffFolder(cache, username);
}
} else {
const message = nls.localize('force_source_diff_components_not_in_org');
notificationService.showErrorMessage(message);
const message = nls.localize('source_diff_components_not_in_org');
await notificationService.showErrorMessage(message);
throw new Error(message);
}
}
};
Loading
Loading