Skip to content

Commit

Permalink
feat: add escape command
Browse files Browse the repository at this point in the history
  • Loading branch information
Chronostasys committed Apr 23, 2024
1 parent cd6f5a1 commit a31b1e6
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to the "pivot-lang-support" extension will be documented in

Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file.

## [0.0.23]

- add escape analysis command

## [0.0.22]

- support match keyword
Expand Down
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "pivot-lang-support",
"displayName": "pivot-lang support",
"description": "",
"version": "0.0.22",
"version": "0.0.23",
"publisher": "pivot-langAuthors",
"license": "MIT",
"repository": {
Expand Down Expand Up @@ -84,6 +84,11 @@
"title": "Restart pivot-lang Language server",
"category": "pivot-lang"
},
{
"command": "pivot-lang.analyze_escape",
"title": "Analyse variable allocate location",
"category": "pivot-lang"
},
{
"command": "pivot-lang.debug_current",
"title": "Debug current pivot-lang project",
Expand Down
49 changes: 49 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,21 @@ import { openStdin } from 'process';
import { workspace, ExtensionContext, WorkspaceFolder, DebugConfiguration, CancellationToken, ProviderResult } from 'vscode';
import * as os from 'os';
import * as vscode from "vscode";
import * as cp from "child_process";

const execShell = (cmd: string) =>
new Promise<string>((resolve, reject) => {
cp.exec(cmd, {
cwd: vscode.workspace.workspaceFolders?.[0].uri.fsPath,
}, (err, out) => {
if (err) {
return reject(err);
//or, reject(err);
}
return resolve(out);
});
});


const myExtDir = vscode.extensions.getExtension("pivot-langauthors.pivot-lang-support").extensionPath;

Expand Down Expand Up @@ -87,6 +102,40 @@ export function activate(context: ExtensionContext) {
program: vscode.window.activeTextEditor.document.uri.fsPath,
});
});
vscode.commands.registerCommand("pivot-lang.analyze_escape", async () => {
// start a status bar, spinning
let status = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Right);
status.text = "$(sync~spin) Analyzing escape";
status.show();
try {
let outfile = os.tmpdir() + "/pivot-lang-esacpe" + Math.random().toString(36).substring(7);
let out = await execShell("plc -v 0 " + vscode.window.activeTextEditor.document.uri.fsPath + ` -o ${outfile} --pstack`);
let lines = out.split('\n');
// for each location, highlight the code, and show a diagnostic
// every line is like: "variable moved to stack: `i` at /Users/bobli/src/pivot-lang/planglib/std/cols/arr.pi:98:17"
for (let line of lines) {
let match = line.match(/`(.*)` at (.+):(\d+):(\d+)/);
if (match) {
let [_, variable, file, line, col] = match;
let range = new vscode.Range(new vscode.Position(parseInt(line) - 1, parseInt(col) - 1), new vscode.Position(parseInt(line) - 1, parseInt(col) + variable.length - 1));
// hilight the code if the file is open
let active = vscode.window.visibleTextEditors.find(e => e.document.uri.fsPath == file);
if (active) {
active.setDecorations(vscode.window.createTextEditorDecorationType({
color: "green",
borderRadius: "2px"
}), [range]);
}

}
}
} catch (error) {
vscode.window.showErrorMessage("Error analyzing escape: " + error);
}
// stop the status bar
status.dispose();

});

vscode.commands.registerCommand("pivot-lang.run_current", async () => {
let fspath = vscode.window.activeTextEditor.document.uri.fsPath;
Expand Down

0 comments on commit a31b1e6

Please sign in to comment.