Skip to content

Commit 6084767

Browse files
authored
Add objectscript.explorer.alwaysShowServerCopy setting (#889)
1 parent dc35116 commit 6084767

File tree

7 files changed

+86
-43
lines changed

7 files changed

+86
-43
lines changed

docs/SettingsReference.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ The extensions in the InterSystems ObjectScript Extension Pack provide many sett
4141
| `"objectscript.compileOnSave"` | Automatically compile an InterSystems file when saved in the editor. | `boolean` | `true` | |
4242
| `"objectscript.conn"` | Configures the active server connection. | `object` | `undefined` | See the [Configuration page](../configuration/#config-server-conn) for more details on configuring server connections. |
4343
| `"objectscript.debug.debugThisMethod"` | Show inline `Debug this method` CodeLens action for ClassMethods. | `boolean` | `true` | |
44+
| `"objectscript.explorer.alwaysShowServerCopy"` | Always show the server copy of a document in the ObjectScript Explorer. | `boolean` | `false` | |
4445
| `"objectscript.export.addCategory"` | Add a category folder to the beginning of the export path. | `boolean` or `object` | `false` | |
4546
| `"objectscript.export.atelier"` | Export source code as Atelier did it, with packages as subfolders. | `boolean` | `true` | |
4647
| `"objectscript.export.category"` | Category of source code to export: `CLS` = classes; `RTN` = routines; `CSP` = csp files; `OTH` = other. Default is `*` = all. | `string` or `object` | `"*"` | |

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1072,6 +1072,11 @@
10721072
"description": "Automatically collapse all folding ranges when a class is opened for the first time.",
10731073
"type": "boolean",
10741074
"default": false
1075+
},
1076+
"objectscript.explorer.alwaysShowServerCopy": {
1077+
"description": "Always show the server copy of a document in the ObjectScript Explorer.",
1078+
"type": "boolean",
1079+
"default": false
10751080
}
10761081
}
10771082
},

src/explorer/models/classNode.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as vscode from "vscode";
22
import { DocumentContentProvider } from "../../providers/DocumentContentProvider";
33
import { NodeBase, NodeOptions } from "./nodeBase";
4+
import { config } from "../../extension";
45

56
export class ClassNode extends NodeBase {
67
public static readonly contextValue: string = "dataNode:classNode";
@@ -12,18 +13,27 @@ export class ClassNode extends NodeBase {
1213
const displayName: string = this.label;
1314
const itemUri = DocumentContentProvider.getUri(this.fullName, this.workspaceFolder, this.namespace);
1415
const isLocalFile = itemUri.scheme === "file";
16+
const showServerCopy: boolean = config("explorer.alwaysShowServerCopy", this.workspaceFolder);
17+
const serverCopyUri = DocumentContentProvider.getUri(
18+
this.fullName,
19+
this.workspaceFolder,
20+
this.namespace,
21+
undefined,
22+
undefined,
23+
true
24+
);
1525

1626
return {
1727
collapsibleState: vscode.TreeItemCollapsibleState.None,
1828
command: {
19-
arguments: [itemUri],
29+
arguments: [isLocalFile && !showServerCopy ? itemUri : serverCopyUri],
2030
command: "vscode-objectscript.explorer.open",
2131
title: "Open Class",
2232
},
23-
resourceUri: isLocalFile ? itemUri : undefined,
33+
resourceUri: isLocalFile && !showServerCopy ? itemUri : undefined,
2434
contextValue: "dataNode:classNode",
2535
label: `${displayName}`,
26-
tooltip: isLocalFile ? undefined : this.fullName,
36+
tooltip: isLocalFile && !showServerCopy ? undefined : this.fullName,
2737
};
2838
}
2939
}

src/explorer/models/cspFileNode.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as vscode from "vscode";
22
import { DocumentContentProvider } from "../../providers/DocumentContentProvider";
33
import { NodeBase, NodeOptions } from "./nodeBase";
4+
import { config } from "../../extension";
45

