Skip to content

Commit bc300f9

Browse files
authored
Improve CodeLenses (#1007)
1 parent 469528c commit bc300f9

File tree

3 files changed

+37
-43
lines changed

3 files changed

+37
-43
lines changed

docs/SettingsReference.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,10 @@ The extensions in the InterSystems ObjectScript Extension Pack provide many sett
4848
| `"objectscript.conn.server"` | InterSystems server's name in Server Manager settings from which to get connection info. | `string` | `undefined` | Specify only `ns` and `active` when using this setting. See the [Server Manager README](https://github.com/intersystems-community/intersystems-servermanager) for more details. |
4949
| `"objectscript.conn.docker-compose"` | Configures the active server port using information from a file which must be named `docker-compose.yml` in the project's root directory. | `object` | `undefined` | |
5050
| `"objectscript.conn.docker-compose.service"` | InterSystems service's name in `docker-compose.yml`. | `string` | `undefined` | |
51-
| `"objectscript.conn.docker-compose .internalPort"` | InterSystems service's internal port in `docker-compose.yml`. | `object` | `undefined` | This should almost always be 52773 unless your IRIS server is configured in a non-standard way|
52-
| `"objectscript.debug.debugThisMethod"` | Show inline `Debug this method` CodeLens action for ClassMethods. | `boolean` | `true` | |
53-
| `"objectscript.explorer .alwaysShowServerCopy"` | Always show the server copy of a document in the ObjectScript Explorer. | `boolean` | `false` | |
51+
| `"objectscript.conn.docker-compose.internalPort"` | InterSystems service's internal port in `docker-compose.yml`. | `object` | `undefined` | This should almost always be 52773 unless your IRIS server is configured in a non-standard way |
52+
| `"objectscript.debug.copyToClipboard"` | Show inline `Copy Invocation` CodeLens action for ClassMethods and Routine Labels. | `boolean` | `true` | |
53+
| `"objectscript.debug.debugThisMethod"` | Show inline `Debug` CodeLens action for ClassMethods and Routine Labels. | `boolean` | `true` | |
54+
| `"objectscript.explorer.alwaysShowServerCopy"` | Always show the server copy of a document in the ObjectScript Explorer. | `boolean` | `false` | |
5455
| `"objectscript.export.addCategory"` | Add a category folder to the beginning of the export path. | `boolean` or `object` | `false` | |
5556
| `"objectscript.export.atelier"` | Export source code as Atelier did it, with packages as subfolders. | `boolean` | `true` | This setting only affects classes, routines, include files and DFI files. |
5657
| `"objectscript.export.category"` | Category of source code to export: `CLS` = classes; `RTN` = routines; `CSP` = csp files; `OTH` = other. Default is `*` = all. | `string` or `object` | `"*"` | |
@@ -61,7 +62,7 @@ The extensions in the InterSystems ObjectScript Extension Pack provide many sett
6162
| `"objectscript.export.generated"` | Export generated source code files, such as INTs generated from classes. | `boolean` | `false` | |
6263
| `"objectscript.export.map"` | Map file names before export, with regexp pattern as a key and replacement as a value. | `object` | `{}` | For example, `{ \"%(.*)\": \"_$1\" }` to make % classes or routines use underscore prefix instead. |
6364
| `"objectscript.export.mapped"` | Export source code files mapped from a non-default database. | `boolean` | `true` | |
64-
| `"objectscript.export .maxConcurrentConnections"` | Maximum number of concurrent export connections. | `number` | `0` | 0 = unlimited |
65+
| `"objectscript.export.maxConcurrentConnections"` | Maximum number of concurrent export connections. | `number` | `0` | 0 = unlimited |
6566
| `"objectscript.export.noStorage"` | Strip the storage definition on export. | `boolean` | `false` | Can be useful when working across multiple systems. |
6667
| `"objectscript.format.commandCase"` | Case for commands. | `"upper"`, `"lower"` or `"word"` | `"word"` | Has no effect if the `InterSystems Language Server` extension is installed and enabled. |
6768
| `"objectscript.format.functionCase"` | Case for system functions and system variables. | `"upper"`, `"lower"` or `"word"` | `"word"` | Has no effect if the `InterSystems Language Server` extension is installed and enabled. |

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1267,7 +1267,7 @@
12671267
"objectscript.debug.debugThisMethod": {
12681268
"type": "boolean",
12691269
"default": true,
1270-
"markdownDescription": "Show inline `Debug Method` CodeLens action for ClassMethods and Routine Labels."
1270+
"markdownDescription": "Show inline `Debug` CodeLens action for ClassMethods and Routine Labels."
12711271
},
12721272
"objectscript.debug.copyToClipboard": {
12731273
"type": "boolean",

src/providers/ObjectScriptCodeLensProvider.ts

Lines changed: 31 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,27 @@ export class ObjectScriptCodeLensProvider implements vscode.CodeLensProvider {
77
document: vscode.TextDocument,
88
token: vscode.CancellationToken
99
): vscode.ProviderResult<vscode.CodeLens[]> {
10-
const result = new Array<vscode.CodeLens>();
11-
12-
if (document.fileName.toLowerCase().endsWith(".cls")) {
13-
result.push(...this.classMethods(document));
10+
if (document.languageId == "objectscript-class") {
11+
return this.classMethods(document);
1412
}
15-
if (document.fileName.toLowerCase().endsWith(".mac")) {
16-
result.push(...this.routineLabels(document));
13+
if (["objectscript", "objectscript-int"].includes(document.languageId)) {
14+
return this.routineLabels(document);
1715
}
18-
return result;
16+
return [];
1917
}
2018

2119
private classMethods(document: vscode.TextDocument): vscode.CodeLens[] {
2220
const file = currentFile(document);
2321
const result = new Array<vscode.CodeLens>();
2422

25-
if (!file.name.match(/\.cls$/i)) {
26-
return result;
27-
}
2823
const className = file.name.split(".").slice(0, -1).join(".");
2924

3025
const { debugThisMethod, copyToClipboard } = config("debug");
26+
if (!debugThisMethod && !copyToClipboard) {
27+
// Return early if both types are turned off
28+
return result;
29+
}
30+
3131
const pattern = /(?:^ClassMethod\s)([^(]+)\((.*)/i;
3232
let inComment = false;
3333
for (let i = 0; i < document.lineCount; i++) {
@@ -63,51 +63,44 @@ export class ObjectScriptCodeLensProvider implements vscode.CodeLensProvider {
6363
return result;
6464
}
6565

66-
private routineLabels(document: vscode.TextDocument): vscode.CodeLens[] {
66+
private async routineLabels(document: vscode.TextDocument): Promise<vscode.CodeLens[]> {
6767
const file = currentFile(document);
6868
const result = new Array<vscode.CodeLens>();
6969

70-
if (!file.name.match(/\.mac$/i)) {
71-
return result;
72-
}
7370
const routineName = file.name.split(".").slice(0, -1).join(".");
7471

7572
const { debugThisMethod, copyToClipboard } = config("debug");
73+
if (!debugThisMethod && !copyToClipboard) {
74+
// Return early if both types are turned off
75+
return result;
76+
}
7677

7778
debugThisMethod && result.push(this.addDebugThisMethod(0, [`^${routineName}`, false]));
7879
copyToClipboard && result.push(this.addCopyToClipboard(0, [`^${routineName}`]));
7980

80-
let inComment = false;
81-
for (let i = 1; i < document.lineCount; i++) {
82-
const line = document.lineAt(i);
83-
const text = this.stripLineComments(line.text);
84-
85-
if (text.match(/\/\*/)) {
86-
inComment = true;
87-
}
88-
89-
if (inComment) {
90-
if (text.match(/\*\//)) {
91-
inComment = false;
81+
const symbols: vscode.DocumentSymbol[] = await vscode.commands.executeCommand(
82+
"vscode.executeDocumentSymbolProvider",
83+
document.uri
84+
);
85+
symbols
86+
.filter((symbol) => symbol.kind === vscode.SymbolKind.Method)
87+
.forEach((symbol) => {
88+
const line = symbol.selectionRange.start.line;
89+
const labelMatch = document.lineAt(line).text.match(/^(\w[^(\n\s]+)(?:\(([^)]*)\))?/i);
90+
if (labelMatch) {
91+
const [, name, parens] = labelMatch;
92+
93+
debugThisMethod && result.push(this.addDebugThisMethod(line, [`${name}^${routineName}`, parens !== "()"]));
94+
copyToClipboard && result.push(this.addCopyToClipboard(line, [`${name}^${routineName}`]));
9295
}
93-
continue;
94-
}
95-
96-
const labelMatch = text.match(/^(\w[^(\n\s]+)(?:\(([^)]*)\))?/i);
97-
if (labelMatch) {
98-
const [, name, parens] = labelMatch;
99-
100-
debugThisMethod && result.push(this.addDebugThisMethod(i, [`${name}^${routineName}`, parens !== "()"]));
101-
copyToClipboard && result.push(this.addCopyToClipboard(i, [`${name}^${routineName}`]));
102-
}
103-
}
96+
});
10497

10598
return result;
10699
}
107100

108101
private addDebugThisMethod(line: number, args: any[]) {
109102
return new vscode.CodeLens(new vscode.Range(line, 0, line, 80), {
110-
title: `Debug this Method`,
103+
title: `Debug`,
111104
command: "vscode-objectscript.debug",
112105
arguments: args,
113106
});

0 commit comments

Comments
 (0)