Skip to content

Commit 8f78f91

Browse files
Make a webapp ISFS folder fall back to the folder-specific settings of its namespace (#1479)
* Make a webapp ISFS folder fall back to the folder-specific settings of its namespace * Changes after PR comments * Handle optional trailing slash on path
1 parent aae0541 commit 8f78f91

File tree

2 files changed

+46
-5
lines changed

2 files changed

+46
-5
lines changed

src/extension.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ import {
101101
cspApps,
102102
otherDocExts,
103103
getWsServerConnection,
104+
addWsServerRootFolderData,
104105
} from "./utils";
105106
import { ObjectScriptDiagnosticProvider } from "./providers/ObjectScriptDiagnosticProvider";
106107
import { DocumentLinkProvider } from "./providers/DocumentLinkProvider";
@@ -802,6 +803,9 @@ export async function activate(context: vscode.ExtensionContext): Promise<any> {
802803
continue;
803804
}
804805
}
806+
for await (const workspaceFolder of vscode.workspace.workspaceFolders ?? []) {
807+
await addWsServerRootFolderData(workspaceFolder.uri);
808+
}
805809

806810
xmlContentProvider = new XmlContentProvider();
807811

@@ -1321,6 +1325,9 @@ export async function activate(context: vscode.ExtensionContext): Promise<any> {
13211325
const serverName = notIsfs(uri) ? config("conn", configName).server : configName;
13221326
await resolveConnectionSpec(serverName);
13231327
}
1328+
for await (const workspaceFolder of added) {
1329+
await addWsServerRootFolderData(workspaceFolder.uri);
1330+
}
13241331
}),
13251332
vscode.workspace.onDidChangeConfiguration(async ({ affectsConfiguration }) => {
13261333
if (affectsConfiguration("objectscript.conn") || affectsConfiguration("intersystems.servers")) {
@@ -1337,7 +1344,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<any> {
13371344
}
13381345
// Check connections sequentially for each workspace folder
13391346
let refreshFilesExplorer = false;
1340-
for await (const folder of vscode.workspace.workspaceFolders) {
1347+
for await (const folder of vscode.workspace.workspaceFolders ?? []) {
13411348
if (schemas.includes(folder.uri.scheme)) {
13421349
refreshFilesExplorer = true;
13431350
}

src/utils/index.ts

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,35 @@ export async function shellWithDocker(): Promise<vscode.Terminal> {
617617
return terminal;
618618
}
619619

620+
interface WSServerRootFolderData {
621+
redirectDotvscode: boolean;
622+
}
623+
624+
const wsServerRootFolders = new Map<string, WSServerRootFolderData>();
625+
626+
/**
627+
* Add uri to the wsServerRootFolders map if eligible
628+
*/
629+
export async function addWsServerRootFolderData(uri: vscode.Uri): Promise<void> {
630+
if (!schemas.includes(uri.scheme)) {
631+
return;
632+
}
633+
const value: WSServerRootFolderData = {
634+
redirectDotvscode: true,
635+
};
636+
if (isCSPFile(uri) && !["", "/"].includes(uri.path)) {
637+
// A CSP-type root folder for a specific webapp that already has a .vscode/settings.json file must not redirect .vscode/* references
638+
const api = new AtelierAPI(uri);
639+
api
640+
.headDoc(`${uri.path}${!uri.path.endsWith("/") ? "/" : ""}.vscode/settings.json`)
641+
.then(() => {
642+
value.redirectDotvscode = false;
643+
})
644+
.catch(() => {});
645+
}
646+
wsServerRootFolders.set(uri.toString(), value);
647+
}
648+
620649
/**
621650
* Alter isfs-type uri.path of /.vscode/* files or subdirectories.
622651
* Rewrite `/.vscode/path/to/file` as `/_vscode/XYZ/path/to/file`
@@ -633,13 +662,18 @@ export function redirectDotvscodeRoot(uri: vscode.Uri): vscode.Uri {
633662
if (!schemas.includes(uri.scheme)) {
634663
return uri;
635664
}
636-
const dotMatch = uri.path.match(/^\/(\.[^/]*)(\/.*)?$/);
637-
if (dotMatch && dotMatch[1] === ".vscode") {
665+
const dotMatch = uri.path.match(/^(.*)\/\.vscode(\/.*)?$/);
666+
if (dotMatch) {
667+
const dotvscodeRoot = uri.with({ path: dotMatch[1] || "/" });
668+
if (!wsServerRootFolders.get(dotvscodeRoot.toString())?.redirectDotvscode) {
669+
return uri;
670+
}
638671
let namespace: string;
672+
const andCSP = !isCSPFile(uri) ? "&csp" : "";
639673
const nsMatch = `&${uri.query}&`.match(/&ns=([^&]+)&/);
640674
if (nsMatch) {
641675
namespace = nsMatch[1].toUpperCase();
642-
const newQueryString = (("&" + uri.query).replace(`ns=${namespace}`, "ns=%SYS") + "&csp").slice(1);
676+
const newQueryString = (("&" + uri.query).replace(`ns=${namespace}`, "ns=%SYS") + andCSP).slice(1);
643677
return uri.with({ path: `/_vscode/${namespace}${dotMatch[2] || ""}`, query: newQueryString });
644678
} else {
645679
const parts = uri.authority.split(":");
@@ -648,7 +682,7 @@ export function redirectDotvscodeRoot(uri: vscode.Uri): vscode.Uri {
648682
return uri.with({
649683
authority: `${parts[0]}:%SYS`,
650684
path: `/_vscode/${namespace}${dotMatch[2] || ""}`,
651-
query: uri.query + "&csp",
685+
query: uri.query + andCSP,
652686
});
653687
}
654688
}

0 commit comments

Comments
 (0)