Skip to content

Commit 78d039a

Browse files
authored
Refactor Explorer code (#1717)
1 parent 3c292b7 commit 78d039a

File tree

11 files changed

+224
-285
lines changed

11 files changed

+224
-285
lines changed

package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -331,11 +331,6 @@
331331
"when": "view == ObjectScriptProjectsExplorer",
332332
"group": "navigation"
333333
},
334-
{
335-
"command": "vscode-objectscript.explorer.project.openOtherServerNs",
336-
"when": "view == ObjectScriptProjectsExplorer && vscode-objectscript.projectsExplorerRootCount > 0",
337-
"group": "navigation"
338-
},
339334
{
340335
"command": "vscode-objectscript.openISCDocument",
341336
"when": "view == workbench.explorer.fileView && vscode-objectscript.connectActive && workspaceFolderCount != 0",
@@ -433,6 +428,11 @@
433428
"when": "view == ObjectScriptProjectsExplorer && viewItem == projectsServerNsNode:extra",
434429
"group": "inline@10"
435430
},
431+
{
432+
"command": "vscode-objectscript.explorer.project.openOtherServerNs",
433+
"when": "view == ObjectScriptProjectsExplorer && viewItem == projectsServerNsNode",
434+
"group": "inline@10"
435+
},
436436
{
437437
"command": "vscode-objectscript.intersystems-servermanager.webterminal",
438438
"when": "view == intersystems-community_servermanager && viewItem =~ /namespace$/ && (viewItem > 6 || !(viewItem =~ /^\\d+/))",
@@ -989,7 +989,7 @@
989989
{
990990
"category": "ObjectScript",
991991
"command": "vscode-objectscript.explorer.project.openOtherServerNs",
992-
"title": "View Projects in Another Server Namespace",
992+
"title": "View Projects in Another Namespace...",
993993
"icon": "$(add)"
994994
},
995995
{

src/api/index.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -296,15 +296,8 @@ export class AtelierAPI {
296296
}
297297

298298
public get connInfo(): string {
299-
const { serverName, host, port, docker, dockerService } = this.config;
300-
const ns = this.ns.toUpperCase();
301-
return (
302-
(docker
303-
? "docker" + (dockerService ? `:${dockerService}:${port}` : "")
304-
: serverName
305-
? serverName
306-
: `${host}:${port}`) + `[${ns}]`
307-
);
299+
const { port, docker, dockerService } = this.config;
300+
return (docker ? "docker" + (dockerService ? `:${dockerService}:${port}` : "") : this.serverId) + `[${this.ns}]`;
308301
}
309302

310303
/** Return the server's name in `intersystems.servers` if it exists, else its `host:port/pathPrefix` */

src/commands/addServerNamespaceToWorkspace.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { isfsConfig, IsfsUriParam } from "../utils/FileProviderUtil";
1717
* @param message The prefix of the message to show when the server manager API can't be found.
1818
* @returns An object containing `serverName` and `namespace`, or `undefined`.
1919
*/
20-
export async function pickServerAndNamespace(message?: string): Promise<{ serverName: string; namespace: string }> {
20+
async function pickServerAndNamespace(message?: string): Promise<{ serverName: string; namespace: string }> {
2121
if (!serverManagerApi) {
2222
vscode.window.showErrorMessage(
2323
`${

src/commands/compile.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -434,10 +434,10 @@ export async function importFolder(uri: vscode.Uri, noCompile = false): Promise<
434434
}
435435

436436
export async function compileExplorerItems(nodes: NodeBase[]): Promise<any> {
437-
const { workspaceFolderUri, namespace } = nodes[0];
438-
const conf = vscode.workspace.getConfiguration("objectscript", workspaceFolderUri);
439-
const api = new AtelierAPI(workspaceFolderUri);
440-
api.setNamespace(namespace);
437+
const { wsFolder, namespace } = nodes[0];
438+
const conf = vscode.workspace.getConfiguration("objectscript", wsFolder);
439+
const api = new AtelierAPI(wsFolder.uri);
440+
if (namespace) api.setNamespace(namespace);
441441
const docs = [];
442442
for (const node of nodes) {
443443
if (node instanceof PackageNode) {

src/commands/delete.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,21 @@ import * as vscode from "vscode";
22

33
import { AtelierAPI } from "../api";
44
import { FILESYSTEM_SCHEMA, explorerProvider } from "../extension";
5-
import { outputChannel, uriOfWorkspaceFolder } from "../utils";
5+
import { outputChannel } from "../utils";
66
import { OtherStudioAction, fireOtherStudioAction } from "./studio";
77
import { DocumentContentProvider } from "../providers/DocumentContentProvider";
88
import { UserAction } from "../api/atelier";
99
import { NodeBase, PackageNode, RootNode } from "../explorer/nodes";
1010

11-
function deleteList(items: string[], workspaceFolder: string, namespace: string): Promise<any> {
11+
function deleteList(items: string[], wsFolder: vscode.WorkspaceFolder, namespace?: string): Promise<any> {
1212
if (!items || !items.length) {
13-
vscode.window.showWarningMessage("Nothing to delete");
13+
vscode.window.showWarningMessage("No documents to delete.", "Dismiss");
1414
}
15-
16-
const wsFolderUri = uriOfWorkspaceFolder(workspaceFolder);
17-
const api = new AtelierAPI(workspaceFolder);
18-
api.setNamespace(namespace);
15+
const api = new AtelierAPI(wsFolder.uri);
16+
if (namespace) api.setNamespace(namespace);
1917
return Promise.all(items.map((item) => api.deleteDoc(item))).then((files) => {
2018
files.forEach((file) => {
21-
if (file.result.ext && wsFolderUri?.scheme == FILESYSTEM_SCHEMA) {
19+
if (file.result.ext && wsFolder.uri.scheme == FILESYSTEM_SCHEMA) {
2220
// Only process source control output if we're in an isfs folder
2321
const uri = DocumentContentProvider.getUri(file.result.name);
2422
fireOtherStudioAction(OtherStudioAction.DeletedDocument, uri, <UserAction>file.result.ext);
@@ -29,7 +27,7 @@ function deleteList(items: string[], workspaceFolder: string, namespace: string)
2927
}
3028

3129
export async function deleteExplorerItems(nodes: NodeBase[]): Promise<any> {
32-
const { workspaceFolder, namespace } = nodes[0];
30+
const { wsFolder, namespace } = nodes[0];
3331
const nodesPromiseList: Promise<NodeBase[]>[] = [];
3432
for (const node of nodes) {
3533
nodesPromiseList.push(node instanceof RootNode ? node.getChildren(node) : Promise.resolve([node]));
@@ -56,7 +54,7 @@ export async function deleteExplorerItems(nodes: NodeBase[]): Promise<any> {
5654
// Don't delete without confirmation
5755
return;
5856
}
59-
deleteList(items, workspaceFolder, namespace);
57+
deleteList(items, wsFolder, namespace);
6058
explorerProvider.refresh();
6159
}
6260
});

src/commands/export.ts

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import {
1616
RateLimiter,
1717
replaceFile,
1818
stringifyError,
19-
uriOfWorkspaceFolder,
2019
workspaceFolderOfUri,
2120
} from "../utils";
2221
import { pickDocuments } from "../utils/documentPicker";
@@ -127,24 +126,24 @@ async function exportFile(wsFolderUri: vscode.Uri, namespace: string, name: stri
127126
}
128127
}
129128

130-
export async function exportList(files: string[], workspaceFolder: string, namespace: string): Promise<any> {
129+
export async function exportList(files: string[], wsFolder: vscode.WorkspaceFolder, namespace?: string): Promise<any> {
131130
if (!files || !files.length) {
132131
vscode.window.showWarningMessage("No documents to export.", "Dismiss");
133132
return;
134133
}
135-
const wsFolderUri = uriOfWorkspaceFolder(workspaceFolder);
136-
if (!workspaceFolder || !wsFolderUri) return;
137-
if (!vscode.workspace.fs.isWritableFileSystem(wsFolderUri.scheme)) {
138-
vscode.window.showErrorMessage(`Cannot export to read-only file system '${wsFolderUri.scheme}'.`, "Dismiss");
134+
if (!wsFolder) return;
135+
if (!vscode.workspace.fs.isWritableFileSystem(wsFolder.uri.scheme)) {
136+
vscode.window.showErrorMessage(`Cannot export to read-only file system '${wsFolder.uri.scheme}'.`, "Dismiss");
139137
return;
140138
}
141-
if (!new AtelierAPI(wsFolderUri).active) {
139+
const api = new AtelierAPI(wsFolder.uri);
140+
if (!api.active) {
142141
vscode.window.showErrorMessage("Exporting documents requires an active server connection.", "Dismiss");
143142
return;
144143
}
145144

146-
const { atelier, folder, addCategory, map } = config("export", workspaceFolder);
147-
const root = wsFolderUri.fsPath + (folder.length ? path.sep + folder : "");
145+
const { atelier, folder, addCategory, map } = config("export", wsFolder.name);
146+
const root = wsFolder.uri.fsPath + (folder.length ? path.sep + folder : "");
148147
outputChannel.show(true);
149148
const rateLimiter = new RateLimiter(50);
150149
return vscode.window.withProgress(
@@ -157,7 +156,7 @@ export async function exportList(files: string[], workspaceFolder: string, names
157156
Promise.allSettled<void>(
158157
files.map((file) =>
159158
rateLimiter.call(() =>
160-
exportFile(wsFolderUri, namespace, file, getFileName(root, file, atelier, addCategory, map))
159+
exportFile(wsFolder.uri, namespace ?? api.ns, file, getFileName(root, file, atelier, addCategory, map))
161160
)
162161
)
163162
)
@@ -223,24 +222,21 @@ export async function exportAll(): Promise<any> {
223222
if (!files?.length) return;
224223
await exportList(
225224
files.map((file) => file.label),
226-
wsFolder.name,
227-
api.ns
225+
wsFolder
228226
);
229227
} catch (error) {
230228
handleError(error, "Error executing 'Export Code from Server...' command.");
231229
}
232230
}
233231

234232
export async function exportExplorerItems(nodes: NodeBase[]): Promise<any> {
235-
const node = nodes[0];
236-
const nodeNs = node.namespace.toUpperCase();
237-
const origNamespace = config("conn", node.workspaceFolder).ns?.toUpperCase();
238-
if (origNamespace?.toUpperCase() != node.namespace.toUpperCase()) {
233+
const { wsFolder, namespace } = nodes[0];
234+
if (namespace) {
239235
const answer = await vscode.window.showWarningMessage(
240236
`
241-
You are about to export from namespace ${nodeNs}.
237+
You are about to export from namespace ${namespace}.
242238
243-
Future edits to the file(s) in your local workspace will be saved and compiled in the primary namespace of your workspace root, ${origNamespace}, not the namespace from which you originally exported.
239+
Future edits to the file(s) in your local workspace will be saved and compiled in the primary namespace of your workspace root, ${new AtelierAPI(wsFolder.uri).ns}, not the namespace from which you originally exported.
244240
245241
Would you like to continue?`,
246242
{
@@ -252,9 +248,9 @@ Would you like to continue?`,
252248
return;
253249
}
254250
}
255-
return Promise.all(nodes.map((node) => node.getItems4Export()))
251+
return Promise.all(nodes.map((node) => node.getItemsForExport()))
256252
.then((items) => {
257-
return exportList(items.flat(), node.workspaceFolder, nodeNs).then(() => explorerProvider.refresh());
253+
return exportList(items.flat(), wsFolder, namespace).then(() => explorerProvider.refresh());
258254
})
259255
.catch((error) => {
260256
handleError(error, "Error exporting Explorer items.");
@@ -272,8 +268,7 @@ export async function exportCurrentFile(): Promise<any> {
272268
// Only export files opened from the explorer
273269
return;
274270
}
275-
const api = new AtelierAPI(openDoc.uri);
276-
return exportList([currentFile(openDoc).name], api.configName, api.config.ns);
271+
return exportList([currentFile(openDoc).name], vscode.workspace.getWorkspaceFolder(openDoc.uri));
277272
}
278273

279274
export async function exportDocumentsToXMLFile(): Promise<void> {

src/commands/project.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ export async function pickProject(api: AtelierAPI, allowCreate = true): Promise<
9292
export async function createProject(node: NodeBase | undefined, api?: AtelierAPI): Promise<string | undefined> {
9393
if (api == undefined) {
9494
if (node instanceof NodeBase) {
95-
api = new AtelierAPI(node.workspaceFolderUri);
96-
api.setNamespace(node.namespace);
95+
api = new AtelierAPI(node.wsFolder.uri);
96+
if (node.namespace) api.setNamespace(node.namespace);
9797
} else {
9898
// Have the user pick a server connection
9999
const connUri = await getWsServerConnection();
@@ -160,8 +160,8 @@ export async function deleteProject(node: ProjectNode | undefined): Promise<any>
160160
let api: AtelierAPI;
161161
let project: string;
162162
if (node instanceof ProjectNode) {
163-
api = new AtelierAPI(node.workspaceFolderUri);
164-
api.setNamespace(node.namespace);
163+
api = new AtelierAPI(node.wsFolder.uri);
164+
if (node.namespace) api.setNamespace(node.namespace);
165165
project = node.label;
166166
} else {
167167
// Have the user pick a server connection
@@ -919,8 +919,7 @@ export async function exportProjectContents(): Promise<any> {
919919
[project]
920920
)
921921
.then((data) => data.result.content.map((e) => e.Name)),
922-
wsFolder.name,
923-
api.ns
922+
wsFolder
924923
);
925924
} catch (error) {
926925
handleError(error, "Error executing 'Export Project Contents from Server...' command.");
@@ -1008,7 +1007,10 @@ export async function addIsfsFileToProject(project: string, fileName: string, ap
10081007

10091008
export function addWorkspaceFolderForProject(node: ProjectNode): void {
10101009
// Check if an isfs folder already exists for this project
1011-
const idx = isfsFolderForProject(node.label, new AtelierAPI(node.workspaceFolderUri));
1010+
const api = new AtelierAPI(node.wsFolder.uri);
1011+
if (node.namespace) api.setNamespace(node.namespace);
1012+
const serverName = api.config.serverName;
1013+
const idx = isfsFolderForProject(node.label, api);
10121014
// If not, create one
10131015
if (idx != -1) {
10141016
vscode.window.showWarningMessage(`A workspace folder for this project already exists.`, "Dismiss");
@@ -1019,8 +1021,8 @@ export function addWorkspaceFolderForProject(node: ProjectNode): void {
10191021
vscode.workspace.workspaceFolders ? vscode.workspace.workspaceFolders.length : 0,
10201022
0,
10211023
{
1022-
uri: vscode.Uri.parse(`isfs://${node.conn.serverName}:${node.namespace}/?project=${node.label}`),
1023-
name: `${node.label} - ${node.conn.serverName}:${node.namespace.toUpperCase()}`,
1024+
uri: vscode.Uri.parse(`isfs://${serverName}:${api.ns.toLowerCase()}/?project=${node.label}`),
1025+
name: `${node.label} - ${serverName}:${api.ns}`,
10241026
}
10251027
);
10261028
// Switch to Explorer view so user sees the outcome
@@ -1036,8 +1038,8 @@ async function handleCommandArg(
10361038
if (nodeOrUri instanceof NodeBase) {
10371039
// Called from Projects Explorer
10381040
node = nodeOrUri;
1039-
api = new AtelierAPI(node.workspaceFolderUri);
1040-
api.setNamespace(node.namespace);
1041+
api = new AtelierAPI(node.wsFolder.uri);
1042+
if (node.namespace) api.setNamespace(node.namespace);
10411043
project = node.options.project;
10421044
} else if (nodeOrUri instanceof vscode.Uri) {
10431045
// Called from files explorer

0 commit comments

Comments
 (0)