Skip to content

Commit ada72e1

Browse files
committed
style: fix format style
1 parent 1040187 commit ada72e1

File tree

3 files changed

+55
-74
lines changed

3 files changed

+55
-74
lines changed

src/copilot/contextProvider.ts

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,30 +29,28 @@ export async function registerCopilotContextProviders(
2929
if (!apis.clientApi || !apis.chatApi) {
3030
return;
3131
}
32-
3332
// Register the Java completion context provider
3433
const provider: ContextProvider<SupportedContextItem> = {
3534
id: 'vscjava.vscode-java-dependency', // use extension id as provider id for now
3635
selector: [{ language: "java" }],
3736
resolver: { resolve: createJavaContextResolver() }
3837
};
39-
4038
const installCount = await JavaContextProviderUtils.installContextProviderOnApis(apis, provider, context, installContextProvider);
41-
4239
if (installCount === 0) {
4340
return;
4441
}
45-
4642
sendInfo("", {
4743
"action": "registerCopilotContextProvider",
4844
"extension": 'vscjava.vscode-java-dependency',
4945
"status": "succeeded",
5046
"installCount": installCount
5147
});
52-
console.log(`Registered Copilot context provider for Java on ${installCount} APIs.`);
5348
}
5449
catch (error) {
55-
sendError(new ContextProviderRegistrationError('Failed to register Copilot context provider: ' + ((error as Error).message || "unknown_error")));
50+
const errorMessage = (error as Error).message || "unknown_error";
51+
sendError(new ContextProviderRegistrationError(
52+
'Failed to register Copilot context provider: ' + errorMessage
53+
));
5654
}
5755
}
5856

