@@ -5,39 +5,49 @@ import * as vscode from 'vscode';
55// This method is called when your extension is activated
66// Your extension is activated the very first time the command is executed
77export function activate ( context : vscode . ExtensionContext ) {
8- function getItemPath ( projectPath : string , param : any ) : string | null
9- {
10- var targetFile = param . _resourceUri . fsPath . replace ( projectPath , '' ) ;
8+ function getRelativeItemPath ( projectPath : string , fullTargetFilePath : string ) : string | null {
9+ var relativeFilePath = fullTargetFilePath . replace ( projectPath , '' ) ;
1110 // remove first / or \
12- if ( targetFile [ 0 ] === '/' || targetFile [ 0 ] === '\\' ) {
13- targetFile = targetFile . slice ( 1 , targetFile . length ) ;
11+ if ( relativeFilePath [ 0 ] === '/' || relativeFilePath [ 0 ] === '\\' ) {
12+ relativeFilePath = relativeFilePath . slice ( 1 , relativeFilePath . length ) ;
1413 }
1514
16- return targetFile ;
15+ return relativeFilePath ;
1716 }
1817
1918 async function executeOperation (
2019 commandParam : any ,
2120 gitArgumentsFunc : ( targetFile : string ) => string [ ] ,
22- infoMessageFunc : ( targetFile : string ) => string ) {
21+ infoMessageFunc : ( targetFile : string ) => string ) : Promise < void > {
22+ const fullTargetFilePath : string = commandParam . resourceUri . fsPath ;
23+
2324 const simpleGit = await import ( 'simple-git' ) ;
2425 if ( vscode . workspace . workspaceFolders ) {
25- const projectPath = vscode . workspace . workspaceFolders [ 0 ] . uri . fsPath ;
26- var targetFile = getItemPath ( projectPath , commandParam ) ;
27- if ( targetFile === null ) {
28- vscode . window . showWarningMessage ( 'Could not get target path.' ) ;
29- return ;
30- }
26+ // Look through the workspace folders and find the one that has our file.
27+ for ( let workspaceFolder of vscode . workspace . workspaceFolders ) {
28+ const projectPath = workspaceFolder . uri . fsPath ;
29+ if ( fullTargetFilePath . startsWith ( projectPath ) ) {
30+ var targetFile = getRelativeItemPath ( projectPath , fullTargetFilePath ) ;
31+ if ( targetFile === null ) {
32+ vscode . window . showWarningMessage ( 'Could not get target path.' ) ;
33+ return ;
34+ }
35+
36+ vscode . window . showInformationMessage ( infoMessageFunc ( targetFile ) ) ;
37+
38+ simpleGit ( projectPath ) . raw (
39+ gitArgumentsFunc ( targetFile ) ,
40+ ( err : any , result : any ) => {
41+ if ( err ) {
42+ vscode . window . showWarningMessage ( err ) ;
43+ }
44+ } ) ;
45+
46+ return ;
47+ }
48+ }
3149
32- vscode . window . showInformationMessage ( infoMessageFunc ( targetFile ) ) ;
33-
34- simpleGit ( projectPath ) . raw (
35- gitArgumentsFunc ( targetFile ) ,
36- ( err : any , result : any ) => {
37- if ( err ) {
38- vscode . window . showWarningMessage ( err ) ;
39- }
40- } ) ;
50+ vscode . window . showWarningMessage ( 'Could not find workspace for ' + fullTargetFilePath ) ;
4151 }
4252 }
4353
0 commit comments