addons/vscode/extension/DeletedFileContentProvider.tsblame
View source
b69ab311/**
b69ab312 * Copyright (c) Meta Platforms, Inc. and affiliates.
b69ab313 *
b69ab314 * This source code is licensed under the MIT license found in the
b69ab315 * LICENSE file in the root directory of this source tree.
b69ab316 */
b69ab317
b69ab318import * as vscode from 'vscode';
b69ab319
b69ab3110export const DELETED_FILE_DIFF_VIEW_PROVIDER_SCHEME = 'sapling-deleted-file';
b69ab3111
b69ab3112/**
b69ab3113 * Provides empty content for deleted files, so they may be used in diff views.
b69ab3114 */
b69ab3115export class DeletedFileContentProvider implements vscode.TextDocumentContentProvider {
b69ab3116 disposable: vscode.Disposable;
b69ab3117
b69ab3118 constructor() {
b69ab3119 this.disposable = vscode.workspace.registerTextDocumentContentProvider(
b69ab3120 DELETED_FILE_DIFF_VIEW_PROVIDER_SCHEME,
b69ab3121 this,
b69ab3122 );
b69ab3123 }
b69ab3124
b69ab3125 public provideTextDocumentContent(_uri: vscode.Uri): Promise<string | null> {
b69ab3126 return Promise.resolve('');
b69ab3127 }
b69ab3128
b69ab3129 dispose() {
b69ab3130 this.disposable.dispose();
b69ab3131 }
b69ab3132}
b69ab3133
b69ab3134/**
b69ab3135 * URIs are provided for the QuickDiff encoded, so that we can restore the original URI.
b69ab3136 */
b69ab3137export function encodeDeletedFileUri(uri: vscode.Uri): vscode.Uri {
b69ab3138 return uri.with({
b69ab3139 scheme: DELETED_FILE_DIFF_VIEW_PROVIDER_SCHEME,
b69ab3140 query: JSON.stringify({originalScheme: uri.scheme}),
b69ab3141 });
b69ab3142}