diff --git a/src/extension.js b/src/extension.js index d2722b6..7acf3d4 100644 --- a/src/extension.js +++ b/src/extension.js @@ -29,6 +29,7 @@ class MyDataProvider { if (element) { if (element instanceof FileItem) { return Promise.resolve(element.files.map(file => { + file = file.trim().slice(2).replace(" ", ""); let fileName = path.basename(file); const item = new vscode.TreeItem(fileName); const extension = path.extname(file).slice(1); @@ -38,10 +39,13 @@ class MyDataProvider { if (!fs.existsSync(item.iconPath)) { item.iconPath = __dirname + '/icons/file_type_default.svg'; } + + const absoluteFilePath = path.join(vscode.workspace.rootPath, file); + item.tooltip = absoluteFilePath; item.command = { command: 'vscode.open', - arguments: [vscode.Uri.file(path.join(this.workspaceRoot, file))], + arguments: [vscode.Uri.file(absoluteFilePath)], title: 'Open File' }; @@ -69,33 +73,11 @@ class MyDataProvider { const item3 = new vscode.TreeItem(''); - const item4 = new vscode.TreeItem('Commit Staged files '); - item4.iconPath = new vscode.ThemeIcon('play'); - item4.command = { - command: 'wmc.commit', - title: 'Commit Staged files', - arguments: [] - }; - - const item5 = new vscode.TreeItem(''); - - if (!this.workspaceRoot) { - vscode.window.showInformationMessage('No data'); + if (!this.workspaceRoot) { + vscode.window.showInformationMessage('No data'); const item6 = new vscode.TreeItem('No data, please try to open a git repository'); - return Promise.resolve([item1, item2, item3, item4, item5, item6]); - } - - const stagedFilesPromise = new Promise((resolve, reject) => { - cp.exec('git diff --name-only --cached', { cwd: this.workspaceRoot }, (err, stdout) => { - if (err) { - console.error(err); - resolve(new vscode.TreeItem('Oops, something went wrong')); - } else { - const files = stdout.split('\n').filter(file => !!file); - resolve(new FileItem('Staged Files', files)); - } - }); - }); + return Promise.resolve([item1, item2, item3]); + } const modifiedFilesPromise = new Promise((resolve, reject) => { cp.exec('git status --short', { cwd: this.workspaceRoot }, (err, stdout) => { @@ -109,7 +91,7 @@ class MyDataProvider { }); }); - return Promise.all([Promise.resolve(item1), Promise.resolve(item2), Promise.resolve(item3), Promise.resolve(item4), Promise.resolve(item5), stagedFilesPromise, modifiedFilesPromise]); + return Promise.all([Promise.resolve(item1), Promise.resolve(item2), Promise.resolve(item3), modifiedFilesPromise]); } } } @@ -137,14 +119,13 @@ function activate(context) { const commitMessageFormat = vscode.workspace.getConfiguration('writemycommits').get('commitMessageFormat'); const commitMessage = commitMessageFormat - .replace('{type}', type) - .replace('{scope}', scope) - .replace('{message}', description) - .replace('{breakingChange}', isBreakingChange ? '!' : ''); - return commitMessage; + .replace('{type}', type) + .replace('{scope}', scope) + .replace('{message}', description) + .replace('{breakingChange}', isBreakingChange ? '!' : ''); - // await vscode.env.clipboard.writeText(commitMessage); - // vscode.window.showInformationMessage('Commit name copied to clipboard'); + await vscode.env.clipboard.writeText(commitMessage); + vscode.window.showInformationMessage('Commit name copied to clipboard'); }); const getUserInputFullCommand = vscode.commands.registerCommand('writemycommits.getUserInputFull', async () => { @@ -157,34 +138,13 @@ function activate(context) { isBreakingChange === 'Yes' ? isBreakingChange = true : isBreakingChange = false; const commitMessage = `${type}${scope ? `(${scope})` : ''}${isBreakingChange ? '!' : ''}: ${description}${body ? `\n\n${body}` : ''}${footer ? `\n\n${isBreakingChange ? 'BREAKING CHANGE : ' : ''}${footer}` : ''}`; - // await vscode.env.clipboard.writeText(commitMessage); - // vscode.window.showInformationMessage('Commit message copied to clipboard'); - }); - - const commitCommand = vscode.commands.registerCommand('wmc.commit', async () => { - const message = await vscode.commands.executeCommand('writemycommits.getUserInput'); - const valid = await vscode.window.showQuickPick(['Yes', 'No'], { placeHolder: 'Do you want to commit "' + message + '" ?' }); - if (valid === 'Yes') { - cp.exec('git commit -m"' + String(message) + '"', { cwd: vscode.workspace.workspaceFolders[0].uri.fsPath }, (err, stdout, stderr) => { - if (err) { - console.error(err); - vscode.window.showErrorMessage('Error: ' + stderr); - } else { - vscode.window.showInformationMessage('Commit successful'); - } - }) - } - }); - - const docCommand = vscode.commands.registerCommand('writemycommits.getDoc', async () => { - vscode.env.openExternal(vscode.Uri.parse('https://www.conventionalcommits.org/en/v1.0.0/')); + await vscode.env.clipboard.writeText(commitMessage); + vscode.window.showInformationMessage('Commit message copied to clipboard'); }); context.subscriptions.push(getUserInputCommand); context.subscriptions.push(getUserInputFullCommand); - context.subscriptions.push(commitCommand); - context.subscriptions.push(docCommand); - context.subscriptions.push(refreshCommand); + context.subscriptions.push(refreshCommand); } exports.activate = activate;