Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export class GhostTextProvider {
if (typeof info === 'number') {
return; // deprecated API
}
this.instantiationService.invokeFunction(handlePartialGhostTextPostInsert, item.copilotCompletion, info.acceptedLength, info.kind);
this.instantiationService.invokeFunction(handlePartialGhostTextPostInsert, item.copilotCompletion, info.acceptedLength);
}

async handleEndOfLifetime(completionItem: GhostTextCompletionItem, reason: InlineCompletionEndOfLifeReason) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { RequestId } from '../../../../lib/src/openai/openai';
import { RequestId } from '../../../../../../../platform/networking/common/fetch';
import { CopilotNamedAnnotationList } from '../../../../lib/src/openai/stream';
import { TelemetryWithExp } from '../../../../lib/src/telemetry';
import { IRange } from '../../../../lib/src/textDocument';
Expand Down
565 changes: 286 additions & 279 deletions src/extension/completions-core/vscode-node/lib/src/ghostText/ghostText.ts

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import { createServiceIdentifier } from '../../../../../../util/common/services'
import { ServicesAccessor } from '../../../../../../util/vs/platform/instantiation/common/instantiation';
import { ICompletionsLogTargetService, Logger } from '../logger';
import { postInsertionTasks, postRejectionTasks } from '../postInsertion';
import { countLines, PartialAcceptTriggerKind, SuggestionStatus } from '../suggestions/partialSuggestions';
import { countLines, SuggestionStatus } from '../suggestions/partialSuggestions';
import { TelemetryWithExp } from '../telemetry';
import { IPosition, TextDocumentContents, TextDocumentIdentifier } from '../textDocument';
import { CopilotCompletion } from './copilotCompletion';
import { ResultType } from './ghostText';
import { PostInsertionCategory, telemetryShown } from './telemetry';
import { GHOST_TEXT_CATEGORY, telemetryShown } from './telemetry';

const ghostTextLogger = new Logger('ghostText');

