mirror of
https://github.com/microsoft/vscode.git
synced 2026-02-21 18:28:50 +00:00
This commit is contained in:
committed by
Henning Dieterichs
parent
1c8a55c110
commit
8b01ac01a7
@@ -130,6 +130,7 @@ export type IModel = ITextModel;
|
||||
|
||||
declare namespace monaco.languages {
|
||||
|
||||
#include(vs/editor/common/textModelEditSource): EditDeltaInfo
|
||||
#include(vs/base/common/glob): IRelativePattern
|
||||
#include(vs/editor/common/languageSelector): LanguageSelector, LanguageFilter
|
||||
#includeAll(vs/editor/standalone/browser/standaloneLanguages;languages.=>;editorCommon.=>editor.;model.=>editor.;IMarkerData=>editor.IMarkerData):
|
||||
|
||||
@@ -26,6 +26,7 @@ import { ContiguousMultilineTokens } from './tokens/contiguousMultilineTokens.js
|
||||
import { localize } from '../../nls.js';
|
||||
import { ExtensionIdentifier } from '../../platform/extensions/common/extensions.js';
|
||||
import { IMarkerData } from '../../platform/markers/common/markers.js';
|
||||
import { EditDeltaInfo } from './textModelEditSource.js';
|
||||
|
||||
/**
|
||||
* @internal
|
||||
@@ -886,7 +887,7 @@ export interface InlineCompletionsProvider<T extends InlineCompletions = InlineC
|
||||
* Will be called when an item is shown.
|
||||
* @param updatedInsertText Is useful to understand bracket completion.
|
||||
*/
|
||||
handleItemDidShow?(completions: T, item: T['items'][number], updatedInsertText: string): void;
|
||||
handleItemDidShow?(completions: T, item: T['items'][number], updatedInsertText: string, editDeltaInfo: EditDeltaInfo): void;
|
||||
|
||||
/**
|
||||
* Will be called when an item is partially accepted. TODO: also handle full acceptance here!
|
||||
|
||||
@@ -205,6 +205,7 @@ export class EditDeltaInfo {
|
||||
return new EditDeltaInfo(linesAdded, 0, charsAdded, 0);
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
public static fromEdit(edit: BaseStringEdit, originalString: StringText): EditDeltaInfo {
|
||||
const lineEdit = LineEdit.fromStringEdit(edit, originalString);
|
||||
const linesAdded = sumBy(lineEdit.replacements, r => r.newLines.length);
|
||||
|
||||
@@ -28,6 +28,7 @@ import { CachedFunction } from '../../../../../base/common/cache.js';
|
||||
import { InlineCompletionViewData, InlineCompletionViewKind } from '../view/inlineEdits/inlineEditsViewInterface.js';
|
||||
import { isDefined } from '../../../../../base/common/types.js';
|
||||
import { inlineCompletionIsVisible } from './inlineSuggestionItem.js';
|
||||
import { EditDeltaInfo } from '../../../../common/textModelEditSource.js';
|
||||
|
||||
export type InlineCompletionContextWithoutUuid = Omit<InlineCompletionContext, 'requestUuid'>;
|
||||
|
||||
@@ -331,7 +332,8 @@ export class InlineSuggestData {
|
||||
this._viewData.renderData = viewData;
|
||||
this._timeUntilShown = Date.now() - this._requestInfo.startTime;
|
||||
|
||||
this.source.provider.handleItemDidShow?.(this.source.inlineSuggestions, this.sourceInlineCompletion, updatedInsertText);
|
||||
const editDeltaInfo = new EditDeltaInfo(viewData.lineCountModified, viewData.lineCountOriginal, viewData.characterCountModified, viewData.characterCountOriginal);
|
||||
this.source.provider.handleItemDidShow?.(this.source.inlineSuggestions, this.sourceInlineCompletion, updatedInsertText, editDeltaInfo);
|
||||
|
||||
if (this.sourceInlineCompletion.shownCommand) {
|
||||
await commandService.executeCommand(this.sourceInlineCompletion.shownCommand.id, ...(this.sourceInlineCompletion.shownCommand.arguments || []));
|
||||
|
||||
@@ -25,6 +25,7 @@ import { IMonarchLanguage } from '../common/monarch/monarchTypes.js';
|
||||
import { IStandaloneThemeService } from '../common/standaloneTheme.js';
|
||||
import { IConfigurationService } from '../../../platform/configuration/common/configuration.js';
|
||||
import { IMarkerData, IMarkerService } from '../../../platform/markers/common/markers.js';
|
||||
import { EditDeltaInfo } from '../../common/textModelEditSource.js';
|
||||
|
||||
/**
|
||||
* Register information about a new language.
|
||||
@@ -811,5 +812,6 @@ export function createMonacoLanguagesAPI(): typeof monaco.languages {
|
||||
// classes
|
||||
FoldingRangeKind: languages.FoldingRangeKind,
|
||||
SelectedSuggestionInfo: <any>languages.SelectedSuggestionInfo,
|
||||
EditDeltaInfo: <any>EditDeltaInfo,
|
||||
};
|
||||
}
|
||||
|
||||
12
src/vs/monaco.d.ts
vendored
12
src/vs/monaco.d.ts
vendored
@@ -6517,6 +6517,16 @@ declare namespace monaco.editor {
|
||||
|
||||
declare namespace monaco.languages {
|
||||
|
||||
|
||||
export class EditDeltaInfo {
|
||||
readonly linesAdded: number;
|
||||
readonly linesRemoved: number;
|
||||
readonly charsAdded: number;
|
||||
readonly charsRemoved: number;
|
||||
static fromText(text: string): EditDeltaInfo;
|
||||
static tryCreate(linesAdded: number | undefined, linesRemoved: number | undefined, charsAdded: number | undefined, charsRemoved: number | undefined): EditDeltaInfo | undefined;
|
||||
constructor(linesAdded: number, linesRemoved: number, charsAdded: number, charsRemoved: number);
|
||||
}
|
||||
export interface IRelativePattern {
|
||||
/**
|
||||
* A base file path to which this pattern will be matched against relatively.
|
||||
@@ -7589,7 +7599,7 @@ declare namespace monaco.languages {
|
||||
* Will be called when an item is shown.
|
||||
* @param updatedInsertText Is useful to understand bracket completion.
|
||||
*/
|
||||
handleItemDidShow?(completions: T, item: T['items'][number], updatedInsertText: string): void;
|
||||
handleItemDidShow?(completions: T, item: T['items'][number], updatedInsertText: string, editDeltaInfo: EditDeltaInfo): void;
|
||||
/**
|
||||
* Will be called when an item is partially accepted. TODO: also handle full acceptance here!
|
||||
* @param acceptedCharacters Deprecated. Use `info.acceptedCharacters` instead.
|
||||
|
||||
@@ -638,19 +638,21 @@ export class MainThreadLanguageFeatures extends Disposable implements MainThread
|
||||
const result = await this._proxy.$provideInlineCompletions(handle, model.uri, position, context, token);
|
||||
return result;
|
||||
},
|
||||
handleItemDidShow: async (completions: IdentifiableInlineCompletions, item: IdentifiableInlineCompletion, updatedInsertText: string): Promise<void> => {
|
||||
handleItemDidShow: async (completions: IdentifiableInlineCompletions, item: IdentifiableInlineCompletion, updatedInsertText: string, editDeltaInfo: EditDeltaInfo): Promise<void> => {
|
||||
this._instantiationService.invokeFunction(accessor => {
|
||||
const aiEditTelemetryService = accessor.getIfExists(IAiEditTelemetryService);
|
||||
item.suggestionId = aiEditTelemetryService?.createSuggestionId({
|
||||
applyCodeBlockSuggestionId: undefined,
|
||||
feature: 'inlineSuggestion',
|
||||
source: providerId,
|
||||
languageId: completions.languageId,
|
||||
editDeltaInfo: new EditDeltaInfo(1, 1, -1, -1), // TODO@hediet, fix this approximation.
|
||||
modeId: undefined,
|
||||
modelId: undefined,
|
||||
presentation: item.isInlineEdit ? 'nextEditSuggestion' : 'inlineCompletion',
|
||||
});
|
||||
if (item.suggestionId === undefined) {
|
||||
item.suggestionId = aiEditTelemetryService?.createSuggestionId({
|
||||
applyCodeBlockSuggestionId: undefined,
|
||||
feature: 'inlineSuggestion',
|
||||
source: providerId,
|
||||
languageId: completions.languageId,
|
||||
editDeltaInfo: editDeltaInfo,
|
||||
modeId: undefined,
|
||||
modelId: undefined,
|
||||
presentation: item.isInlineEdit ? 'nextEditSuggestion' : 'inlineCompletion',
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
if (supportsHandleEvents) {
|
||||
@@ -681,23 +683,25 @@ export class MainThreadLanguageFeatures extends Disposable implements MainThread
|
||||
if (reason.kind === languages.InlineCompletionEndOfLifeReasonKind.Accepted) {
|
||||
this._instantiationService.invokeFunction(accessor => {
|
||||
const aiEditTelemetryService = accessor.getIfExists(IAiEditTelemetryService);
|
||||
aiEditTelemetryService?.handleCodeAccepted({
|
||||
suggestionId: item.suggestionId,
|
||||
feature: 'inlineSuggestion',
|
||||
source: providerId,
|
||||
languageId: completions.languageId,
|
||||
editDeltaInfo: EditDeltaInfo.tryCreate(
|
||||
lifetimeSummary.lineCountModified,
|
||||
lifetimeSummary.lineCountOriginal,
|
||||
lifetimeSummary.characterCountModified,
|
||||
lifetimeSummary.characterCountOriginal,
|
||||
),
|
||||
modeId: undefined,
|
||||
modelId: undefined,
|
||||
presentation: item.isInlineEdit ? 'nextEditSuggestion' : 'inlineCompletion',
|
||||
acceptanceMethod: 'accept',
|
||||
applyCodeBlockSuggestionId: undefined,
|
||||
});
|
||||
if (item.suggestionId !== undefined) {
|
||||
aiEditTelemetryService?.handleCodeAccepted({
|
||||
suggestionId: item.suggestionId,
|
||||
feature: 'inlineSuggestion',
|
||||
source: providerId,
|
||||
languageId: completions.languageId,
|
||||
editDeltaInfo: EditDeltaInfo.tryCreate(
|
||||
lifetimeSummary.lineCountModified,
|
||||
lifetimeSummary.lineCountOriginal,
|
||||
lifetimeSummary.characterCountModified,
|
||||
lifetimeSummary.characterCountOriginal,
|
||||
),
|
||||
modeId: undefined,
|
||||
modelId: undefined,
|
||||
presentation: item.isInlineEdit ? 'nextEditSuggestion' : 'inlineCompletion',
|
||||
acceptanceMethod: 'accept',
|
||||
applyCodeBlockSuggestionId: undefined,
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user