Skip to content

Commit d6adf8a

Browse files
author
Eric Amodio
committed
Re-adds command
1 parent 697b702 commit d6adf8a

2 files changed

Lines changed: 33 additions & 24 deletions

File tree

extensions/github-browser/package.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@
2121
"main": "./out/extension.js",
2222
"contributes": {
2323
"commands": [
24+
{
25+
"command": "githubBrowser.openRepository",
26+
"title": "Open GitHub Repository...",
27+
"category": "GitHub Browser"
28+
},
2429
{
2530
"command": "githubBrowser.commit",
2631
"title": "Commit",
@@ -48,6 +53,10 @@
4853
],
4954
"menus": {
5055
"commandPalette": [
56+
{
57+
"command": "githubBrowser.openRepository",
58+
"when": "config.githubBrowser.openRepository"
59+
},
5160
{
5261
"command": "githubBrowser.commit",
5362
"when": "false"

extensions/github-browser/src/extension.ts

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import { ExtensionContext, Uri, workspace } from 'vscode';
6+
import { commands, ExtensionContext, Uri, window, workspace } from 'vscode';
77
import { ChangeStore } from './changeStore';
88
import { ContextStore } from './contextStore';
99
import { VirtualFS } from './fs';
1010
import { GitHubApiContext, GitHubApi } from './github/api';
1111
import { GitHubFS } from './github/fs';
1212
import { VirtualSCM } from './scm';
1313

14-
// const repositoryRegex = /^(?:(?:https:\/\/)?github.com\/)?([^\/]+)\/([^\/]+?)(?:\/|.git|$)/i;
14+
const repositoryRegex = /^(?:(?:https:\/\/)?github.com\/)?([^\/]+)\/([^\/]+?)(?:\/|.git|$)/i;
1515

1616
export function activate(context: ExtensionContext) {
1717
const contextStore = new ContextStore<GitHubApiContext>(context.workspaceState, GitHubFS.scheme);
@@ -28,23 +28,23 @@ export function activate(context: ExtensionContext) {
2828
new VirtualSCM(GitHubFS.scheme, githubApi, changeStore)
2929
);
3030

31-
// commands.registerCommand('githubBrowser.openRepository', async () => {
32-
// const value = await window.showInputBox({
33-
// placeHolder: 'e.g. https://github.com/microsoft/vscode',
34-
// prompt: 'Enter a GitHub repository url',
35-
// validateInput: value => repositoryRegex.test(value) ? undefined : 'Invalid repository url'
36-
// });
31+
commands.registerCommand('githubBrowser.openRepository', async () => {
32+
const value = await window.showInputBox({
33+
placeHolder: 'e.g. https://github.com/microsoft/vscode',
34+
prompt: 'Enter a GitHub repository url',
35+
validateInput: value => repositoryRegex.test(value) ? undefined : 'Invalid repository url'
36+
});
3737

38-
// if (value) {
39-
// const match = repositoryRegex.exec(value);
40-
// if (match) {
41-
// const [, owner, repo] = match;
38+
if (value) {
39+
const match = repositoryRegex.exec(value);
40+
if (match) {
41+
const [, owner, repo] = match;
4242

43-
// const uri = Uri.parse(`codespace://HEAD/${owner}/${repo}`);
44-
// openWorkspace(uri, repo, 'currentWindow');
45-
// }
46-
// }
47-
// });
43+
const uri = Uri.parse(`codespace://HEAD/${owner}/${repo}`);
44+
openWorkspace(uri, repo, 'currentWindow');
45+
}
46+
}
47+
});
4848
}
4949

5050
export function getRelativePath(rootUri: Uri, uri: Uri) {
@@ -63,11 +63,11 @@ export function isDescendent(folderPath: string, filePath: string) {
6363
return folderPath.length === 0 || filePath.startsWith(folderPath.endsWith('/') ? folderPath : `${folderPath}/`);
6464
}
6565

66-
// function openWorkspace(uri: Uri, name: string, location: 'currentWindow' | 'newWindow' | 'addToCurrentWorkspace') {
67-
// if (location === 'addToCurrentWorkspace') {
68-
// const count = (workspace.workspaceFolders && workspace.workspaceFolders.length) || 0;
69-
// return workspace.updateWorkspaceFolders(count, 0, { uri: uri, name: name });
70-
// }
66+
function openWorkspace(uri: Uri, name: string, location: 'currentWindow' | 'newWindow' | 'addToCurrentWorkspace') {
67+
if (location === 'addToCurrentWorkspace') {
68+
const count = (workspace.workspaceFolders && workspace.workspaceFolders.length) || 0;
69+
return workspace.updateWorkspaceFolders(count, 0, { uri: uri, name: name });
70+
}
7171

72-
// return commands.executeCommand('vscode.openFolder', uri, location === 'newWindow');
73-
// }
72+
return commands.executeCommand('vscode.openFolder', uri, location === 'newWindow');
73+
}

0 commit comments

Comments
 (0)