Expand Down Expand Up @@ -168,7 +168,7 @@ export function handleGhostTextShown(accessor: ServicesAccessor, cmp: CopilotCom
`[${cmp.telemetry.properties.headerRequestId}] shown choiceIndex: ${cmp.telemetry.properties.choiceIndex}, fromCache ${fromCache}`
);
cmp.telemetry.measurements.compCharLen = cmp.displayText.length;
telemetryShown(accessor, 'ghostText', cmp);
telemetryShown(accessor, cmp);
}
}
}
Expand Down Expand Up @@ -206,7 +206,6 @@ function handleLineAcceptance(accessor: ServicesAccessor, cmp: CopilotCompletion
export function handleGhostTextPostInsert(
accessor: ServicesAccessor,
cmp: CopilotCompletion,
triggerCategory: PostInsertionCategory = 'ghostText'
) {
const last = accessor.get(ICompletionsLastGhostText);

Expand All @@ -232,7 +231,7 @@ export function handleGhostTextPostInsert(

return postInsertionTasks(
accessor,
triggerCategory,
GHOST_TEXT_CATEGORY,
cmp.displayText,
cmp.offset,
cmp.uri,
Expand All @@ -246,8 +245,6 @@ export function handlePartialGhostTextPostInsert(
accessor: ServicesAccessor,
cmp: CopilotCompletion,
acceptedLength: number,
triggerKind: PartialAcceptTriggerKind = PartialAcceptTriggerKind.Unknown,
triggerCategory: PostInsertionCategory = 'ghostText',
) {
const last = accessor.get(ICompletionsLastGhostText);

Expand All @@ -261,7 +258,7 @@ export function handlePartialGhostTextPostInsert(

return postInsertionTasks(
accessor,
triggerCategory,
GHOST_TEXT_CATEGORY,
cmp.displayText,
cmp.offset,
cmp.uri,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,17 @@ import { ICompletionsSpeculativeRequestCache } from './speculativeRequestCache';

export type PostInsertionCategory = 'ghostText' | 'solution';

export const GHOST_TEXT_CATEGORY: PostInsertionCategory = 'ghostText';

export const logger = new Logger('getCompletions');

/** Send `.shown` event */
export function telemetryShown(accessor: ServicesAccessor, insertionCategory: PostInsertionCategory, completion: CopilotCompletion) {
export function telemetryShown(accessor: ServicesAccessor, completion: CopilotCompletion) {
const speculativeRequestCache = accessor.get(ICompletionsSpeculativeRequestCache);
void speculativeRequestCache.request(completion.clientCompletionId);
completion.telemetry.markAsDisplayed(); // TODO: Consider removing displayedTime as unused and generally incorrect.
completion.telemetry.properties.reason = resultTypeToString(completion.resultType);
telemetry(accessor, `${insertionCategory}.shown`, completion.telemetry);
telemetry(accessor, `ghostText.shown`, completion.telemetry);
}

/** Send `.accepted` event */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ suite('Isolated GhostText tests', function () {

// Setup closures with the state as default
function requestGhostText(completionState = state) {
return getGhostText(accessor, completionState, token);
return getGhostText(accessor, completionState, token, {});
}
async function requestPrompt(completionState = state) {
const telemExp = TelemetryWithExp.createEmptyConfigForTesting();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ suite('Isolated LastGhostText tests', function () {
handleGhostTextShown(accessor, cmp);

const { reporter } = await withInMemoryTelemetry(accessor, () => {
handlePartialGhostTextPostInsert(accessor, cmp, 'line1'.length, undefined, undefined);
handlePartialGhostTextPostInsert(accessor, cmp, 'line1'.length);
});

const event = reporter.events.find(e => e.name === 'ghostText.accepted');
Expand All @@ -112,11 +112,11 @@ suite('Isolated LastGhostText tests', function () {
last.setState({ uri: 'file:///test' }, { line: 0, character: 0 });
const cmp = makeCompletion(0, 'line1\nline2\nline3', 0);
handleGhostTextShown(accessor, cmp);
handlePartialGhostTextPostInsert(accessor, cmp, 'line1'.length, undefined, undefined);
handlePartialGhostTextPostInsert(accessor, cmp, 'line1'.length);
cmp.displayText = 'line2\nline3'; // Simulate the display text being updated after accepting the first line

const { reporter } = await withInMemoryTelemetry(accessor, () => {
handlePartialGhostTextPostInsert(accessor, cmp, 'line2'.length, undefined, undefined);
handlePartialGhostTextPostInsert(accessor, cmp, 'line2'.length);
});

const event = reporter.events.reverse().find(e => e.name === 'ghostText.accepted');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,11 @@
*--------------------------------------------------------------------------------------------*/

import type { CancellationToken } from 'vscode';
import { IAuthenticationService } from '../../../../../../platform/authentication/common/authentication';
import { generateUuid } from '../../../../../../util/vs/base/common/uuid';
import { IInstantiationService } from '../../../../../../util/vs/platform/instantiation/common/instantiation';
import { getTokenizer } from '../../../prompt/src/tokenization';
import { ICompletionsCopilotTokenManager } from '../auth/copilotTokenManager';
import { ICompletionsLogTargetService } from '../logger';
import { Response } from '../networking';
import { ICompletionsStatusReporter } from '../progress';
import { TelemetryData, TelemetryWithExp } from '../telemetry';
import { ICompletionsRuntimeModeService } from '../util/runtimeMode';
import {
CompletionError,
CompletionParams,
Expand Down Expand Up @@ -53,6 +48,9 @@ export function fakeAPIChoice(
headerRequestId,
serverExperiments: 'dummy',
deploymentId: 'dummy',
gitHubRequestId: 'dummy',
completionId: 'dummy',
created: 0
},
telemetryData,
// This slightly convoluted way of getting the tokens as a string array is an
Expand Down Expand Up @@ -155,6 +153,15 @@ export class SyntheticCompletions extends OpenAIFetcher {
return fakeResponse(emptyCompletions, finishedCb, params.postOptions, baseTelemetryData);
}
}

async fetchAndStreamCompletions2(
params: CompletionParams,
baseTelemetryData: TelemetryWithExp,
finishedCb: FinishedCallback,
cancel?: CancellationToken
): Promise<CompletionResults | CompletionError> {
return this.fetchAndStreamCompletions(params, baseTelemetryData, finishedCb, cancel);
}
}


Expand All @@ -163,17 +170,6 @@ export class ErrorReturningFetcher extends LiveOpenAIFetcher {

private response: Response | 'not-sent' = 'not-sent';

constructor(
@IInstantiationService instantiationService: IInstantiationService,
@ICompletionsRuntimeModeService runtimeModeService: ICompletionsRuntimeModeService,
@ICompletionsLogTargetService logTargetService: ICompletionsLogTargetService,
@ICompletionsCopilotTokenManager copilotTokenManager: ICompletionsCopilotTokenManager,
@ICompletionsStatusReporter statusReporter: ICompletionsStatusReporter,
@IAuthenticationService authenticationService: IAuthenticationService,
) {
super(instantiationService, runtimeModeService, logTargetService, copilotTokenManager, statusReporter, authenticationService);
}

setResponse(response: Response | 'not-sent') {
this.response = response;
}
Expand Down
Loading
Loading