Skip to content

Commit b1ca834

Browse files
authored
Fix importing of web app files (intersystems-community#918)
1 parent b0d548a commit b1ca834

File tree

3 files changed

+39
-12
lines changed

3 files changed

+39
-12
lines changed

src/commands/compile.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,12 @@ import {
1414
} from "../extension";
1515
import { DocumentContentProvider } from "../providers/DocumentContentProvider";
1616
import {
17+
cspAppsForUri,
1718
currentFile,
1819
CurrentFile,
1920
currentFileFromContent,
20-
currentWorkspaceFolder,
2121
outputChannel,
2222
throttleRequests,
23-
uriOfWorkspaceFolder,
2423
} from "../utils";
2524
import { PackageNode } from "../explorer/models/packageNode";
2625
import { NodeBase } from "../explorer/models/nodeBase";
@@ -423,10 +422,7 @@ export async function importFolder(uri: vscode.Uri, noCompile = false): Promise<
423422
return importFiles([uripath], noCompile);
424423
}
425424
let globpattern = "*.{cls,inc,int,mac}";
426-
const workspace = currentWorkspaceFolder();
427-
const workspacePath = uriOfWorkspaceFolder(workspace).fsPath;
428-
const folderPathNoWorkspaceArr = uripath.replace(workspacePath + path.sep, "").split(path.sep);
429-
if (folderPathNoWorkspaceArr.includes("csp")) {
425+
if (cspAppsForUri(uri).findIndex((cspApp) => uri.path.includes(cspApp + "/") || uri.path.endsWith(cspApp)) != -1) {
430426
// This folder is a CSP application, so import all files
431427
// We need to include eveything becuase CSP applications can
432428
// include non-InterSystems files

src/extension.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,13 @@ export function getResolvedConnectionSpec(key: string, dflt: any): any {
196196
return resolvedConnSpecs.has(key) ? resolvedConnSpecs.get(key) : dflt;
197197
}
198198

199+
/**
200+
* A map of all CSP web apps in a server-namespace.
201+
* The key is either `serverName:ns`, or `host:port/pathPrefix:ns`, lowercase.
202+
* The value is an array of CSP apps as returned by GET %25SYS/cspapps.
203+
*/
204+
export const cspApps: Map<string, string[]> = new Map();
205+
199206
export async function checkConnection(clearCookies = false, uri?: vscode.Uri): Promise<void> {
200207
// Do nothing if already checking the connection
201208
if (checkingConnection) {
@@ -282,7 +289,7 @@ export async function checkConnection(clearCookies = false, uri?: vscode.Uri): P
282289
checkingConnection = true;
283290
return api
284291
.serverInfo()
285-
.then((info) => {
292+
.then(async (info) => {
286293
panel.text = api.connInfo;
287294
panel.tooltip = `Connected${pathPrefix ? " to " + pathPrefix : ""} as ${username}`;
288295
const hasHS = info.result.content.features.find((el) => el.name === "HEALTHSHARE" && el.enabled) !== undefined;
@@ -291,6 +298,15 @@ export async function checkConnection(clearCookies = false, uri?: vscode.Uri): P
291298
serverVersion: info.result.content.version,
292299
healthshare: hasHS ? "yes" : "no",
293300
});
301+
// Update CSP web app cache if required
302+
const key = (
303+
api.config.serverName && api.config.serverName != ""
304+
? `${api.config.serverName}:${api.config.ns}`
305+
: `${api.config.host}:${api.config.port}${api.config.pathPrefix}:${api.config.ns}`
306+
).toLowerCase();
307+
if (!cspApps.has(key)) {
308+
cspApps.set(key, await api.getCSPApps().then((data) => data.result.content || []));
309+
}
294310
return;
295311
})
296312
.catch((error) => {

src/utils/index.ts

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ import { R_OK } from "constants";
44
import * as url from "url";
55
import { exec } from "child_process";
66
import * as vscode from "vscode";
7-
import { config, schemas, workspaceState, terminals, extensionContext } from "../extension";
7+
import { config, schemas, workspaceState, terminals, extensionContext, cspApps } from "../extension";
88
import { getCategory } from "../commands/export";
9+
import { AtelierAPI } from "../api";
910

1011
let latestErrorMessage = "";
1112
export const outputChannel: {
@@ -56,6 +57,19 @@ export interface ConnectionTarget {
5657
configName: string;
5758
}
5859

60+
/**
61+
* Get a list of all CSP web apps in the server-namespace that `uri` is connected to.
62+
*/
63+
export function cspAppsForUri(uri: vscode.Uri): string[] {
64+
const api = new AtelierAPI(uri);
65+
const key = (
66+
api.config.serverName && api.config.serverName != ""
67+
? `${api.config.serverName}:${api.config.ns}`
68+
: `${api.config.host}:${api.config.port}${api.config.pathPrefix}:${api.config.ns}`
69+
).toLowerCase();
70+
return cspApps.get(key) ?? [];
71+
}
72+
5973
/**
6074
* Determine the server name of a local non-ObjectScript file (any file that's not CLS,MAC,INT,INC).
6175
* @param localPath The full path to the file on disk.
@@ -66,7 +80,8 @@ function getServerDocName(localPath: string, workspace: string, fileExt: string)
6680
const workspacePath = uriOfWorkspaceFolder(workspace).fsPath;
6781
const filePathNoWorkspaceArr = localPath.replace(workspacePath + path.sep, "").split(path.sep);
6882
if (fileExt !== "dfi") {
69-
return filePathNoWorkspaceArr.slice(filePathNoWorkspaceArr.indexOf("csp")).join("/");
83+
const uri = vscode.Uri.file(localPath);
84+
return uri.path.slice(uri.path.indexOf(cspAppsForUri(uri).find((cspApp) => uri.path.includes(cspApp + "/"))));
7085
}
7186
const { atelier, folder, addCategory } = config("export", workspace);
7287
const root = [
@@ -91,9 +106,7 @@ export function isImportableLocalFile(file: vscode.TextDocument): boolean {
91106
const workspace = currentWorkspaceFolder(file);
92107
const workspacePath = uriOfWorkspaceFolder(workspace).fsPath;
93108
const filePathNoWorkspaceArr = file.fileName.replace(workspacePath + path.sep, "").split(path.sep);
94-
if (filePathNoWorkspaceArr.includes("csp")) {
95-
return true;
96-
} else if (file.uri.path.toLowerCase().endsWith(".dfi")) {
109+
if (file.uri.path.toLowerCase().endsWith(".dfi")) {
97110
// This is a DFI file, so make sure it matches our export settings
98111
const { atelier, folder, addCategory } = config("export", workspace);
99112
const expectedRoot = [
@@ -109,6 +122,8 @@ export function isImportableLocalFile(file: vscode.TextDocument): boolean {
109122
return true;
110123
}
111124
}
125+
} else {
126+
return cspAppsForUri(file.uri).findIndex((cspApp) => file.uri.path.includes(cspApp + "/")) != -1;
112127
}
113128
return false;
114129
}

0 commit comments

Comments
 (0)