Skip to content

Commit b0632c1

Browse files
committed
perf: update code to comments
1 parent 34515f1 commit b0632c1

2 files changed

Lines changed: 13 additions & 10 deletions

File tree

src/copilot/contextProvider.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ export async function registerCopilotContextProviders(
4141
}
4242
sendInfo("", {
4343
"action": "registerCopilotContextProvider",
44-
"extension": 'vscjava.vscode-java-dependency',
4544
"status": "succeeded",
4645
"installCount": installCount
4746
});
@@ -99,7 +98,7 @@ async function resolveJavaContext(request: ResolveRequest, copilotCancel: vscode
9998
JavaContextProviderUtils.checkCancellation(copilotCancel);
10099
// Resolve project dependencies and convert to context items
101100
const projectDependencyItems = await CopilotHelper.resolveAndConvertProjectDependencies(
102-
vscode.workspace.workspaceFolders,
101+
vscode.window.activeTextEditor,
103102
copilotCancel,
104103
JavaContextProviderUtils.checkCancellation
105104
);

src/copilot/copilotHelper.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export enum EmptyReason {
3030

3131
export interface INodeImportClass {
3232
uri: string;
33-
value: string; // Changed from 'class' to 'className' to match Java code
33+
value: string;
3434
}
3535

3636
export interface IImportClassContentResult {
@@ -175,7 +175,7 @@ export namespace CopilotHelper {
175175
* @returns Result object containing project dependencies and error information
176176
*/
177177
export async function resolveProjectDependenciesWithReason(
178-
projectUri: Uri,
178+
fileUri: Uri,
179179
cancellationToken?: CancellationToken
180180
): Promise<IProjectDependenciesResult> {
181181
if (cancellationToken?.isCancellationRequested) {
@@ -187,7 +187,7 @@ export namespace CopilotHelper {
187187
}
188188

189189
try {
190-
const normalizedUri = decodeURIComponent(Uri.file(projectUri.fsPath).toString());
190+
const normalizedUri = decodeURIComponent(Uri.file(fileUri.fsPath).toString());
191191
const commandPromise = commands.executeCommand(
192192
Commands.EXECUTE_WORKSPACE_COMMAND,
193193
Commands.JAVA_PROJECT_GET_DEPENDENCIES,
@@ -267,20 +267,24 @@ export namespace CopilotHelper {
267267
* @returns Array of context items for project dependencies, or empty array if no workspace folders
268268
*/
269269
export async function resolveAndConvertProjectDependencies(
270-
workspaceFolders: readonly { uri: Uri }[] | undefined,
270+
activeEditor: { document: { uri: Uri; languageId: string } } | undefined,
271271
copilotCancel: CancellationToken,
272272
checkCancellation: (token: CancellationToken) => void
273273
): Promise<{ name: string; value: string; importance: number }[]> {
274274
const items: any[] = [];
275275
// Check if workspace folders exist
276-
if (!workspaceFolders || workspaceFolders.length === 0) {
277-
sendContextOperationTelemetry("resolveProjectDependencies", "ContextEmpty", sendInfo, EmptyReason.NoWorkspace);
276+
if (!activeEditor) {
277+
sendContextOperationTelemetry("resolveLocalImports", "ContextEmpty", sendInfo, EmptyReason.NoActiveEditor);
278278
return items;
279279
}
280-
const projectUri = workspaceFolders[0];
280+
if (activeEditor.document.languageId !== 'java') {
281+
sendContextOperationTelemetry("resolveLocalImports", "ContextEmpty", sendInfo, EmptyReason.NotJavaFile);
282+
return items;
283+
}
284+
const documentUri = activeEditor.document.uri;
281285

282286
// Resolve project dependencies
283-
const projectDependenciesResult = await resolveProjectDependenciesWithReason(projectUri.uri, copilotCancel);
287+
const projectDependenciesResult = await resolveProjectDependenciesWithReason(documentUri, copilotCancel);
284288

285289
// Check for cancellation after dependency resolution
286290
checkCancellation(copilotCancel);

0 commit comments

Comments
 (0)