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' ;
77import { ChangeStore } from './changeStore' ;
88import { ContextStore } from './contextStore' ;
99import { VirtualFS } from './fs' ;
1010import { GitHubApiContext , GitHubApi } from './github/api' ;
1111import { GitHubFS } from './github/fs' ;
1212import { VirtualSCM } from './scm' ;
1313
14- // const repositoryRegex = /^(?:(?:https:\/\/)?github.com\/)?([^\/]+)\/([^\/]+?)(?:\/|.git|$)/i;
14+ const repositoryRegex = / ^ (?: (?: h t t p s : \/ \/ ) ? g i t h u b .c o m \/ ) ? ( [ ^ \/ ] + ) \/ ( [ ^ \/ ] + ?) (?: \/ | .g i t | $ ) / i;
1515
1616export 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
5050export 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