diff --git a/rascal-vscode-extension/package.json b/rascal-vscode-extension/package.json index 57cbed1dd..5935c4958 100644 --- a/rascal-vscode-extension/package.json +++ b/rascal-vscode-extension/package.json @@ -52,6 +52,11 @@ "command": "rascalmpl.startDebuggerForRepl", "title": "Start Rascal debugger for REPL", "icon": "$(debug)" + }, + { + "command": "rascalmpl.copySourceLocation", + "title": "Copy Path as Rascal Location", + "icon": "$(copy)" } ], "menus": { @@ -59,6 +64,10 @@ { "command": "rascalmpl.startDebuggerForRepl", "when": "false" + }, + { + "command": "rascalmpl.copySourceLocation", + "when": "false" } ], "view/item/context": [ @@ -67,6 +76,12 @@ "when": "view == rascalmpl-debugger-view && viewItem == 'canStartDebugging'", "group": "inline" } + ], + "explorer/context": [ + { + "command": "rascalmpl.copySourceLocation", + "group": "6_copypath@21" + } ] }, "languages": [ diff --git a/rascal-vscode-extension/src/RascalExtension.ts b/rascal-vscode-extension/src/RascalExtension.ts index f3b5c41a7..f9ca72518 100644 --- a/rascal-vscode-extension/src/RascalExtension.ts +++ b/rascal-vscode-extension/src/RascalExtension.ts @@ -28,7 +28,7 @@ import * as os from 'os'; import * as path from 'path'; import * as vscode from 'vscode'; -import { integer } from'vscode-languageclient'; +import { integer, URI } from'vscode-languageclient'; import { checkForJVMUpdate, getJavaExecutable } from './auto-jvm/JavaLookup'; import { RascalLanguageServer } from './lsp/RascalLanguageServer'; import { LanguageParameter, ParameterizedLanguageServer } from './lsp/ParameterizedLanguageServer'; @@ -53,6 +53,7 @@ export class RascalExtension implements vscode.Disposable { this.registerTerminalCommand(); this.registerMainRun(); this.registerImportModule(); + this.registerCopySourceLocationCommand(); checkForJVMUpdate(); vscode.window.registerTreeDataProvider('rascalmpl-configuration-view', new RascalLibraryProvider(this.rascal.rascalClient)); @@ -105,6 +106,15 @@ export class RascalExtension implements vscode.Disposable { ); } + private registerCopySourceLocationCommand() { + this.context.subscriptions.push( + vscode.commands.registerCommand("rascalmpl.copySourceLocation", async (uri: URI) => { + const rascalUri = `|${decodeURIComponent(uri)}|`; + await vscode.env.clipboard.writeText(rascalUri); + }) + ); + } + private async startTerminal(uri: vscode.Uri | undefined, command?: string | undefined) { try { await vscode.window.withProgress({