Skip to content

Commit

Permalink
feat: add distinct configs for apex action and general oas eligibility
Browse files Browse the repository at this point in the history
  • Loading branch information
mingxuanzhangsfdx committed Dec 4, 2024
1 parent 256b7f5 commit c8c82da
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 16 deletions.
27 changes: 27 additions & 0 deletions packages/salesforcedx-vscode-apex/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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%"
}
}
},
Expand Down
1 change: 1 addition & 0 deletions packages/salesforcedx-vscode-apex/package.nls.ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down
3 changes: 3 additions & 0 deletions packages/salesforcedx-vscode-apex/package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
28 changes: 20 additions & 8 deletions packages/salesforcedx-vscode-apex/src/languageServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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()
Expand Down
60 changes: 52 additions & 8 deletions packages/salesforcedx-vscode-apex/src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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<string[]>('salesforcedx-vscode-apex.apexoas.aa.class.definition-modifiers', APEX_ACTION_CLASS_DEF_MODIFIERS);

export const retrieveAAClassAccessModifiers = (): string[] =>
vscode.workspace
.getConfiguration()
.get<string[]>('salesforcedx-vscode-apex.apexoas.aa.class.access-modifiers', APEX_ACTION_CLASS_ACCESS_MODIFIERS);

export const retrieveAAMethodDefModifiers = (): string[] =>
vscode.workspace
.getConfiguration()
.get<string[]>('salesforcedx-vscode-apex.apexoas.aa.method.definition-modifiers', APEX_ACTION_METHOD_DEF_MODIFIERS);

export const retrieveAAMethodAccessModifiers = (): string[] =>
vscode.workspace
.getConfiguration()
.get<string[]>('salesforcedx-vscode-apex.apexoas.aa.method.access-modifiers', APEX_ACTION_METHOD_ACCESS_MODIFIERS);

export const retrieveAAPropDefModifiers = (): string[] =>
vscode.workspace
.getConfiguration()
.get<string[]>('salesforcedx-vscode-apex.apexoas.aa.prop.definition-modifiers', APEX_ACTION_PROP_DEF_MODIFIERS);

export const retrieveAAPropAccessModifiers = (): string[] =>
vscode.workspace
.getConfiguration()
.get<string[]>('salesforcedx-vscode-apex.apexoas.aa.prop.definition-modifiers', APEX_ACTION_PROP_ACCESS_MODIFIERS);

export const retrieveAAAnnotations = (): string[] =>
vscode.workspace
.getConfiguration()
.get<string[]>('salesforcsalesforcedx-vscode-apex.apexoas.eligibility.class.access-modifiers', ['public']);
.get<string[]>('salesforcedx-vscode-apex.apexoas.aa.annotations', APEX_ACTION_ANNOTATIONS);

export const retrieveClassDefinitionModifiers = (): string[] =>
export const retrieveGeneralClassAccessModifiers = (): string[] =>
vscode.workspace
.getConfiguration()
.get<string[]>('salesforcsalesforcedx-vscode-apex.apexoas.eligibility.class.definition-modifiers', ['withsharing']);
.get<string[]>('salesforcedx-vscode-apex.apexoas.general.class.access-modifiers', DEFAULT_CLASS_ACCESS_MODIFIERS);

export const retrieveMethodAndPropertyModifiers = (): string[] =>
export const retrieveGeneralMethodAccessModifiers = (): string[] =>
vscode.workspace
.getConfiguration()
.get<string[]>('salesforcedx-vscode-apex.apexoas.eligibility.method.modifiers', ['global', 'public']);
.get<string[]>('salesforcedx-vscode-apex.apexoas.general.method.access-modifiers', DEFAULT_METHOD_ACCESS_MODIFIERS);

export const retrieveMethodAndPropertyAnnotations = (): string[] =>
export const retrieveGeneralPropAccessModifiers = (): string[] =>
vscode.workspace
.getConfiguration()
.get<string[]>('salesforcedx-vscode-apex.apexoas.eligibility.method.annotations', ['AuraEnabled', 'RestResource']);
.get<string[]>('salesforcedx-vscode-apex.apexoas.general.prop.access-modifiers', DEFAULT_PROP_ACCESS_MODIFIERS);

0 comments on commit c8c82da

Please sign in to comment.