import { IConfigurationService } from '../../../platform/configuration/common/configurationService'; import { DocumentId } from '../../../platform/inlineEdits/common/dataTypes/documentId'; import { ObservableWorkspace } from '../../../platform/inlineEdits/common/observableWorkspace'; import type { IStatelessNextEditModelTelemetry } from '../../../platform/inlineEdits/common/statelessNextEditProvider'; import { ILogService } from '../../../platform/log/common/logService'; import { IExperimentationService } from '../../../platform/telemetry/common/nullExperimentationService'; import { Disposable } from '../../../util/vs/base/common/lifecycle'; import { AnnotatedStringReplacement, StringEdit, StringReplacement } from '../../../util/vs/editor/common/core/edits/stringEdit'; import { OffsetRange } from '../../../util/vs/editor/common/core/ranges/offsetRange'; import { StringText } from '../../../util/vs/editor/common/core/text/abstractText'; import { EditDataWithIndex } from '../common/editRebase'; import type { NextEditFetchRequest } from './nextEditProvider'; import { type RebaseResult } from './rebaseResult'; export interface CachedEditOpts { isFromCursorJump: boolean; /** Model attribution for the request that produced this edit. */ modelTelemetry: IStatelessNextEditModelTelemetry; /** * For cursor jump edits, this is the edit window around the original cursor position * (before the jump), allowing the edit to be served from cache when the cursor is * in either the original location or the jump target location. */ originalEditWindow?: OffsetRange; /** * The cursor offset at the time the edit was cached. * Used for cursor-distance filtering: if the user moves farther from the edit, * the cached entry is not served. */ cursorOffset?: number; /** * Zero-based index of the model-emitted patch this edit originated from * (diff-patch response format). `undefined` for formats without an explicit * patch structure. @see StreamedEdit.patchIndex */ patchIndex?: number; /** * Patch indices for the bundled `nextEdits`, aligned by position. Stored on the * first cached entry so that edits served later via rebase (addressed by * `rebasedEditIndex` into the bundle) can be attributed to the right model patch. */ patchIndices?: readonly (number | undefined)[]; /** * The document the cached edit actually applies to, when it differs from the * document the entry is keyed under (cross-file NES). `undefined` means the edit * targets the owning/key document (the common same-file case). * * Used to cache an `A -> suggestion-in-B` association: the entry is keyed and * gated against the active document A (content + edit window), but the edit it * carries lands in document B. */ targetDocId?: DocumentId; /** * The target document's content at the time the cross-file edit was produced * (i.e. the content the {@link CachedEdit.edit} offsets index into). Only set * together with {@link targetDocId}. The read path must serve the edit only when * the target document's live content still equals this snapshot; otherwise the * edit's offsets are stale and would resolve against the wrong content. */ targetDocumentBeforeEdit?: StringText; } export interface CachedEdit { docId: DocumentId; /** * The document the cached edit actually applies to, when it differs from {@link docId} * (cross-file NES). `undefined` means the edit targets the owning/key document * {@link docId} (the common same-file case). @see CachedEditOpts.targetDocId */ targetDocId?: DocumentId; /** * The target document's content at the time the cross-file edit was produced. * Only set together with {@link targetDocId}. @see CachedEditOpts.targetDocumentBeforeEdit */ targetDocumentBeforeEdit?: StringText; documentBeforeEdit: StringText; editWindow?: OffsetRange; /** * For cursor jump edits, the edit window around the original cursor position. * @see CachedEditOpts.originalEditWindow */ originalEditWindow?: OffsetRange; edit: StringReplacement | undefined; isFromCursorJump: boolean; edits?: StringReplacement[]; detailedEdits: AnnotatedStringReplacement[][]; userEditSince?: StringEdit; rebaseFailed?: boolean; rejected?: boolean; /** * When caching multiple edits, this is the order in which they were applied. */ subsequentN?: number; /** * Zero-based index of the model-emitted patch this edit originated from * (diff-patch response format). @see StreamedEdit.patchIndex */ patchIndex?: number; /** * Patch indices for the bundled `edits`, aligned by position. Present on the * first cached entry (the one carrying the `edits` bundle) so rebased subsequent * edits, addressed by `rebasedEditIndex`, can be attributed to the right patch. */ patchIndices?: readonly (number | undefined)[]; /** Model attribution for the request that produced this edit. */ modelTelemetry: IStatelessNextEditModelTelemetry; source: NextEditFetchRequest; cacheTime: number; /** * The cursor offset at the time the edit was cached. * @see CachedEditOpts.cursorOffset */ cursorOffsetAtCacheTime?: number; /** * Set to `true` once this cached suggestion has been rendered as an inline * (ghost text at cursor) suggestion. Used by the "mimic ghost text behavior" * gating to suppress re-serving the same suggestion in a non-inline form. */ wasRenderedAsInlineSuggestion?: boolean; } export type CachedOrRebasedEdit = CachedEdit & { rebasedEdit?: StringReplacement; rebasedEditIndex?: number; isFromSpeculativeRequest?: boolean; /** * When this is a rebased view of a cached edit, points to the underlying * stored {@link CachedEdit} so that flags such as * {@link CachedEdit.wasRenderedAsInlineSuggestion} can be persisted on the * stable cache entry instead of the transient rebased view. */ baseCacheEntry?: CachedEdit; }; export declare class NextEditCache extends Disposable { readonly workspace: ObservableWorkspace; private readonly _logService; private readonly _configService; private readonly _expService; private readonly _documentCaches; private readonly _sharedCache; constructor(workspace: ObservableWorkspace, _logService: ILogService, _configService: IConfigurationService, _expService: IExperimentationService); setKthNextEdit(docId: DocumentId, documentContents: StringText, editWindow: OffsetRange | undefined, nextEdit: StringReplacement, subsequentN: number, nextEdits: StringReplacement[] | undefined, userEditSince: StringEdit | undefined, source: NextEditFetchRequest, opts: CachedEditOpts): CachedEdit | undefined; setNoNextEdit(docId: DocumentId, documentContents: StringText, editWindow: OffsetRange | undefined, source: NextEditFetchRequest, modelTelemetry: IStatelessNextEditModelTelemetry): void; private _getNesRebaseConfigs; lookupNextEdit(docId: DocumentId, currentDocumentContents: StringText, currentSelection: readonly OffsetRange[]): CachedOrRebasedEdit | undefined; tryRebaseCacheEntry(cachedEdit: CachedEdit, currentDocumentContents: StringText, currentSelection: readonly OffsetRange[]): RebaseResult; rejectedNextEdit(requestId: string): void; isRejectedNextEdit(docId: DocumentId, currentDocumentContents: StringText, edit: StringReplacement): boolean; evictedCachedEdit(cachedEdit: CachedEdit): void; clear(): void; } //# sourceMappingURL=nextEditCache.d.ts.map