Skip to content

Commit ee2e23d

Browse files
authored
Add objectscript.openClassContracted setting (#882)
1 parent fd29abe commit ee2e23d

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

docs/SettingsReference.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ The extensions in the InterSystems ObjectScript Extension Pack provide many sett
5555
| `"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. |
5656
| `"objectscript.ignoreInstallServerManager"` | Do not offer to install the [intersystems-community.servermanager](https://marketplace.visualstudio.com/items?itemName=intersystems-community.servermanager) extension. | `boolean` | `false` | |
5757
| `"objectscript.multilineMethodArgs"` | List method arguments on multiple lines, if the server supports it. | `boolean` | `false` | Only supported on IRIS 2019.1.2, 2020.1.1+, 2021.1.0+ and subsequent versions! On all other versions, this setting will have no effect. |
58+
| `"objectscript.openClassContracted"` | Automatically collapse all folding ranges when a class is opened for the first time. | `boolean` | `false` | |
5859
| `"objectscript.overwriteServerChanges"` | Overwrite a changed server version without confirmation when importing the local file. | `boolean` | `false` | |
5960
| `"objectscript.serverSideEditing"` | Allow editing code directly on the server after opening it from ObjectScript Explorer. | `boolean` | `false` | |
6061
| `"objectscript.serverSourceControl.disableOtherActionTriggers"` | Prevent server-side source control 'other action' triggers from firing. | `boolean` | `false` | |

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1067,6 +1067,11 @@
10671067
"markdownDescription": "List method arguments on multiple lines, if the server supports it. **NOTE:** Only supported on IRIS 2019.1.2, 2020.1.1+, 2021.1.0+ and subsequent versions! On all other versions, this setting will have no effect.",
10681068
"type": "boolean",
10691069
"default": false
1070+
},
1071+
"objectscript.openClassContracted": {
1072+
"description": "Automatically collapse all folding ranges when a class is opened for the first time.",
1073+
"type": "boolean",
1074+
"default": false
10701075
}
10711076
}
10721077
},

src/extension.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,9 @@ function languageServer(install = true): vscode.Extension<any> {
449449
return extension;
450450
}
451451

452+
// The URIs of all classes that have been opened. Used when objectscript.openClassContracted is true.
453+
let openedClasses: string[];
454+
452455
export async function activate(context: vscode.ExtensionContext): Promise<any> {
453456
if (!packageJson.version.includes("SNAPSHOT")) {
454457
try {
@@ -738,6 +741,8 @@ export async function activate(context: vscode.ExtensionContext): Promise<any> {
738741
}
739742
}
740743

744+
openedClasses = workspaceState.get("openedClasses") ?? [];
745+
741746
context.subscriptions.push(
742747
reporter,
743748
panel,
@@ -968,6 +973,25 @@ export async function activate(context: vscode.ExtensionContext): Promise<any> {
968973
})
969974
)
970975
),
976+
vscode.window.onDidChangeActiveTextEditor((editor: vscode.TextEditor) => {
977+
const uri: string = editor.document.uri.toString();
978+
if (
979+
config("openClassContracted") &&
980+
editor &&
981+
editor.document.languageId === "objectscript-class" &&
982+
!openedClasses.includes(uri)
983+
) {
984+
vscode.commands.executeCommand("editor.foldAll");
985+
openedClasses.push(uri);
986+
}
987+
}),
988+
vscode.workspace.onDidCloseTextDocument((doc: vscode.TextDocument) => {
989+
const uri: string = doc.uri.toString();
990+
const idx: number = openedClasses.indexOf(uri);
991+
if (idx > -1) {
992+
openedClasses.splice(idx, 1);
993+
}
994+
}),
971995

972996
/* Anything we use from the VS Code proposed API */
973997
...proposed
@@ -1036,6 +1060,9 @@ export async function activate(context: vscode.ExtensionContext): Promise<any> {
10361060
}
10371061

10381062
export function deactivate(): void {
1063+
if (workspaceState) {
1064+
workspaceState.update("openedClasses", openedClasses);
1065+
}
10391066
// This will ensure all pending events get flushed
10401067
reporter && reporter.dispose();
10411068
if (terminals) {

0 commit comments

Comments
 (0)