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

W-17260440 - feat: gather context #5988

Merged
merged 10 commits into from
Jan 2, 2025
Binary file modified packages/salesforcedx-vscode-apex/out/apex-jorje-lsp.jar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +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 { AiApiClient, CommandSource, ServiceProvider, ServiceType } from '@salesforce/vscode-service-provider';

Check failure on line 7 in packages/salesforcedx-vscode-apex/src/commands/metadataOrchestrator.ts

View workflow job for this annotation

GitHub Actions / build-and-test / build-all / build-all

Module '"@salesforce/vscode-service-provider"' has no exported member 'AiApiClient'.

Check failure on line 7 in packages/salesforcedx-vscode-apex/src/commands/metadataOrchestrator.ts

View workflow job for this annotation

GitHub Actions / build-and-test / build-all / build-all

Module '"@salesforce/vscode-service-provider"' has no exported member 'CommandSource'.

Check failure on line 7 in packages/salesforcedx-vscode-apex/src/commands/metadataOrchestrator.ts

View workflow job for this annotation

GitHub Actions / build-and-test / unit-tests / windows-unit-tests / windows-unit-tests

Module '"@salesforce/vscode-service-provider"' has no exported member 'AiApiClient'.

Check failure on line 7 in packages/salesforcedx-vscode-apex/src/commands/metadataOrchestrator.ts

View workflow job for this annotation

GitHub Actions / build-and-test / unit-tests / windows-unit-tests / windows-unit-tests

Module '"@salesforce/vscode-service-provider"' has no exported member 'CommandSource'.

Check failure on line 7 in packages/salesforcedx-vscode-apex/src/commands/metadataOrchestrator.ts

View workflow job for this annotation

GitHub Actions / build-and-test / unit-tests / linux-unit-tests / linux-unit-tests

Module '"@salesforce/vscode-service-provider"' has no exported member 'AiApiClient'.

Check failure on line 7 in packages/salesforcedx-vscode-apex/src/commands/metadataOrchestrator.ts

View workflow job for this annotation

GitHub Actions / build-and-test / unit-tests / linux-unit-tests / linux-unit-tests

Module '"@salesforce/vscode-service-provider"' has no exported member 'CommandSource'.
import * as path from 'path';
import * as vscode from 'vscode';
import { languageClientUtils } from '../languageUtils';
Expand Down Expand Up @@ -98,6 +98,26 @@
return response;
};

public gatherContext = async (
sourceUri: vscode.Uri | vscode.Uri[]
): Promise<ApexClassOASEligibleResponses | undefined> => {
const telemetryService = await getTelemetryService();
let response;
const languageClient = languageClientUtils.getClientInstance();
if (languageClient) {
try {
response = (await languageClient?.sendRequest(
'apexoas/gatherContext',
sourceUri?.toString() ?? vscode.window.activeTextEditor?.document.uri.toString()
)) as ApexClassOASEligibleResponses;
} catch (error) {
// fallback TBD after we understand it better
throw new Error(nls.localize('cannot_gather_context'));
}
}
return response;
};

public validateEligibility = async (
sourceUri: vscode.Uri | vscode.Uri[],
isMethodSelected: boolean = false
Expand Down Expand Up @@ -140,6 +160,7 @@
requests.push(request);
}

const response = this.gatherContext(sourceUri);
Copy link
Contributor

Choose a reason for hiding this comment

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

@CristiCanizales I was thinking that context gathering would occur after eligibility is determined and the class is eligible for generation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes! Right now it's just like a placeholder so we can play with the response when doing prompt engineering

const responses = await this.eligibilityDelegate({ payload: requests });
return responses;
};
Expand Down Expand Up @@ -203,6 +224,6 @@
};

getAiApiClient = async (): Promise<AiApiClient> => {
return ServiceProvider.getService(ServiceType.AiApiClient);

Check failure on line 227 in packages/salesforcedx-vscode-apex/src/commands/metadataOrchestrator.ts

View workflow job for this annotation

GitHub Actions / build-and-test / build-all / build-all

Property 'AiApiClient' does not exist on type 'typeof ServiceType'.

Check failure on line 227 in packages/salesforcedx-vscode-apex/src/commands/metadataOrchestrator.ts

View workflow job for this annotation

GitHub Actions / build-and-test / unit-tests / windows-unit-tests / windows-unit-tests

Property 'AiApiClient' does not exist on type 'typeof ServiceType'.

Check failure on line 227 in packages/salesforcedx-vscode-apex/src/commands/metadataOrchestrator.ts

View workflow job for this annotation

GitHub Actions / build-and-test / unit-tests / linux-unit-tests / linux-unit-tests

Property 'AiApiClient' does not exist on type 'typeof ServiceType'.
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export const messages = {
'Method %s is not eligible for Apex Action creation. It is not annotated with @AuraEnabled or has wrong access modifiers.',
unknown: 'Unknown',
invalid_active_text_editor: 'The active text editor is missing or is an invalid file.',
cannot_gather_context: 'An error occurred while gathering context for the Apex class.',
sobjects_no_refresh_if_already_active_error_text:
'sObject 定義の更新が既に実行中です。プロセスを再起動する必要がある場合は、実行中のタスクをキャンセルしてください。',
test_view_loading_message: 'Apex テストを読み込んでいます...',
Expand Down
3 changes: 2 additions & 1 deletion packages/salesforcedx-vscode-apex/src/messages/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,5 +106,6 @@ export const messages = {
orphan_process_advice:
"The list of processes below are Apex Language Server instances that didn't properly shutdown. These\nprocesses can be stopped from the warning message that brought you here, or you can handle this\ntask yourself. If you choose to terminate these processes yourself, refer to relevant documentation\nto stop these processes.",
unknown: 'Unknown',
invalid_active_text_editor: 'The active text editor is missing or is an invalid file.'
invalid_active_text_editor: 'The active text editor is missing or is an invalid file.',
cannot_gather_context: 'An error occurred while gathering context for the Apex class.'
};
Loading