diff --git a/extension/package.json b/extension/package.json index 603ae52876..993f4c0a3c 100644 --- a/extension/package.json +++ b/extension/package.json @@ -191,6 +191,11 @@ "command": "dvc.removeTarget", "category": "DVC", "icon": "$(trash)" + }, + { + "title": "%command.copyFilePath%", + "command": "dvc.copyFilePath", + "category": "DVC" } ], "configuration": { @@ -311,6 +316,10 @@ { "command": "dvc.removeTarget", "when": "false" + }, + { + "command": "dvc.copyFilePath", + "when": "false" } ], "scm/title": [ @@ -420,6 +429,10 @@ "command": "dvc.pullTarget", "group": "DVC", "when": "viewItem != dvc" + }, + { + "command": "dvc.copyFilePath", + "group": "1_cutcopypaste" } ] }, diff --git a/extension/package.nls.json b/extension/package.nls.json index c0d46d57bb..84be2e6191 100644 --- a/extension/package.nls.json +++ b/extension/package.nls.json @@ -4,6 +4,7 @@ "command.addTarget": "Add Target", "command.checkout": "Checkout", "command.checkoutTarget": "Checkout Target", + "command.copyFilePath": "Copy Path", "command.commit": "Commit", "command.commitTarget": "Commit Target", "command.deleteTarget": "Delete", diff --git a/extension/src/extension.ts b/extension/src/extension.ts index 9eae948481..9339d5bad8 100644 --- a/extension/src/extension.ts +++ b/extension/src/extension.ts @@ -39,6 +39,7 @@ import { definedAndNonEmpty } from './util/array' import { setContextValue } from './vscode/context' import { OutputChannel } from './vscode/outputChannel' import { WebviewSerializer } from './webviewSerializer' +import { reRegisterVsCodeCommands } from './vscode/commands' export { Disposable, Disposer } @@ -147,6 +148,8 @@ export class Extension implements IExtension { registerRepositoryCommands(this.cliExecutor) this.registerConfigCommands() + + reRegisterVsCodeCommands(this.dispose) } public hasRoots = () => definedAndNonEmpty(this.dvcRoots) diff --git a/extension/src/test/suite/fileSystem/views/trackedExplorerTree.test.ts b/extension/src/test/suite/fileSystem/views/trackedExplorerTree.test.ts index 29a011e16c..0a6e3d0074 100644 --- a/extension/src/test/suite/fileSystem/views/trackedExplorerTree.test.ts +++ b/extension/src/test/suite/fileSystem/views/trackedExplorerTree.test.ts @@ -50,6 +50,15 @@ suite('Extension Test Suite', () => { }) describe('TrackedExplorerTree', () => { + it('should be able to run dvc.copyFilePath and copy a path to the clipboard', async () => { + await commands.executeCommand('dvc.copyFilePath', dvcDemoPath) + + await commands.executeCommand('workbench.action.files.newUntitledFile') + await commands.executeCommand('editor.action.clipboardPasteAction') + + expect(window.activeTextEditor?.document.getText()).to.equal(dvcDemoPath) + }) + it('should be able to run dvc.deleteTarget without error', async () => { const path = join(dvcDemoPath, 'deletable.txt') ensureFileSync(path) diff --git a/extension/src/vscode/commands.ts b/extension/src/vscode/commands.ts new file mode 100644 index 0000000000..80dbc7bff7 --- /dev/null +++ b/extension/src/vscode/commands.ts @@ -0,0 +1,10 @@ +import { Disposer } from '@hediet/std/disposable' +import { commands, Uri } from 'vscode' + +export const reRegisterVsCodeCommands = (disposer: Disposer) => { + disposer.track( + commands.registerCommand('dvc.copyFilePath', path => + commands.executeCommand('copyFilePath', Uri.file(path)) + ) + ) +}