Skip to content

Commit 7526c0b

Browse files
committed
Make a webapp ISFS folder fall back to the folder-specific settings of its namespace
1 parent 75f6ea9 commit 7526c0b

File tree

2 files changed

+42
-4
lines changed

2 files changed

+42
-4
lines changed

src/extension.ts

Lines changed: 7 additions & 0 deletions
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")) {

src/utils/index.ts

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,32 @@ 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)) {
637+
// A CSP-type root folder that already has a .vscode/settings.json file must not redirect .vscode/* references
638+
const api = new AtelierAPI(uri);
639+
api.getDoc(`${uri.path}/.vscode/settings.json`).then(() => {
640+
value.redirectDotvscode = false;
641+
});
642+
}
643+
wsServerRootFolders.set(uri.toString(), value);
644+
}
645+
620646
/**
621647
* Alter isfs-type uri.path of /.vscode/* files or subdirectories.
622648
* Rewrite `/.vscode/path/to/file` as `/_vscode/XYZ/path/to/file`
@@ -633,13 +659,18 @@ export function redirectDotvscodeRoot(uri: vscode.Uri): vscode.Uri {
633659
if (!schemas.includes(uri.scheme)) {
634660
return uri;
635661
}
636-
const dotMatch = uri.path.match(/^\/(\.[^/]*)(\/.*)?$/);
637-
if (dotMatch && dotMatch[1] === ".vscode") {
662+
const dotMatch = uri.path.match(/^(.*)\/\.vscode(\/.*)?$/);
663+
if (dotMatch) {
664+
const dotvscodeRoot = uri.with({ path: dotMatch[1] || "/" });
665+
if (!wsServerRootFolders.get(dotvscodeRoot.toString())?.redirectDotvscode) {
666+
return uri;
667+
}
638668
let namespace: string;
669+
const andCSP = !isCSPFile(uri) ? "&csp" : "";
639670
const nsMatch = `&${uri.query}&`.match(/&ns=([^&]+)&/);
640671
if (nsMatch) {
641672
namespace = nsMatch[1].toUpperCase();
642-
const newQueryString = (("&" + uri.query).replace(`ns=${namespace}`, "ns=%SYS") + "&csp").slice(1);
673+
const newQueryString = (("&" + uri.query).replace(`ns=${namespace}`, "ns=%SYS") + andCSP).slice(1);
643674
return uri.with({ path: `/_vscode/${namespace}${dotMatch[2] || ""}`, query: newQueryString });
644675
} else {
645676
const parts = uri.authority.split(":");
@@ -648,7 +679,7 @@ export function redirectDotvscodeRoot(uri: vscode.Uri): vscode.Uri {
648679
return uri.with({
649680
authority: `${parts[0]}:%SYS`,
650681
path: `/_vscode/${namespace}${dotMatch[2] || ""}`,
651-
query: uri.query + "&csp",
682+
query: uri.query + andCSP,
652683
});
653684
}
654685
}

0 commit comments

Comments
 (0)