Skip to content

Commit 3fadb63

Browse files
Fix some routine CodeLens issues (intersystems-community#1216)
1 parent 795a993 commit 3fadb63

File tree

2 files changed

+25
-16
lines changed

2 files changed

+25
-16
lines changed

src/extension.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1028,7 +1028,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<any> {
10281028
vscode.debug.registerDebugAdapterDescriptorFactory("objectscript", debugAdapterFactory),
10291029
debugAdapterFactory,
10301030
vscode.languages.registerCodeLensProvider(
1031-
documentSelector("objectscript-class", "objectscript"),
1031+
documentSelector("objectscript-class", "objectscript", "objectscript-int"),
10321032
new ObjectScriptCodeLensProvider()
10331033
),
10341034
vscode.commands.registerCommand("vscode-objectscript.compileOnly", () => compileOnly(false)),

src/providers/ObjectScriptCodeLensProvider.ts

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -81,26 +81,35 @@ export class ObjectScriptCodeLensProvider implements vscode.CodeLensProvider {
8181
return result;
8282
}
8383

84-
debugThisMethod && result.push(this.addDebugThisMethod(0, [`^${routineName}`, false]));
85-
copyToClipboard && result.push(this.addCopyToClipboard(0, [`^${routineName}`]));
86-
8784
const symbols: vscode.DocumentSymbol[] = await vscode.commands.executeCommand(
8885
"vscode.executeDocumentSymbolProvider",
8986
document.uri
9087
);
91-
symbols
92-
.filter((symbol) => symbol.kind === vscode.SymbolKind.Method)
93-
.forEach((symbol) => {
94-
const line = symbol.selectionRange.start.line;
95-
const labelMatch = document.lineAt(line).text.match(/^(\w[^(\n\s]+)(?:\(([^)]*)\))?/i);
96-
if (labelMatch) {
97-
const [, name, parens] = labelMatch;
98-
99-
debugThisMethod && result.push(this.addDebugThisMethod(line, [`${name}^${routineName}`, parens !== "()"]));
100-
copyToClipboard && result.push(this.addCopyToClipboard(line, [`${name}^${routineName}`]));
101-
}
102-
});
10388

89+
let labelledLine1 = false;
90+
if (symbols) {
91+
symbols
92+
.filter((symbol) => symbol.kind === vscode.SymbolKind.Method)
93+
.forEach((symbol) => {
94+
const line = symbol.selectionRange.start.line;
95+
const labelMatch = document.lineAt(line).text.match(/^(\w[^(\n\s]+)(?:\(([^)]*)\))?/i);
96+
if (labelMatch) {
97+
if (line === 1) {
98+
labelledLine1 = true;
99+
}
100+
const [, name, parens] = labelMatch;
101+
debugThisMethod &&
102+
result.push(this.addDebugThisMethod(line, [`${name}^${routineName}`, parens && parens !== "()"]));
103+
copyToClipboard && result.push(this.addCopyToClipboard(line, [`${name}^${routineName}`]));
104+
}
105+
});
106+
}
107+
108+
// Add lenses at the top only if the first code line had no label
109+
if (!labelledLine1) {
110+
debugThisMethod && result.push(this.addDebugThisMethod(0, [`^${routineName}`, false]));
111+
copyToClipboard && result.push(this.addCopyToClipboard(0, [`^${routineName}`]));
112+
}
104113
return result;
105114
}
106115

0 commit comments

Comments
 (0)