src/vs/platform/agentHost/common/fileEditDiff.ts
68 LOC · 68 covered · 0 uncovered · 6 ranges · 3 concepts · 3 introducers · 2 tests
File neighbourhood
The centred file is linked to every concept that introduces one of its ranges, every test that runs code from the file, and the gray connector concepts standing between those tests and the file's own introducer concepts. Undirected links join concepts to every file where they introduce source and concepts to the tests they introduce; arrows show specialization between the displayed concepts and bridge only concepts omitted from this view. Concept colors match the source ranges below; connector concepts have no source color and are shown in gray.
Focused file, its introducer and connector concepts, their introduced files, and tests that run code from the file
In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the related-file, concept, and source links on this page.
Graph controls are ready.
Interactive rendering requires JavaScript and WebGL. Use the related-file, concept, and source links on this page while the interactive map is unavailable.
/*---------------------------------------------------------------------------------------------
fileEditDiff.ts ×3
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { URI } from '../../../base/common/uri.js';
import { isEqual } from '../../../base/common/resources.js';
import type { FileEdit } from './state/protocol/state.js';
import { FileEditKind } from './state/sessionState.js';
/**
* A {@link FileEdit} decoded into parsed URIs and a resolved {@link FileEditKind}.
*
* The create/delete/rename/edit detection and the "primary resource" rule
* (after-URI for create/edit/rename, before-URI for delete) are subtle and
* were historically duplicated across several adapters. {@link normalizeFileEdit}
* centralizes them so every consumer derives the same shape from a protocol
* {@link FileEdit}.
*/
export interface INormalizedFileEdit {
/** The kind of file operation. */
readonly kind: FileEditKind;
/** Primary file URI: after-URI for create/edit/rename, before-URI for delete. */
readonly resource: URI;
/** The before-state file URI, when present (absent for creates). */
readonly beforeUri?: URI;
/** The after-state file URI, when present (absent for deletes). */
readonly afterUri?: URI;
/** URI from which the before-content can be read (absent for creates). */
readonly beforeContentUri?: URI;
/** URI from which the after-content can be read (absent for deletes). */
readonly afterContentUri?: URI;
}
/**
* Decodes a protocol {@link FileEdit} into parsed URIs and a resolved
* {@link FileEditKind}. Returns `undefined` when the edit carries no usable
* file URI (neither `before` nor `after`).
*/
export function normalizeFileEdit(edit: FileEdit): INormalizedFileEdit | undefined {
const beforeUri = edit.before ? URI.parse(edit.before.uri) : undefined;
const afterUri = edit.after ? URI.parse(edit.after.uri) : undefined;
const resource = afterUri ?? beforeUri;
if (!resource) {
}
let kind: FileEditKind;
} else if (beforeUri && !afterUri) {
kind = FileEditKind.Delete;
} else if (beforeUri && afterUri && !isEqual(beforeUri, afterUri)) {
kind = FileEditKind.Rename;
} else {
kind = FileEditKind.Edit;
}
return {
kind,
resource,
beforeUri,
afterUri,
beforeContentUri: edit.before?.content.uri ? URI.parse(edit.before.content.uri) : undefined,
fileEditDiff.ts ×3
afterContentUri: edit.after?.content.uri ? URI.parse(edit.after.content.uri) : undefined,
};
}