Skip to content

Commit b179283

Browse files
committed
quickly debug classmethod by action from code
1 parent a765222 commit b179283

File tree

3 files changed

+100
-1
lines changed

3 files changed

+100
-1
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,7 @@
580580
"properties": {
581581
"program": {
582582
"type": "string",
583-
"description": "Absolute path to the program."
583+
"description": "Class or routine to debug."
584584
}
585585
}
586586
},

src/extension.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import { ObjectScriptDefinitionProvider } from "./providers/ObjectScriptDefiniti
2626
import { ObjectScriptFoldingRangeProvider } from "./providers/ObjectScriptFoldingRangeProvider";
2727
import { ObjectScriptHoverProvider } from "./providers/ObjectScriptHoverProvider";
2828
import { ObjectScriptRoutineSymbolProvider } from "./providers/ObjectScriptRoutineSymbolProvider";
29+
import { ObjectScriptClassCodeLensProvider } from "./providers/ObjectScriptClassCodeLensProvider";
2930
import { XmlContentProvider } from "./providers/XmlContentProvider";
3031

3132
import { StatusCodeError } from "request-promise/errors";
@@ -184,6 +185,28 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
184185
vscode.commands.registerCommand("vscode-objectscript.compileAllWithFlags", () => namespaceCompile(true)),
185186
vscode.commands.registerCommand("vscode-objectscript.compileFolder", importFileOrFolder),
186187
vscode.commands.registerCommand("vscode-objectscript.export", exportAll),
188+
vscode.commands.registerCommand("vscode-objectscript.debug", (program: string, askArgs: boolean) => {
189+
const startDebugging = args => {
190+
const programWithArgs = program + `(${args})`;
191+
vscode.debug.startDebugging(undefined, {
192+
type: "objectscript",
193+
request: "launch",
194+
name: `Debug ${program}`,
195+
program: programWithArgs,
196+
});
197+
};
198+
if (!askArgs) {
199+
startDebugging("");
200+
return;
201+
}
202+
return vscode.window
203+
.showInputBox({
204+
placeHolder: "Please enter comma delimited arguments list",
205+
})
206+
.then(args => {
207+
startDebugging(args);
208+
});
209+
}),
187210
vscode.commands.registerCommand("vscode-objectscript.pickProcess", async config => {
188211
const system = config.system;
189212
const api = new AtelierAPI();
@@ -282,6 +305,10 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
282305
vscode.debug.registerDebugConfigurationProvider("objectscript", new ObjectScriptConfigurationProvider()),
283306
vscode.debug.registerDebugAdapterDescriptorFactory("objectscript", debugAdapterFactory),
284307
debugAdapterFactory,
308+
vscode.languages.registerCodeLensProvider(
309+
documentSelector("objectscript-class"),
310+
new ObjectScriptClassCodeLensProvider()
311+
),
285312

286313
/* from proposed api */
287314
vscode.workspace.registerFileSearchProvider(FILESYSTEM_SCHEMA, new FileSearchProvider()),
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import * as vscode from "vscode";
2+
3+
export class ObjectScriptClassCodeLensProvider implements vscode.CodeLensProvider {
4+
public provideCodeLenses(
5+
document: vscode.TextDocument,
6+
token: vscode.CancellationToken
7+
): vscode.ProviderResult<vscode.CodeLens[]> {
8+
const result = new Array<vscode.CodeLens>();
9+
10+
const isClass = document.fileName.toLowerCase().endsWith(".cls");
11+
12+
if (isClass) {
13+
result.push(...this.classMethods(document));
14+
}
15+
return result;
16+
}
17+
18+
private classMethods(document: vscode.TextDocument): vscode.CodeLens[] {
19+
const result = new Array<vscode.CodeLens>();
20+
21+
let inComment = false;
22+
let className = "";
23+
for (let i = 0; i < document.lineCount; i++) {
24+
const line = document.lineAt(i);
25+
const text = this.stripLineComments(line.text);
26+
27+
if (text.match(/\/\*/)) {
28+
inComment = true;
29+
}
30+
31+
if (inComment) {
32+
if (text.match(/\*\//)) {
33+
inComment = false;
34+
}
35+
continue;
36+
}
37+
if (!className.length) {
38+
const classNameMatch = text.match(/(?<=^Class\s)[^ ]+/i);
39+
if (classNameMatch) {
40+
[className] = classNameMatch;
41+
}
42+
}
43+
const methodMatch = text.match(/(?<=^ClassMethod\s)([^(]+)(\(.)/i);
44+
if (methodMatch) {
45+
const [, name, parens] = methodMatch;
46+
const program = `##class(${className}).${name}`;
47+
const askArgs = parens !== "()";
48+
result.push(
49+
new vscode.CodeLens(
50+
new vscode.Range(
51+
new vscode.Position(i, methodMatch.index),
52+
new vscode.Position(i, methodMatch.index + name.length)
53+
),
54+
{
55+
title: `Debug this method`,
56+
command: "vscode-objectscript.debug",
57+
arguments: [program, askArgs],
58+
}
59+
)
60+
);
61+
}
62+
}
63+
return result;
64+
}
65+
66+
private stripLineComments(text: string) {
67+
text = text.replace(/\/\/.*$/, "");
68+
text = text.replace(/#+;.*$/, "");
69+
text = text.replace(/;.*$/, "");
70+
return text;
71+
}
72+
}

0 commit comments

Comments
 (0)