Skip to content

Commit f884aa0

Browse files
committed
nes: extract language context computation
side effect that we now always await not when language context is enabled
1 parent 544dc36 commit f884aa0

File tree

2 files changed

+44
-18
lines changed

2 files changed

+44
-18
lines changed

src/extension/xtab/node/xtabProvider.ts

Lines changed: 43 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -271,24 +271,18 @@ export class XtabProvider implements IStatelessNextEditProvider {
271271

272272
telemetryBuilder.setNLinesOfCurrentFileInPrompt(nLinesCurrentFile);
273273

274-
const recordingEnabled = this.configService.getConfig<boolean>(ConfigKey.Internal.InlineEditsLogContextRecorderEnabled);
275-
276-
let langCtx: LanguageContextResponse | undefined;
277-
if (promptOptions.languageContext.enabled || recordingEnabled) {
278-
const langCtxPromise = this.getLanguageContext(request, delaySession, activeDocument, cursorPosition, logContext, cancellationToken);
279-
280-
if (promptOptions.languageContext.enabled) {
281-
langCtx = await langCtxPromise;
282-
}
274+
const langCtx = await this.getAndProcessLanguageContext(
275+
request,
276+
delaySession,
277+
activeDocument,
278+
cursorPosition,
279+
promptOptions,
280+
logContext,
281+
cancellationToken,
282+
);
283283

284-
if (recordingEnabled) {
285-
logContext.setFileDiagnostics(this.langDiagService.getAllDiagnostics());
286-
langCtxPromise.then(langCtxs => {
287-
if (langCtxs) {
288-
logContext.setLanguageContext(langCtxs);
289-
}
290-
});
291-
}
284+
if (cancellationToken.isCancellationRequested) {
285+
return Result.error(new NoNextEditReason.GotCancelled('afterLanguageContextAwait'));
292286
}
293287

294288
const promptPieces = new PromptPieces(
@@ -420,6 +414,38 @@ export class XtabProvider implements IStatelessNextEditProvider {
420414
}));
421415
}
422416

417+
private getAndProcessLanguageContext(
418+
request: StatelessNextEditRequest,
419+
delaySession: DelaySession,
420+
activeDocument: StatelessNextEditDocument,
421+
cursorPosition: Position,
422+
promptOptions: ModelConfig,
423+
logContext: InlineEditRequestLogContext,
424+
cancellationToken: CancellationToken,
425+
): Promise<LanguageContextResponse | undefined> {
426+
const recordingEnabled = this.configService.getConfig<boolean>(ConfigKey.Internal.InlineEditsLogContextRecorderEnabled);
427+
428+
if (!promptOptions.languageContext.enabled && !recordingEnabled) {
429+
return Promise.resolve(undefined);
430+
}
431+
432+
const langCtxPromise = this.getLanguageContext(request, delaySession, activeDocument, cursorPosition, logContext, cancellationToken);
433+
434+
// if recording, add diagnostics for the file to the recording and hook up the language context promise to write to the recording
435+
if (recordingEnabled) {
436+
logContext.setFileDiagnostics(this.langDiagService.getAllDiagnostics());
437+
langCtxPromise.then(langCtxs => {
438+
if (langCtxs) {
439+
logContext.setLanguageContext(langCtxs);
440+
}
441+
});
442+
}
443+
444+
return promptOptions.languageContext.enabled
445+
? langCtxPromise
446+
: Promise.resolve(undefined);
447+
}
448+
423449

424450
private async getLanguageContext(
425451
request: StatelessNextEditRequest,

src/platform/inlineEdits/common/statelessNextEditProvider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ export namespace NoNextEditReason {
196196
}
197197
export class GotCancelled {
198198
public readonly kind = 'gotCancelled';
199-
constructor(public readonly message: 'afterDebounce' | 'afterGettingEndpoint' | 'afterPromptConstruction' | 'afterFetchCall' | 'duringStreaming' | 'afterResponse' | 'afterFailedRebase' | 'beforeExecutingNewRequest') {
199+
constructor(public readonly message: 'afterDebounce' | 'afterGettingEndpoint' | 'afterLanguageContextAwait' | 'afterPromptConstruction' | 'afterFetchCall' | 'duringStreaming' | 'afterResponse' | 'afterFailedRebase' | 'beforeExecutingNewRequest') {
200200
}
201201
}
202202
export class FetchFailure {

0 commit comments

Comments
 (0)