56
export class CSPFileNode extends NodeBase {
67
public static readonly contextValue: string = "dataNode:cspFileNode";
@@ -12,18 +13,27 @@ export class CSPFileNode extends NodeBase {
1213
const displayName: string = this.label;
1314
const itemUri = DocumentContentProvider.getUri(this.fullName, this.workspaceFolder, this.namespace);
1415
const isLocalFile = itemUri.scheme === "file";
16+
const showServerCopy: boolean = config("explorer.alwaysShowServerCopy", this.workspaceFolder);
17+
const serverCopyUri = DocumentContentProvider.getUri(
18+
this.fullName,
19+
this.workspaceFolder,
20+
this.namespace,
21+
undefined,
22+
undefined,
23+
true
24+
);
1525

1626
return {
1727
collapsibleState: vscode.TreeItemCollapsibleState.None,
1828
command: {
19-
arguments: [itemUri],
29+
arguments: [isLocalFile && !showServerCopy ? itemUri : serverCopyUri],
2030
command: "vscode-objectscript.explorer.open",
2131
title: "Open File",
2232
},
23-
resourceUri: isLocalFile ? itemUri : undefined,
33+
resourceUri: isLocalFile && !showServerCopy ? itemUri : undefined,
2434
contextValue: CSPFileNode.contextValue,
2535
label: `${displayName}`,
26-
tooltip: isLocalFile ? undefined : this.fullName,
36+
tooltip: isLocalFile && !showServerCopy ? undefined : this.fullName,
2737
};
2838
}
2939
}

src/explorer/models/packageNode.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as vscode from "vscode";
22
import { RootNode } from "./rootNode";
33
import { NodeOptions } from "./nodeBase";
44
import { DocumentContentProvider } from "../../providers/DocumentContentProvider";
5+
import { config } from "../../extension";
56

