Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add command to create rascal location from selection #283

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions rascal-vscode-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,25 @@
{
"command": "rascalmpl.importMain",
"title": "Start Rascal Terminal and Import this module"
},
{
"command": "rascalmpl.copyLocation",
"title": "Copy Location of Selection to Clipboard"
}
],
"keybindings": [
{
"command": "rascalmpl.copyLocation",
"key": "shift+alt+l",
"mac": "shift+cmd+l"
}
],
"menus": {
"editor/context": [{
"command": "rascalmpl.copyLocation",
"group": "editor/context"
}]
},
"languages": [
{
"id": "rascalmpl",
Expand Down
26 changes: 26 additions & 0 deletions rascal-vscode-extension/src/RascalExtension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ export class RascalExtension implements vscode.Disposable {
this.registerMainRun();
this.registerImportModule();

this.registerCopyLocation();

vscode.window.registerTerminalLinkProvider(new RascalTerminalLinkProvider(this.rascal.rascalClient));
}

Expand Down Expand Up @@ -99,6 +101,30 @@ export class RascalExtension implements vscode.Disposable {
);
}


private registerCopyLocation() {
this.context.subscriptions.push(
vscode.commands.registerTextEditorCommand("rascalmpl.copyLocation", (text, _edit, moduleName) => {
const editor = vscode.window.activeTextEditor;
if (editor) {
const fileName = editor.document.uri.fsPath;
const selection = editor.selection;

let offset = editor.document.offsetAt(selection.start);
let length = editor.document.getText(selection).length;
let startLine = selection.start.line;
let startColumn = selection.start.character;
let endLine = selection.end.line;
let endColumn = selection.end.character;
linuswagner marked this conversation as resolved.
Show resolved Hide resolved

const location = `|file://${fileName}|(${offset},${length},<${startLine+1},${startColumn}>,<${endLine+1},${endColumn}>)`;
linuswagner marked this conversation as resolved.
Show resolved Hide resolved

vscode.env.clipboard.writeText(location);
}
})
)
}

private startTerminal(uri: vscode.Uri | undefined, ...extraArgs: string[]) {
return vscode.window.withProgress({
location: vscode.ProgressLocation.Notification,
Expand Down