@@ -64,7 +62,6 @@ function createJavaContextResolver(): ContextResolverFunction {
6462
try {
6563
// Check for immediate cancellation
6664
JavaContextProviderUtils.checkCancellation(copilotCancel);
67-
6865
return await resolveJavaContext(request, copilotCancel);
6966
} catch (error: any) {
7067
sendError(new ContextProviderResolverError('Java Context Resolution Failed: ' + ((error as Error).message || "unknown_error")));
@@ -88,42 +85,36 @@ function sendContextTelemetry(request: ResolveRequest, start: number, items: Sup
8885
"tokenCount": tokenCount,
8986
"status": status
9087
};
91-
9288
if (error) {
9389
telemetryData.error = error;
9490
}
95-
9691
sendInfo("", telemetryData);
9792
}
9893

9994
async function resolveJavaContext(request: ResolveRequest, copilotCancel: vscode.CancellationToken): Promise<SupportedContextItem[]> {
10095
const items: SupportedContextItem[] = [];
10196
const start = performance.now();
102-
10397
try {
10498
// Check for cancellation before starting
10599
JavaContextProviderUtils.checkCancellation(copilotCancel);
106-
107100
// Resolve project dependencies and convert to context items
108101
const projectDependencyItems = await CopilotHelper.resolveAndConvertProjectDependencies(
109102
vscode.workspace.workspaceFolders,
110103
copilotCancel,
111104
JavaContextProviderUtils.checkCancellation
112105
);
113106
JavaContextProviderUtils.checkCancellation(copilotCancel);
114-
console.dir(projectDependencyItems);
115107
items.push(...projectDependencyItems);
116108

117109
JavaContextProviderUtils.checkCancellation(copilotCancel);
118-
110+
119111
// Resolve local imports and convert to context items
120112
const localImportItems = await CopilotHelper.resolveAndConvertLocalImports(
121113
vscode.window.activeTextEditor,
122114
copilotCancel,
123115
JavaContextProviderUtils.checkCancellation
124116
);
125117
JavaContextProviderUtils.checkCancellation(copilotCancel);
126-
console.dir(localImportItems);
127118
items.push(...localImportItems);
128119
} catch (error: any) {
129120
if (error instanceof CopilotCancellationError) {
@@ -134,17 +125,17 @@ async function resolveJavaContext(request: ResolveRequest, copilotCancel: vscode
134125
sendContextTelemetry(request, start, items, "cancelled_internally");
135126
throw new InternalCancellationError();
136127
}
137-
128+
138129
// Send telemetry for general errors (but continue with partial results)
139130
sendContextTelemetry(request, start, items, "error_partial_results", error.message || "unknown_error");
140-
131+
141132
// Return partial results and log completion for error case
142133
return items;
143134
}
144135

145136
// Send telemetry data once at the end for success case
146137
sendContextTelemetry(request, start, items, "succeeded");
147-
138+
148139
return items;
149140
}
150141

src/copilot/copilotHelper.ts

Lines changed: 30 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export interface IProjectDependency {
4444
}
4545

4646
export interface IProjectDependenciesResult {
47-
dependencyInfoList: Array<{ key: string; value: string }>;
47+
dependencyInfoList: { key: string; value: string }[];
4848
emptyReason?: string;
4949
isEmpty: boolean;
5050
}
@@ -80,9 +80,11 @@ export namespace CopilotHelper {
8080

8181
try {
8282
const normalizedUri = decodeURIComponent(Uri.file(fileUri.fsPath).toString());
83-
84-
const commandPromise = commands.executeCommand(Commands.EXECUTE_WORKSPACE_COMMAND, Commands.JAVA_PROJECT_GET_IMPORT_CLASS_CONTENT, normalizedUri) as Promise<IImportClassContentResult>;
85-
83+
const commandPromise = commands.executeCommand(
84+
Commands.EXECUTE_WORKSPACE_COMMAND,
85+
Commands.JAVA_PROJECT_GET_IMPORT_CLASS_CONTENT,
86+
normalizedUri
87+
) as Promise<IImportClassContentResult>;
8688
if (cancellationToken) {
8789
const result = await Promise.race([
8890
commandPromise,
@@ -97,15 +99,13 @@ export namespace CopilotHelper {
9799
}, 80); // 80ms timeout
98100
})
99101
]);
100-
101102
if (!result) {
102103
return {
103104
classInfoList: [],
104105
emptyReason: EmptyReason.CommandNullResult,
105106
isEmpty: true
106107
};
107108
}
108-
109109
return result;
110110
} else {
111111
const result = await Promise.race([
@@ -116,15 +116,13 @@ export namespace CopilotHelper {
116116
}, 80); // 80ms timeout
117117
})
118118
]);
119-
120119
if (!result) {
121120
return {
122121
classInfoList: [],
123122
emptyReason: EmptyReason.CommandNullResult,
124123
isEmpty: true
125124
};
126125
}
127-
128126
return result;
129127
}
130128
} catch (error: any) {
@@ -135,15 +133,13 @@ export namespace CopilotHelper {
135133
isEmpty: true
136134
};
137135
}
138-
139136
if (error.message === ErrorMessage.OperationTimedOut) {
140137
return {
141138
classInfoList: [],
142139
emptyReason: EmptyReason.Timeout,
143140
isEmpty: true
144141
};
145142
}
146-
147143
const errorMessage = 'TsException_' + ((error as Error).message || "unknown");
148144
sendError(new GetImportClassContentError(errorMessage));
149145
return {
@@ -162,13 +158,13 @@ export namespace CopilotHelper {
162158
*/
163159
export async function resolveProjectDependencies(projectUri: Uri, cancellationToken?: CancellationToken): Promise<IProjectDependency> {
164160
const result = await resolveProjectDependenciesWithReason(projectUri, cancellationToken);
165-
161+
166162
// Convert to legacy format
167163
const dependencies: IProjectDependency = {};
168164
for (const dep of result.dependencyInfoList) {
169165
dependencies[dep.key] = dep.value;
170166
}
171-
167+
172168
return dependencies;
173169
}
174170

@@ -178,7 +174,10 @@ export namespace CopilotHelper {
178174
* @param cancellationToken Optional cancellation token to abort the operation
179175
* @returns Result object containing project dependencies and error information
180176
*/
181-
export async function resolveProjectDependenciesWithReason(projectUri: Uri, cancellationToken?: CancellationToken): Promise<IProjectDependenciesResult> {
177+
export async function resolveProjectDependenciesWithReason(
178+
projectUri: Uri,
179+
cancellationToken?: CancellationToken
180+
): Promise<IProjectDependenciesResult> {
182181
if (cancellationToken?.isCancellationRequested) {
183182
return {
184183
dependencyInfoList: [],
@@ -189,9 +188,12 @@ export namespace CopilotHelper {
189188

190189
try {
191190
const normalizedUri = decodeURIComponent(Uri.file(projectUri.fsPath).toString());
191+
const commandPromise = commands.executeCommand(
192+
Commands.EXECUTE_WORKSPACE_COMMAND,
193+
Commands.JAVA_PROJECT_GET_DEPENDENCIES,
194+
normalizedUri
195+
) as Promise<IProjectDependenciesResult>;
192196

193-
const commandPromise = commands.executeCommand(Commands.EXECUTE_WORKSPACE_COMMAND, Commands.JAVA_PROJECT_GET_DEPENDENCIES, normalizedUri) as Promise<IProjectDependenciesResult>;
194-
195197
if (cancellationToken) {
196198
const result = await Promise.race([
197199
commandPromise,
@@ -206,15 +208,13 @@ export namespace CopilotHelper {
206208
}, 40); // 40ms timeout
207209
})
208210
]);
209-
210211
if (!result) {
211212
return {
212213
dependencyInfoList: [],
213214
emptyReason: EmptyReason.CommandNullResult,
214215
isEmpty: true
215216
};
216217
}
217-
218218
return result;
219219
} else {
220220
const result = await Promise.race([
@@ -225,15 +225,13 @@ export namespace CopilotHelper {
225225
}, 40); // 40ms timeout
226226
})
227227
]);
228-
229228
if (!result) {
230229
return {
231230
dependencyInfoList: [],
232231
emptyReason: EmptyReason.CommandNullResult,
233232
isEmpty: true
234233
};
235234
}
236-
237235
return result;
238236
}
239237
} catch (error: any) {
@@ -244,15 +242,13 @@ export namespace CopilotHelper {
244242
isEmpty: true
245243
};
246244
}
247-
248245
if (error.message === ErrorMessage.OperationTimedOut) {
249246
return {
250247
dependencyInfoList: [],
251248
emptyReason: EmptyReason.Timeout,
252249
isEmpty: true
253250
};
254251
}
255-
256252
const errorMessage = 'TsException_' + ((error as Error).message || "unknown");
257253
sendError(new GetProjectDependenciesError(errorMessage));
258254
return {
@@ -274,40 +270,38 @@ export namespace CopilotHelper {
274270
workspaceFolders: readonly { uri: Uri }[] | undefined,
275271
copilotCancel: CancellationToken,
276272
checkCancellation: (token: CancellationToken) => void
277-
): Promise<Array<{ name: string; value: string; importance: number }>> {
273+
): Promise<{ name: string; value: string; importance: number }[]> {
278274
const items: any[] = [];
279-
280275
// Check if workspace folders exist
281276
if (!workspaceFolders || workspaceFolders.length === 0) {
282277
sendContextOperationTelemetry("resolveProjectDependencies", "ContextEmpty", sendInfo, EmptyReason.NoWorkspace);
283278
return items;
284279
}
285-
286280
const projectUri = workspaceFolders[0];
287-
281+
288282
// Resolve project dependencies
289283
const projectDependenciesResult = await resolveProjectDependenciesWithReason(projectUri.uri, copilotCancel);
290-
284+
291285
// Check for cancellation after dependency resolution
292286
checkCancellation(copilotCancel);
293-
287+
294288
// Send telemetry if result is empty
295289
if (projectDependenciesResult.isEmpty && projectDependenciesResult.emptyReason) {
296290
sendContextOperationTelemetry("resolveProjectDependencies", "ContextEmpty", sendInfo, projectDependenciesResult.emptyReason);
297291
}
298-
292+
299293
// Check for cancellation after telemetry
300294
checkCancellation(copilotCancel);
301-
295+
302296
// Convert project dependencies to context items
303297
if (projectDependenciesResult.dependencyInfoList && projectDependenciesResult.dependencyInfoList.length > 0) {
304298
const contextItems = JavaContextProviderUtils.createContextItemsFromProjectDependencies(projectDependenciesResult.dependencyInfoList);
305-
299+
306300
// Check cancellation once after creating all items
307301
checkCancellation(copilotCancel);
308302
items.push(...contextItems);
309303
}
310-
304+
311305
return items;
312306
}
313307

@@ -325,46 +319,40 @@ export namespace CopilotHelper {
325319
checkCancellation: (token: CancellationToken) => void
326320
): Promise<any[]> {
327321
const items: any[] = [];
328-
329322
// Check if there's an active editor with a Java document
330323
if (!activeEditor) {
331324
sendContextOperationTelemetry("resolveLocalImports", "ContextEmpty", sendInfo, EmptyReason.NoActiveEditor);
332325
return items;
333326
}
334-
335327
if (activeEditor.document.languageId !== 'java') {
336328
sendContextOperationTelemetry("resolveLocalImports", "ContextEmpty", sendInfo, EmptyReason.NotJavaFile);
337329
return items;
338330
}
339-
331+
340332
const documentUri = activeEditor.document.uri;
341-
333+
342334
// Check for cancellation before resolving imports
343335
checkCancellation(copilotCancel);
344-
345336
// Resolve imports directly without caching
346337
const importClassResult = await resolveLocalImportsWithReason(documentUri, copilotCancel);
347-
338+
348339
// Check for cancellation after resolution
349340
checkCancellation(copilotCancel);
350-
341+
351342
// Send telemetry if result is empty
352343
if (importClassResult.isEmpty && importClassResult.emptyReason) {
353344
sendContextOperationTelemetry("resolveLocalImports", "ContextEmpty", sendInfo, importClassResult.emptyReason);
354345
}
355346
// Check for cancellation before processing results
356347
checkCancellation(copilotCancel);
357-
358348
if (importClassResult.classInfoList && importClassResult.classInfoList.length > 0) {
359349
// Process imports in batches to reduce cancellation check overhead
360350
const contextItems = JavaContextProviderUtils.createContextItemsFromImports(importClassResult.classInfoList);
361-
362351
// Check cancellation once after creating all items
363352
checkCancellation(copilotCancel);
364-
365353
items.push(...contextItems);
366354
}
367-
355+
368356
return items;
369357
}
370358
}

0 commit comments

Comments
 (0)