From c8c82da10577f318b163cfbc638364bfdad29b76 Mon Sep 17 00:00:00 2001 From: mingxuanzhang Date: Tue, 3 Dec 2024 16:18:03 -0800 Subject: [PATCH] feat: add distinct configs for apex action and general oas eligibility --- .../salesforcedx-vscode-apex/package.json | 27 +++++++++ .../package.nls.ja.json | 1 + .../salesforcedx-vscode-apex/package.nls.json | 3 + .../src/languageServer.ts | 28 ++++++--- .../salesforcedx-vscode-apex/src/settings.ts | 60 ++++++++++++++++--- 5 files changed, 103 insertions(+), 16 deletions(-) diff --git a/packages/salesforcedx-vscode-apex/package.json b/packages/salesforcedx-vscode-apex/package.json index 4e5244f74d..7f40858243 100644 --- a/packages/salesforcedx-vscode-apex/package.json +++ b/packages/salesforcedx-vscode-apex/package.json @@ -419,6 +419,33 @@ "type": "boolean", "default": false, "description": "%apex_code_disable-warnings-for-missing-coverage%" + }, + "salesforcedx-vscode-apex.apexoas.general.class.access-modifiers": { + "type":"array", + "items": { + "type":"string", + "enum": ["global", "public"] + }, + "default": ["global", "public"], + "description": "%apex_oas_general_class_access-modifiers%" + }, + "salesforcedx-vscode-apex.apexoas.general.method.access-modifiers": { + "type":"array", + "items": { + "type":"string", + "enum": ["global", "public"] + }, + "default": ["global", "public"], + "description": "%apex_oas_general_method_access-modifiers%" + }, + "salesforcedx-vscode-apex.apexoas.general.property.access-modifiers": { + "type":"array", + "items": { + "type":"string", + "enum": ["global", "public"] + }, + "default": ["global", "public"], + "description": "%apex_oas_general_property_access-modifiers%" } } }, diff --git a/packages/salesforcedx-vscode-apex/package.nls.ja.json b/packages/salesforcedx-vscode-apex/package.nls.ja.json index 1293c8fa50..205af16c70 100644 --- a/packages/salesforcedx-vscode-apex/package.nls.ja.json +++ b/packages/salesforcedx-vscode-apex/package.nls.ja.json @@ -3,6 +3,7 @@ "anon_apex_execute_selection_text": "SFDX: 現在選択されているテキストを使用して匿名 Apex を実行", "apex_code_completion_stats_description": "Allow the Apex Language Server to collect telemetry on code completion usage", "apex_code_disable-warnings-for-missing-coverage": "Disable UI warning when Apex test coverage is missing.", + "apex_oas_general_class_access-modifiers": "The general eligibility of class access modifiers for the generation of Apex Open API specifications.", "apex_log_get_text": "SFDX: Apex デバッグログを取得", "apex_messages_level_trace_description": "Only output high-level messages of notifications and responses received by the client, and requests sent by the server.", "apex_off_level_trace_description": "Don't generate any output. Turn off all tracing.", diff --git a/packages/salesforcedx-vscode-apex/package.nls.json b/packages/salesforcedx-vscode-apex/package.nls.json index 7e38d3a02c..c8964c83bc 100644 --- a/packages/salesforcedx-vscode-apex/package.nls.json +++ b/packages/salesforcedx-vscode-apex/package.nls.json @@ -5,6 +5,9 @@ "apex_code_disable-warnings-for-missing-coverage": "Disable UI warning when Apex test coverage is missing.", "apex_log_get_text": "SFDX: Get Apex Debug Logs", "apex_messages_level_trace_description": "Only output high-level messages of notifications and responses received by the client, and requests sent by the server.", + "apex_oas_general_class_access-modifiers": "The general eligibility of class access modifiers for the generation of Apex Open API Specs.", + "apex_oas_general_method_access-modifiers": "The general eligibility of method access modifiers for the generation of Apex Open API Specs.", + "apex_oas_general_property_access-modifiers": "The general eligibility of property access modifiers for the generation of Apex Open API Specs.", "apex_off_level_trace_description": "Don't generate any output. Turn off all tracing.", "apex_semantic_errors_description": "Allow Apex Language Server to surface semantic errors", "apex_test_last_method_run_text": "SFDX: Re-Run Last Run Apex Test Method", diff --git a/packages/salesforcedx-vscode-apex/src/languageServer.ts b/packages/salesforcedx-vscode-apex/src/languageServer.ts index 7eaf8d5758..02bd7b7bb5 100644 --- a/packages/salesforcedx-vscode-apex/src/languageServer.ts +++ b/packages/salesforcedx-vscode-apex/src/languageServer.ts @@ -15,11 +15,17 @@ import { soqlMiddleware } from './embeddedSoql'; import { nls } from './messages'; import * as requirements from './requirements'; import { - retrieveClassAccessModifiers, - retrieveClassDefinitionModifiers, retrieveEnableSyncInitJobs, - retrieveMethodAndPropertyAnnotations, - retrieveMethodAndPropertyModifiers + retrieveAAClassDefModifiers, + retrieveAAClassAccessModifiers, + retrieveAAMethodDefModifiers, + retrieveAAMethodAccessModifiers, + retrieveAAPropDefModifiers, + retrieveAAPropAccessModifiers, + retrieveAAAnnotations, + retrieveGeneralClassAccessModifiers, + retrieveGeneralMethodAccessModifiers, + retrieveGeneralPropAccessModifiers } from './settings'; import { getTelemetryService } from './telemetry/telemetry'; @@ -158,10 +164,16 @@ export const buildClientOptions = (): LanguageClientOptions => { initializationOptions: { enableEmbeddedSoqlCompletion: soqlExtensionInstalled, enableSynchronizedInitJobs: retrieveEnableSyncInitJobs(), - apexOASClassAccessModifiers: retrieveClassAccessModifiers().join(','), - apexOASClassDefinitionModifiers: retrieveClassDefinitionModifiers().join(','), - apexOASMethodAndPropertyModifiers: retrieveMethodAndPropertyModifiers().join(','), - apexOASMethodAndPropertyAnnotations: retrieveMethodAndPropertyAnnotations().join(',') + apexActionClassDefModifiers: retrieveAAClassDefModifiers().join(','), + apexActionClassAccessModifiers: retrieveAAClassAccessModifiers().join(','), + apexActionMethodDefModifiers: retrieveAAMethodDefModifiers().join(','), + apexActionMethodAccessModifiers: retrieveAAMethodAccessModifiers().join(','), + apexActionPropDefModifiers: retrieveAAPropDefModifiers().join(','), + apexActionPropAccessModifiers: retrieveAAPropAccessModifiers().join(','), + apexActionAnnotations: retrieveAAAnnotations().join(','), + apexOASClassAccessModifiers: retrieveGeneralClassAccessModifiers().join(','), + apexOASMethodAccessModifiers: retrieveGeneralMethodAccessModifiers().join(','), + apexOASPropAccessModifiers: retrieveGeneralPropAccessModifiers().join(',') }, ...(soqlExtensionInstalled ? { middleware: soqlMiddleware } : {}), errorHandler: new ApexErrorHandler() diff --git a/packages/salesforcedx-vscode-apex/src/settings.ts b/packages/salesforcedx-vscode-apex/src/settings.ts index c56f531763..90da0ffe81 100644 --- a/packages/salesforcedx-vscode-apex/src/settings.ts +++ b/packages/salesforcedx-vscode-apex/src/settings.ts @@ -8,6 +8,20 @@ import { SFDX_CORE_CONFIGURATION_NAME } from '@salesforce/salesforcedx-utils-vscode'; import * as vscode from 'vscode'; +// Eligibility for apex action ONLY, should not be changed by users unless overwriting in settings.json +const APEX_ACTION_CLASS_DEF_MODIFIERS = ['withsharing']; +const APEX_ACTION_CLASS_ACCESS_MODIFIERS = ['global', 'public']; +const APEX_ACTION_METHOD_DEF_MODIFIERS = ['static']; +const APEX_ACTION_METHOD_ACCESS_MODIFIERS = ['global', 'public']; +const APEX_ACTION_PROP_DEF_MODIFIERS = ['static']; +const APEX_ACTION_PROP_ACCESS_MODIFIERS = ['global', 'public']; +const APEX_ACTION_ANNOTATIONS = ['AuraEnabled', 'RestResource']; + +// Default eligibility for general OAS generation. Users can changed the setting through VSCode configurations +const DEFAULT_CLASS_ACCESS_MODIFIERS = ['global', 'public']; +const DEFAULT_METHOD_ACCESS_MODIFIERS = ['global', 'public']; +const DEFAULT_PROP_ACCESS_MODIFIERS = ['global', 'public']; + export const retrieveTestCodeCoverage = (): boolean => { return vscode.workspace .getConfiguration(SFDX_CORE_CONFIGURATION_NAME) @@ -21,22 +35,52 @@ export const retrieveEnableSyncInitJobs = (): boolean => { // Configurations of the definitions of eligible apex classes/methods/properties // We want to lock the eligibility criteria for apexoas, so we do not expose the settings to customer // But we can still modify the config through settings.json -export const retrieveClassAccessModifiers = (): string[] => +export const retrieveAAClassDefModifiers = (): string[] => + vscode.workspace + .getConfiguration() + .get('salesforcedx-vscode-apex.apexoas.aa.class.definition-modifiers', APEX_ACTION_CLASS_DEF_MODIFIERS); + +export const retrieveAAClassAccessModifiers = (): string[] => + vscode.workspace + .getConfiguration() + .get('salesforcedx-vscode-apex.apexoas.aa.class.access-modifiers', APEX_ACTION_CLASS_ACCESS_MODIFIERS); + +export const retrieveAAMethodDefModifiers = (): string[] => + vscode.workspace + .getConfiguration() + .get('salesforcedx-vscode-apex.apexoas.aa.method.definition-modifiers', APEX_ACTION_METHOD_DEF_MODIFIERS); + +export const retrieveAAMethodAccessModifiers = (): string[] => + vscode.workspace + .getConfiguration() + .get('salesforcedx-vscode-apex.apexoas.aa.method.access-modifiers', APEX_ACTION_METHOD_ACCESS_MODIFIERS); + +export const retrieveAAPropDefModifiers = (): string[] => + vscode.workspace + .getConfiguration() + .get('salesforcedx-vscode-apex.apexoas.aa.prop.definition-modifiers', APEX_ACTION_PROP_DEF_MODIFIERS); + +export const retrieveAAPropAccessModifiers = (): string[] => + vscode.workspace + .getConfiguration() + .get('salesforcedx-vscode-apex.apexoas.aa.prop.definition-modifiers', APEX_ACTION_PROP_ACCESS_MODIFIERS); + +export const retrieveAAAnnotations = (): string[] => vscode.workspace .getConfiguration() - .get('salesforcsalesforcedx-vscode-apex.apexoas.eligibility.class.access-modifiers', ['public']); + .get('salesforcedx-vscode-apex.apexoas.aa.annotations', APEX_ACTION_ANNOTATIONS); -export const retrieveClassDefinitionModifiers = (): string[] => +export const retrieveGeneralClassAccessModifiers = (): string[] => vscode.workspace .getConfiguration() - .get('salesforcsalesforcedx-vscode-apex.apexoas.eligibility.class.definition-modifiers', ['withsharing']); + .get('salesforcedx-vscode-apex.apexoas.general.class.access-modifiers', DEFAULT_CLASS_ACCESS_MODIFIERS); -export const retrieveMethodAndPropertyModifiers = (): string[] => +export const retrieveGeneralMethodAccessModifiers = (): string[] => vscode.workspace .getConfiguration() - .get('salesforcedx-vscode-apex.apexoas.eligibility.method.modifiers', ['global', 'public']); + .get('salesforcedx-vscode-apex.apexoas.general.method.access-modifiers', DEFAULT_METHOD_ACCESS_MODIFIERS); -export const retrieveMethodAndPropertyAnnotations = (): string[] => +export const retrieveGeneralPropAccessModifiers = (): string[] => vscode.workspace .getConfiguration() - .get('salesforcedx-vscode-apex.apexoas.eligibility.method.annotations', ['AuraEnabled', 'RestResource']); + .get('salesforcedx-vscode-apex.apexoas.general.prop.access-modifiers', DEFAULT_PROP_ACCESS_MODIFIERS);