1.1 KB43 lines
Blame
1/**
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
8import * as vscode from 'vscode';
9
10export const DELETED_FILE_DIFF_VIEW_PROVIDER_SCHEME = 'sapling-deleted-file';
11
12/**
13 * Provides empty content for deleted files, so they may be used in diff views.
14 */
15export class DeletedFileContentProvider implements vscode.TextDocumentContentProvider {
16 disposable: vscode.Disposable;
17
18 constructor() {
19 this.disposable = vscode.workspace.registerTextDocumentContentProvider(
20 DELETED_FILE_DIFF_VIEW_PROVIDER_SCHEME,
21 this,
22 );
23 }
24
25 public provideTextDocumentContent(_uri: vscode.Uri): Promise<string | null> {
26 return Promise.resolve('');
27 }
28
29 dispose() {
30 this.disposable.dispose();
31 }
32}
33
34/**
35 * URIs are provided for the QuickDiff encoded, so that we can restore the original URI.
36 */
37export function encodeDeletedFileUri(uri: vscode.Uri): vscode.Uri {
38 return uri.with({
39 scheme: DELETED_FILE_DIFF_VIEW_PROVIDER_SCHEME,
40 query: JSON.stringify({originalScheme: uri.scheme}),
41 });
42}
43