From ef50e1ea453d6e38749f2d4a9eca1e0e01c5f4c2 Mon Sep 17 00:00:00 2001 From: mingxuanzhang Date: Wed, 29 Jan 2025 21:12:42 -0800 Subject: [PATCH 1/2] feat: register command to notify a4d activated status --- packages/salesforcedx-vscode-apex/package.json | 10 +++++++--- .../salesforcedx-vscode-apex/package.nls.ja.json | 3 ++- packages/salesforcedx-vscode-apex/package.nls.json | 3 ++- packages/salesforcedx-vscode-apex/src/index.ts | 14 +++++++++++++- 4 files changed, 24 insertions(+), 6 deletions(-) diff --git a/packages/salesforcedx-vscode-apex/package.json b/packages/salesforcedx-vscode-apex/package.json index e3253ff166..2ebfe2e57d 100644 --- a/packages/salesforcedx-vscode-apex/package.json +++ b/packages/salesforcedx-vscode-apex/package.json @@ -135,13 +135,13 @@ }, { "command": "sf.create.apex.action.class", - "when": "sf:project_opened && sf:has_target_org && resource =~ /.\\.(cls)?$/" + "when": "sf:project_opened && sf:has_target_org && resource =~ /.\\.(cls)?$/ && sf:a4d_detected" } ], "explorer/context": [ { "command": "sf.create.apex.action.class", - "when": "sf:project_opened && sf:has_target_org && resource =~ /.\\.(cls)?$/ && resourcePath =~ /classes/" + "when": "sf:project_opened && sf:has_target_org && resource =~ /.\\.(cls)?$/ && resourcePath =~ /classes/ && sf:a4d_detected" } ], "view/title": [ @@ -260,7 +260,7 @@ }, { "command": "sf.create.apex.action.class", - "when": "sf:project_opened && sf:has_target_org && resource =~ /.\\.(cls)?$/ && resourcePath =~ /classes/" + "when": "sf:project_opened && sf:has_target_org && resource =~ /.\\.(cls)?$/ && resourcePath =~ /classes/ && sf:a4d_detected" } ] }, @@ -372,6 +372,10 @@ { "command": "sf.create.apex.action.class", "title": "%create_openapi_doc_class%" + }, + { + "command": "sf.a4d.notify.activated", + "title": "%a4d_notify_activated%" } ], "configuration": { diff --git a/packages/salesforcedx-vscode-apex/package.nls.ja.json b/packages/salesforcedx-vscode-apex/package.nls.ja.json index 9ed54f3339..6c68904b00 100644 --- a/packages/salesforcedx-vscode-apex/package.nls.ja.json +++ b/packages/salesforcedx-vscode-apex/package.nls.ja.json @@ -30,5 +30,6 @@ "run_tests_title": "テストを実行", "show_error_title": "エラーを表示", "test_view_container_title": "テストビューア", - "test_view_name": "Apex テスト" + "test_view_name": "Apex テスト", + "a4d_notify_activated": "Agentforce for Developer is activated." } diff --git a/packages/salesforcedx-vscode-apex/package.nls.json b/packages/salesforcedx-vscode-apex/package.nls.json index a4b312ad5e..9e7a25f149 100644 --- a/packages/salesforcedx-vscode-apex/package.nls.json +++ b/packages/salesforcedx-vscode-apex/package.nls.json @@ -33,5 +33,6 @@ "run_tests_title": "Run Tests", "show_error_title": "Display Error", "test_view_container_title": "Test Viewer", - "test_view_name": "Apex Tests" + "test_view_name": "Apex Tests", + "a4d_notify_activated": "Agentforce for Developer is activated." } diff --git a/packages/salesforcedx-vscode-apex/src/index.ts b/packages/salesforcedx-vscode-apex/src/index.ts index f3fcf3c908..6e75e1377c 100644 --- a/packages/salesforcedx-vscode-apex/src/index.ts +++ b/packages/salesforcedx-vscode-apex/src/index.ts @@ -54,6 +54,14 @@ import { ApexTestRunner, TestRunType } from './views/testRunner'; const metadataOrchestrator = new MetadataOrchestrator(); export const apexActionController = new ApexActionController(metadataOrchestrator); +const onA4DExtensionActivated = () => { + setA4dActivatedContext(true); +}; + +const setA4dActivatedContext = (val: boolean) => { + vscode.commands.executeCommand('setContext', 'sf:a4d_detected', val); +}; + export const activate = async (extensionContext: vscode.ExtensionContext) => { const telemetryService = await getTelemetryService(); if (!telemetryService) { @@ -175,6 +183,9 @@ const registerCommands = (): vscode.Disposable => { 'sf.launch.apex.replay.debugger.with.current.file', launchApexReplayDebuggerWithCurrentFile ); + const notifyA4DExtensionActivated = vscode.commands.registerCommand('sf.notify.a4d.extension.activated', () => + onA4DExtensionActivated() + ); // the command is only used by the a4d extension to notify us that it has been activated return vscode.Disposable.from( anonApexDebugDelegateCmd, @@ -198,7 +209,8 @@ const registerCommands = (): vscode.Disposable => { apexTestSuiteAddCmd, createApexActionFromMethodCmd, createApexActionFromClassCmd, - launchApexReplayDebuggerWithCurrentFileCmd + launchApexReplayDebuggerWithCurrentFileCmd, + notifyA4DExtensionActivated ); }; From 6495a13623e44f86b772ee2015bd87861b49e235 Mon Sep 17 00:00:00 2001 From: mingxuanzhang Date: Thu, 30 Jan 2025 13:47:07 -0800 Subject: [PATCH 2/2] feat: register command for a4d deactivated notifying --- packages/salesforcedx-vscode-apex/src/index.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/salesforcedx-vscode-apex/src/index.ts b/packages/salesforcedx-vscode-apex/src/index.ts index 6e75e1377c..f74e2b3c71 100644 --- a/packages/salesforcedx-vscode-apex/src/index.ts +++ b/packages/salesforcedx-vscode-apex/src/index.ts @@ -58,6 +58,10 @@ const onA4DExtensionActivated = () => { setA4dActivatedContext(true); }; +const onA4DExtensionDeactivated = () => { + setA4dActivatedContext(false); +}; + const setA4dActivatedContext = (val: boolean) => { vscode.commands.executeCommand('setContext', 'sf:a4d_detected', val); }; @@ -187,6 +191,10 @@ const registerCommands = (): vscode.Disposable => { onA4DExtensionActivated() ); // the command is only used by the a4d extension to notify us that it has been activated + const notifyA4DExtensionDeactivated = vscode.commands.registerCommand('sf.notify.a4d.extension.deactivated', () => + onA4DExtensionDeactivated() + ); // the command is only used by the a4d extension to notify us that it has been deactivated + return vscode.Disposable.from( anonApexDebugDelegateCmd, anonApexDebugDocumentCmd, @@ -210,7 +218,8 @@ const registerCommands = (): vscode.Disposable => { createApexActionFromMethodCmd, createApexActionFromClassCmd, launchApexReplayDebuggerWithCurrentFileCmd, - notifyA4DExtensionActivated + notifyA4DExtensionActivated, + notifyA4DExtensionDeactivated ); };