Skip to content

Commit 47ae26f

Browse files
authored
Improve #1503 (#1517)
1 parent 00bc6ed commit 47ae26f

File tree

1 file changed

+22
-18
lines changed

1 file changed

+22
-18
lines changed

src/providers/ObjectScriptCodeLensProvider.ts

+22-18
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ const poundImportRegex = /^\s*#import\s+(.+)$/i;
1212
const poundIncludeRegex = /^\s*#include\s+(\S+)\s*$/i;
1313
const sqlSelectRegex = /^\s*#sqlcompile\s+select\s*=\s*(\S+)\s*$/i;
1414
const commentRegex = /(?:^|(?:[^"]*"[^"]*")*)(\/\/|;|\/\*)/;
15-
const rtnProcedureRegex = /^\(([^)]*)\)\s*(?:\[[^\]]*\])?\s*public/i;
15+
const rtnIsDebuggableRegex = /^\(([^)]*)\)(?:(?:(?:\[[^\]]*\])?public{)|(?!private|methodimpl|{|\[]))/i;
16+
const whitespaceAndCCommentsRegex = /\/\*[\s\S]*?\*\/|\s+/g;
1617

1718
/**
1819
* Extract the text of the Embedded SQL query starting at `[startLine,StartChar]`.
@@ -335,13 +336,6 @@ export class ObjectScriptCodeLensProvider implements vscode.CodeLensProvider {
335336
}
336337

337338
const displayName = quoteClassMemberName(symbol.name);
338-
if (
339-
!isPrivate &&
340-
copyToClipboard &&
341-
(type == "classmethod" || (type == "query" && displayName[0] != '"'))
342-
) {
343-
result.push(this.addCopyToClipboard(symbolLine, [`##class(${className}).${displayName}()`]));
344-
}
345339
if (
346340
!isPrivate &&
347341
debugThisMethod &&
@@ -356,6 +350,13 @@ export class ObjectScriptCodeLensProvider implements vscode.CodeLensProvider {
356350
])
357351
);
358352
}
353+
if (
354+
!isPrivate &&
355+
copyToClipboard &&
356+
(type == "classmethod" || (type == "query" && displayName[0] != '"'))
357+
) {
358+
result.push(this.addCopyToClipboard(symbolLine, [`##class(${className}).${displayName}()`]));
359+
}
359360
}
360361
}
361362
});
@@ -366,24 +367,27 @@ export class ObjectScriptCodeLensProvider implements vscode.CodeLensProvider {
366367
if (symbols && (debugThisMethod || copyToClipboard)) {
367368
symbols.forEach((symbol) => {
368369
const line = symbol.selectionRange.start.line;
369-
const restOfLine = document.lineAt(line).text.slice(symbol.name.length);
370+
const restOfSymbol = document.getText(symbol.range).slice(symbol.name.length);
370371
let hasArgs = false,
371-
isProc = false;
372-
if (restOfLine[0] == "(") {
373-
// Make sure this is a public procedure, and extract the argument list
374-
const procMatch = restOfLine.match(rtnProcedureRegex);
375-
if (procMatch) {
376-
isProc = true;
377-
hasArgs = procMatch[1].length > 0;
372+
hasArgList = false;
373+
if (restOfSymbol[0] == "(") {
374+
const rtnDebuggableMatch = restOfSymbol
375+
// Replace all whitespace and C-Style comments
376+
.replace(whitespaceAndCCommentsRegex, "")
377+
.match(rtnIsDebuggableRegex);
378+
// Extract the argument list
379+
if (rtnDebuggableMatch) {
380+
hasArgList = true;
381+
hasArgs = rtnDebuggableMatch[1].length > 0;
378382
} else {
379-
// This is not a syntactically valid public procedure
383+
// This is not a syntactically valid public procedure or subroutine
380384
return;
381385
}
382386
}
383387
if (line == 1) labeledLine1 = true;
384388
if (debugThisMethod) result.push(this.addDebugThisMethod(line, [`${symbol.name}^${routineName}`, hasArgs]));
385389
if (copyToClipboard) {
386-
result.push(this.addCopyToClipboard(line, [`${symbol.name}^${routineName}${isProc ? "()" : ""}`]));
390+
result.push(this.addCopyToClipboard(line, [`${symbol.name}^${routineName}${hasArgList ? "()" : ""}`]));
387391
}
388392
});
389393
}

0 commit comments

Comments
 (0)