Skip to content

Commit c1e735f

Browse files
Copilotalexr00
andcommitted
Replace file system provider with webview for empty commits
- Removed EmptyCommitFileSystemProvider and related URI scheme - Created showEmptyCommitWebview() function with centered message - Updated openCommitChanges() to accept extensionUri and show webview - Styled webview to display message centered similar to GitHub.com Co-authored-by: alexr00 <[email protected]>
1 parent b0da547 commit c1e735f

File tree

6 files changed

+73
-37
lines changed

6 files changed

+73
-37
lines changed

src/common/uri.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -117,14 +117,6 @@ export function toGitHubCommitUri(fileName: string, params: GitHubCommitUriParam
117117
});
118118
}
119119

120-
export function toEmptyCommitUri(commitSha: string): vscode.Uri {
121-
return vscode.Uri.from({
122-
scheme: Schemes.EmptyCommit,
123-
path: `/commit-${commitSha.substring(0, 7)}.txt`,
124-
query: commitSha
125-
});
126-
}
127-
128120
const ImageMimetypes = ['image/png', 'image/gif', 'image/jpeg', 'image/webp', 'image/tiff', 'image/bmp'];
129121
// Known media types that VS Code can handle: https://github.com/microsoft/vscode/blob/a64e8e5673a44e5b9c2d493666bde684bd5a135c/src/vs/base/common/mime.ts#L33-L84
130122
export const KnownMediaExtensions = [
@@ -758,8 +750,7 @@ export enum Schemes {
758750
Repo = 'repo', // New issue file for passing data
759751
Git = 'git', // File content from the git extension
760752
PRQuery = 'prquery', // PR query tree item
761-
GitHubCommit = 'githubcommit', // file content from GitHub for a commit
762-
EmptyCommit = 'emptycommit' // Empty commit placeholder file
753+
GitHubCommit = 'githubcommit' // file content from GitHub for a commit
763754
}
764755

765756
export function resolvePath(from: vscode.Uri, to: string) {

src/extension.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ import { CommentDecorationProvider } from './view/commentDecorationProvider';
4444
import { CompareChanges } from './view/compareChangesTreeDataProvider';
4545
import { CreatePullRequestHelper } from './view/createPullRequestHelper';
4646
import { EmojiCompletionProvider } from './view/emojiCompletionProvider';
47-
import { EmptyCommitFileSystemProvider } from './view/emptyCommitFileSystemProvider';
4847
import { FileTypeDecorationProvider } from './view/fileTypeDecorationProvider';
4948
import { GitHubCommitFileSystemProvider } from './view/githubFileContentProvider';
5049
import { getInMemPRFileSystemProvider } from './view/inMemPRContentProvider';
@@ -501,8 +500,6 @@ async function deferredActivate(context: vscode.ExtensionContext, showPRControll
501500
context.subscriptions.push(vscode.workspace.registerFileSystemProvider(Schemes.Pr, inMemPRFileSystemProvider, { isReadonly: readOnlyMessage }));
502501
const githubFilesystemProvider = new GitHubCommitFileSystemProvider(reposManager, apiImpl, credentialStore);
503502
context.subscriptions.push(vscode.workspace.registerFileSystemProvider(Schemes.GitHubCommit, githubFilesystemProvider, { isReadonly: new vscode.MarkdownString(vscode.l10n.t('GitHub commits cannot be edited')) }));
504-
const emptyCommitFileSystemProvider = new EmptyCommitFileSystemProvider();
505-
context.subscriptions.push(vscode.workspace.registerFileSystemProvider(Schemes.EmptyCommit, emptyCommitFileSystemProvider, { isReadonly: true }));
506503

507504
await init(context, apiImpl, credentialStore, repositories, prTree, liveshareApiPromise, showPRController, reposManager, createPrHelper, copilotRemoteAgentManager, themeWatcher, prsTreeModel);
508505
return apiImpl;

src/github/emptyCommitWebview.ts

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
import * as vscode from 'vscode';
7+
8+
/**
9+
* Opens a webview panel to display a message for an empty commit.
10+
* The message is centered and styled similar to GitHub.com.
11+
*/
12+
export function showEmptyCommitWebview(extensionUri: vscode.Uri, commitSha: string): void {
13+
const panel = vscode.window.createWebviewPanel(
14+
'emptyCommit',
15+
vscode.l10n.t('Commit {0}', commitSha.substring(0, 7)),
16+
vscode.ViewColumn.Active,
17+
{
18+
enableScripts: false,
19+
localResourceRoots: []
20+
}
21+
);
22+
23+
panel.webview.html = getEmptyCommitHtml();
24+
}
25+
26+
function getEmptyCommitHtml(): string {
27+
return `<!DOCTYPE html>
28+
<html lang="en">
29+
<head>
30+
<meta charset="UTF-8">
31+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
32+
<title>Empty Commit</title>
33+
<style>
34+
body {
35+
margin: 0;
36+
padding: 0;
37+
height: 100vh;
38+
display: flex;
39+
align-items: center;
40+
justify-content: center;
41+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
42+
background-color: var(--vscode-editor-background);
43+
color: var(--vscode-editor-foreground);
44+
}
45+
.container {
46+
text-align: center;
47+
padding: 2rem;
48+
}
49+
.message {
50+
font-size: 1.2rem;
51+
line-height: 1.6;
52+
color: var(--vscode-descriptionForeground);
53+
}
54+
</style>
55+
</head>
56+
<body>
57+
<div class="container">
58+
<div class="message">
59+
No changes to show.<br>
60+
This commit has no content.
61+
</div>
62+
</div>
63+
</body>
64+
</html>`;
65+
}

src/github/pullRequestModel.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import * as vscode from 'vscode';
1111
import { OctokitCommon } from './common';
1212
import { ConflictResolutionModel } from './conflictResolutionModel';
1313
import { CredentialStore } from './credentials';
14+
import { showEmptyCommitWebview } from './emptyCommitWebview';
1415
import { FolderRepositoryManager } from './folderRepositoryManager';
1516
import { GitHubRepository, GraphQLError, GraphQLErrorType } from './githubRepository';
1617
import {
@@ -89,7 +90,7 @@ import { Remote } from '../common/remote';
8990
import { DEFAULT_MERGE_METHOD, PR_SETTINGS_NAMESPACE } from '../common/settingKeys';
9091
import { ITelemetry } from '../common/telemetry';
9192
import { ClosedEvent, EventType, ReviewEvent, TimelineEvent } from '../common/timelineEvent';
92-
import { resolvePath, Schemes, toEmptyCommitUri, toGitHubCommitUri, toPRUri, toReviewUri } from '../common/uri';
93+
import { resolvePath, Schemes, toGitHubCommitUri, toPRUri, toReviewUri } from '../common/uri';
9394
import { formatError, isDescendant } from '../common/utils';
9495
import { InMemFileChangeModel, RemoteFileChangeModel } from '../view/fileChangeModel';
9596

@@ -1465,7 +1466,7 @@ export class PullRequestModel extends IssueModel<PullRequest> implements IPullRe
14651466
return vscode.commands.executeCommand('vscode.changes', vscode.l10n.t('Changes in Pull Request #{0}', pullRequestModel.number), args);
14661467
}
14671468

1468-
static async openCommitChanges(githubRepository: GitHubRepository, commitSha: string) {
1469+
static async openCommitChanges(extensionUri: vscode.Uri, githubRepository: GitHubRepository, commitSha: string) {
14691470
try {
14701471
const parentCommit = await githubRepository.getCommitParent(commitSha);
14711472
if (!parentCommit) {
@@ -1475,9 +1476,9 @@ export class PullRequestModel extends IssueModel<PullRequest> implements IPullRe
14751476

14761477
const changes = await githubRepository.compareCommits(parentCommit, commitSha);
14771478
if (!changes?.files || changes.files.length === 0) {
1478-
// Open a file showing the empty commit message instead of showing a notification
1479-
const emptyCommitUri = toEmptyCommitUri(commitSha);
1480-
return vscode.window.showTextDocument(emptyCommitUri, { preview: false });
1479+
// Show a webview with the empty commit message instead of a notification
1480+
showEmptyCommitWebview(extensionUri, commitSha);
1481+
return;
14811482
}
14821483

14831484
// Create URI pairs for the multi diff editor using review scheme

src/github/pullRequestOverview.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,7 @@ export class PullRequestOverviewPanel extends IssueOverviewPanel<PullRequestMode
554554
private async openCommitChanges(message: IRequestMessage<OpenCommitChangesArgs>): Promise<void> {
555555
try {
556556
const { commitSha } = message.args;
557-
await PullRequestModel.openCommitChanges(this._item.githubRepository, commitSha);
557+
await PullRequestModel.openCommitChanges(this._extensionUri, this._item.githubRepository, commitSha);
558558
this._replyMessage(message, {});
559559
} catch (error) {
560560
Logger.error(`Failed to open commit changes: ${formatError(error)}`, PullRequestOverviewPanel.ID);

src/view/emptyCommitFileSystemProvider.ts

Lines changed: 0 additions & 18 deletions
This file was deleted.

0 commit comments

Comments
 (0)