Skip to content

Commit a7d7b2b

Browse files
committed
commas respectively to params count
1 parent 3c76b3c commit a7d7b2b

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

src/providers/ObjectScriptCodeLensProvider.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export class ObjectScriptCodeLensProvider implements vscode.CodeLensProvider {
2828
const className = file.name.split(".").slice(0, -1).join(".");
2929

3030
const { debugThisMethod, copyToClipboard } = config("debug");
31+
const pattern = /(?:^ClassMethod\s)([^(]+)\(((?:[^()]|\([^()]*\)|{[^{}]*})*)\)/i;
3132
let inComment = false;
3233
for (let i = 0; i < document.lineCount; i++) {
3334
const line = document.lineAt(i);
@@ -44,12 +45,18 @@ export class ObjectScriptCodeLensProvider implements vscode.CodeLensProvider {
4445
continue;
4546
}
4647

47-
const methodMatch = text.match(/(?<=^ClassMethod\s)([^(]+)(\(.)/i);
48+
const methodMatch = text.match(pattern);
4849
if (methodMatch) {
49-
const [, name, parens] = methodMatch;
50-
51-
debugThisMethod && result.push(this.addDebugThisMethod(i, [`##class(${className}).${name}`, parens !== "()"]));
52-
copyToClipboard && result.push(this.addCopyToClipboard(i, [`##class(${className}).${name}()`]));
50+
const [, name, paramsRaw] = methodMatch;
51+
let params = paramsRaw;
52+
params = params.replace(/"[^"]*"/g, '""');
53+
params = params.replace(/{[^{}]*}|{[^{}]*{[^{}]*}[^{}]*}/g, '""');
54+
params = params.replace(/\([^()]*\)/g, "");
55+
const paramsCount = params.length ? params.split(",").length : 0;
56+
57+
debugThisMethod && result.push(this.addDebugThisMethod(i, [`##class(${className}).${name}`, paramsCount > 0]));
58+
copyToClipboard &&
59+
result.push(this.addCopyToClipboard(i, [`##class(${className}).${name}(${Array(paramsCount).join(",")})`]));
5360
}
5461
}
5562
return result;
@@ -99,15 +106,15 @@ export class ObjectScriptCodeLensProvider implements vscode.CodeLensProvider {
99106

100107
private addDebugThisMethod(line: number, args: any[]) {
101108
return new vscode.CodeLens(new vscode.Range(line, 0, line, 80), {
102-
title: `Debug this method`,
109+
title: `Debug this Method`,
103110
command: "vscode-objectscript.debug",
104111
arguments: args,
105112
});
106113
}
107114

108115
private addCopyToClipboard(line: number, args: any[]) {
109116
return new vscode.CodeLens(new vscode.Range(line, 0, line, 80), {
110-
title: `Copy Invocation to Clipboard`,
117+
title: `Copy Invocation`,
111118
command: "vscode-objectscript.copyToClipboard",
112119
arguments: args,
113120
});

0 commit comments

Comments
 (0)