67
export class PackageNode extends RootNode {
78
public constructor(label: string, fullName: string, category: string, options: NodeOptions) {
@@ -12,10 +13,11 @@ export class PackageNode extends RootNode {
1213
const displayName: string = this.label;
1314
const localFolderPath = DocumentContentProvider.getAsFolder(this.fullName, this.workspaceFolder, "cls");
1415
const localUri = localFolderPath ? vscode.Uri.file(localFolderPath) : undefined;
16+
const showServerCopy: boolean = config("explorer.alwaysShowServerCopy", this.workspaceFolder);
1517

1618
return {
1719
collapsibleState: vscode.TreeItemCollapsibleState.Collapsed,
18-
resourceUri: !this.extraNode ? localUri : undefined,
20+
resourceUri: !this.extraNode && !showServerCopy ? localUri : undefined,
1921
contextValue: this.contextValue,
2022
label: `${displayName}`,
2123
tooltip: this.fullName,

src/explorer/models/routineNode.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as vscode from "vscode";
22
import { DocumentContentProvider } from "../../providers/DocumentContentProvider";
33
import { NodeBase, NodeOptions } from "./nodeBase";
4+
import { config } from "../../extension";
45

56
export class RoutineNode extends NodeBase {
67
public static readonly contextValue: string = "dataNode:routineNode";
@@ -12,18 +13,27 @@ export class RoutineNode extends NodeBase {
1213
const displayName: string = this.label;
1314
const itemUri = DocumentContentProvider.getUri(this.fullName, this.workspaceFolder, this.namespace);
1415
const isLocalFile = itemUri.scheme === "file";
16+
const showServerCopy: boolean = config("explorer.alwaysShowServerCopy", this.workspaceFolder);
17+
const serverCopyUri = DocumentContentProvider.getUri(
18+
this.fullName,
19+
this.workspaceFolder,
20+
this.namespace,
21+
undefined,
22+
undefined,
23+
true
24+
);
1525

1626
return {
1727
collapsibleState: vscode.TreeItemCollapsibleState.None,
1828
command: {
19-
arguments: [itemUri],
29+
arguments: [isLocalFile && !showServerCopy ? itemUri : serverCopyUri],
2030
command: "vscode-objectscript.explorer.open",
2131
title: "Open Routine",
2232
},
23-
resourceUri: isLocalFile ? itemUri : undefined,
33+
resourceUri: isLocalFile && !showServerCopy ? itemUri : undefined,
2434
contextValue: "dataNode:routineNode",
2535
label: `${displayName}`,
26-
tooltip: isLocalFile ? undefined : this.fullName,
36+
tooltip: isLocalFile && !showServerCopy ? undefined : this.fullName,
2737
};
2838
}
2939
}

src/providers/DocumentContentProvider.ts

Lines changed: 38 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ export class DocumentContentProvider implements vscode.TextDocumentContentProvid
3838
workspaceFolder?: string,
3939
namespace?: string,
4040
vfs?: boolean,
41-
wFolderUri?: vscode.Uri
41+
wFolderUri?: vscode.Uri,
42+
forceServerCopy = false
4243
): vscode.Uri {
4344
if (vfs === undefined) {
4445
vfs = config("serverSideEditing");
@@ -72,46 +73,50 @@ export class DocumentContentProvider implements vscode.TextDocumentContentProvid
7273
}
7374
} else {
7475
const conn = config("conn", workspaceFolder);
75-
const localFile = this.getAsFile(name, workspaceFolder);
76-
if (localFile && (!namespace || namespace === conn.ns)) {
77-
// Exists as a local file and we aren't viewing a different namespace on the same server,
78-
// so return a file:// uri that will open the local file.
79-
return vscode.Uri.file(localFile);
80-
} else {
81-
// The local file doesn't exist in this folder, so check any other
82-
// local folders in this workspace if it's a multi-root workspace
83-
const wFolders = vscode.workspace.workspaceFolders;
84-
if (wFolders && wFolders.length > 1) {
85-
// This is a multi-root workspace
86-
for (const wFolder of wFolders) {
87-
if (wFolder.uri.scheme === "file" && wFolder.name !== workspaceFolder) {
88-
// This isn't the folder that we checked originally
89-
const wFolderConn = config("conn", wFolder.name);
90-
const compareConns = (): boolean => {
91-
if (wFolderConn.ns === conn.ns) {
92-
if (wFolderConn.server && conn.server) {
93-
if (wFolderConn.server === conn.server) {
94-
return true;
95-
}
96-
} else if (!wFolderConn.server && !conn.server) {
97-
if (wFolderConn.host === conn.host && wFolderConn.port === conn.port) {
98-
return true;
76+
if (!forceServerCopy) {
77+
// Look for the document in the local file system
78+
const localFile = this.getAsFile(name, workspaceFolder);
79+
if (localFile && (!namespace || namespace === conn.ns)) {
80+
// Exists as a local file and we aren't viewing a different namespace on the same server,
81+
// so return a file:// uri that will open the local file.
82+
return vscode.Uri.file(localFile);
83+
} else {
84+
// The local file doesn't exist in this folder, so check any other
85+
// local folders in this workspace if it's a multi-root workspace
86+
const wFolders = vscode.workspace.workspaceFolders;
87+
if (wFolders && wFolders.length > 1) {
88+
// This is a multi-root workspace
89+
for (const wFolder of wFolders) {
90+
if (wFolder.uri.scheme === "file" && wFolder.name !== workspaceFolder) {
91+
// This isn't the folder that we checked originally
92+
const wFolderConn = config("conn", wFolder.name);
93+
const compareConns = (): boolean => {
94+
if (wFolderConn.ns === conn.ns) {
95+
if (wFolderConn.server && conn.server) {
96+
if (wFolderConn.server === conn.server) {
97+
return true;
98+
}
99+
} else if (!wFolderConn.server && !conn.server) {
100+
if (wFolderConn.host === conn.host && wFolderConn.port === conn.port) {
101+
return true;
102+
}
99103
}
100104
}
101-
}
102-
return false;
103-
};
104-
if (compareConns() && (!namespace || namespace === wFolderConn.ns)) {
105-
// This folder is connected to the same server:ns combination as the original folder
106-
const wFolderFile = this.getAsFile(name, wFolder.name);
107-
if (wFolderFile) {
108-
return vscode.Uri.file(wFolderFile);
105+
return false;
106+
};
107+
if (compareConns() && (!namespace || namespace === wFolderConn.ns)) {
108+
// This folder is connected to the same server:ns combination as the original folder
109+
const wFolderFile = this.getAsFile(name, wFolder.name);
110+
if (wFolderFile) {
111+
return vscode.Uri.file(wFolderFile);
112+
}
109113
}
110114
}
111115
}
112116
}
113117
}
114118
}
119+
115120
const { active } = conn;
116121
if (!active) {
117122
return null;

0 commit comments

Comments
 (0)