From d6adf8aaf2d026bc5abbf78bbfecc35d949772c2 Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Thu, 2 Jul 2020 03:49:04 -0400 Subject: [PATCH] Re-adds command --- extensions/github-browser/package.json | 9 ++++ extensions/github-browser/src/extension.ts | 48 +++++++++++----------- 2 files changed, 33 insertions(+), 24 deletions(-) diff --git a/extensions/github-browser/package.json b/extensions/github-browser/package.json index 6e3c071b70e..9938e25ed54 100644 --- a/extensions/github-browser/package.json +++ b/extensions/github-browser/package.json @@ -21,6 +21,11 @@ "main": "./out/extension.js", "contributes": { "commands": [ + { + "command": "githubBrowser.openRepository", + "title": "Open GitHub Repository...", + "category": "GitHub Browser" + }, { "command": "githubBrowser.commit", "title": "Commit", @@ -48,6 +53,10 @@ ], "menus": { "commandPalette": [ + { + "command": "githubBrowser.openRepository", + "when": "config.githubBrowser.openRepository" + }, { "command": "githubBrowser.commit", "when": "false" diff --git a/extensions/github-browser/src/extension.ts b/extensions/github-browser/src/extension.ts index 63cb1441a48..8a454c693b1 100644 --- a/extensions/github-browser/src/extension.ts +++ b/extensions/github-browser/src/extension.ts @@ -3,7 +3,7 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { ExtensionContext, Uri, workspace } from 'vscode'; +import { commands, ExtensionContext, Uri, window, workspace } from 'vscode'; import { ChangeStore } from './changeStore'; import { ContextStore } from './contextStore'; import { VirtualFS } from './fs'; @@ -11,7 +11,7 @@ import { GitHubApiContext, GitHubApi } from './github/api'; import { GitHubFS } from './github/fs'; import { VirtualSCM } from './scm'; -// const repositoryRegex = /^(?:(?:https:\/\/)?github.com\/)?([^\/]+)\/([^\/]+?)(?:\/|.git|$)/i; +const repositoryRegex = /^(?:(?:https:\/\/)?github.com\/)?([^\/]+)\/([^\/]+?)(?:\/|.git|$)/i; export function activate(context: ExtensionContext) { const contextStore = new ContextStore(context.workspaceState, GitHubFS.scheme); @@ -28,23 +28,23 @@ export function activate(context: ExtensionContext) { new VirtualSCM(GitHubFS.scheme, githubApi, changeStore) ); - // commands.registerCommand('githubBrowser.openRepository', async () => { - // const value = await window.showInputBox({ - // placeHolder: 'e.g. https://github.com/microsoft/vscode', - // prompt: 'Enter a GitHub repository url', - // validateInput: value => repositoryRegex.test(value) ? undefined : 'Invalid repository url' - // }); + commands.registerCommand('githubBrowser.openRepository', async () => { + const value = await window.showInputBox({ + placeHolder: 'e.g. https://github.com/microsoft/vscode', + prompt: 'Enter a GitHub repository url', + validateInput: value => repositoryRegex.test(value) ? undefined : 'Invalid repository url' + }); - // if (value) { - // const match = repositoryRegex.exec(value); - // if (match) { - // const [, owner, repo] = match; + if (value) { + const match = repositoryRegex.exec(value); + if (match) { + const [, owner, repo] = match; - // const uri = Uri.parse(`codespace://HEAD/${owner}/${repo}`); - // openWorkspace(uri, repo, 'currentWindow'); - // } - // } - // }); + const uri = Uri.parse(`codespace://HEAD/${owner}/${repo}`); + openWorkspace(uri, repo, 'currentWindow'); + } + } + }); } export function getRelativePath(rootUri: Uri, uri: Uri) { @@ -63,11 +63,11 @@ export function isDescendent(folderPath: string, filePath: string) { return folderPath.length === 0 || filePath.startsWith(folderPath.endsWith('/') ? folderPath : `${folderPath}/`); } -// function openWorkspace(uri: Uri, name: string, location: 'currentWindow' | 'newWindow' | 'addToCurrentWorkspace') { -// if (location === 'addToCurrentWorkspace') { -// const count = (workspace.workspaceFolders && workspace.workspaceFolders.length) || 0; -// return workspace.updateWorkspaceFolders(count, 0, { uri: uri, name: name }); -// } +function openWorkspace(uri: Uri, name: string, location: 'currentWindow' | 'newWindow' | 'addToCurrentWorkspace') { + if (location === 'addToCurrentWorkspace') { + const count = (workspace.workspaceFolders && workspace.workspaceFolders.length) || 0; + return workspace.updateWorkspaceFolders(count, 0, { uri: uri, name: name }); + } -// return commands.executeCommand('vscode.openFolder', uri, location === 'newWindow'); -// } + return commands.executeCommand('vscode.openFolder', uri, location === 'newWindow'); +}