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