From 7526c0b9c192a74810327c6837ae75df81c5a787 Mon Sep 17 00:00:00 2001 From: gjsjohnmurray Date: Wed, 12 Feb 2025 00:49:41 +0000 Subject: [PATCH 1/3] Make a webapp ISFS folder fall back to the folder-specific settings of its namespace --- src/extension.ts | 7 +++++++ src/utils/index.ts | 39 +++++++++++++++++++++++++++++++++++---- 2 files changed, 42 insertions(+), 4 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index 2c328767..fbe55575 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -101,6 +101,7 @@ import { cspApps, otherDocExts, getWsServerConnection, + addWsServerRootFolderData, } from "./utils"; import { ObjectScriptDiagnosticProvider } from "./providers/ObjectScriptDiagnosticProvider"; import { DocumentLinkProvider } from "./providers/DocumentLinkProvider"; @@ -802,6 +803,9 @@ export async function activate(context: vscode.ExtensionContext): Promise { continue; } } + for await (const workspaceFolder of vscode.workspace.workspaceFolders) { + await addWsServerRootFolderData(workspaceFolder.uri); + } xmlContentProvider = new XmlContentProvider(); @@ -1321,6 +1325,9 @@ export async function activate(context: vscode.ExtensionContext): Promise { const serverName = notIsfs(uri) ? config("conn", configName).server : configName; await resolveConnectionSpec(serverName); } + for await (const workspaceFolder of added) { + await addWsServerRootFolderData(workspaceFolder.uri); + } }), vscode.workspace.onDidChangeConfiguration(async ({ affectsConfiguration }) => { if (affectsConfiguration("objectscript.conn") || affectsConfiguration("intersystems.servers")) { diff --git a/src/utils/index.ts b/src/utils/index.ts index 0fc548ba..a7691b8d 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -617,6 +617,32 @@ export async function shellWithDocker(): Promise { return terminal; } +interface WSServerRootFolderData { + redirectDotvscode: boolean; +} + +const wsServerRootFolders = new Map(); + +/** + * Add uri to the wsServerRootFolders map if eligible + */ +export async function addWsServerRootFolderData(uri: vscode.Uri): Promise { + if (!schemas.includes(uri.scheme)) { + return; + } + const value: WSServerRootFolderData = { + redirectDotvscode: true, + }; + if (isCSPFile(uri)) { + // A CSP-type root folder that already has a .vscode/settings.json file must not redirect .vscode/* references + const api = new AtelierAPI(uri); + api.getDoc(`${uri.path}/.vscode/settings.json`).then(() => { + value.redirectDotvscode = false; + }); + } + wsServerRootFolders.set(uri.toString(), value); +} + /** * Alter isfs-type uri.path of /.vscode/* files or subdirectories. * Rewrite `/.vscode/path/to/file` as `/_vscode/XYZ/path/to/file` @@ -633,13 +659,18 @@ export function redirectDotvscodeRoot(uri: vscode.Uri): vscode.Uri { if (!schemas.includes(uri.scheme)) { return uri; } - const dotMatch = uri.path.match(/^\/(\.[^/]*)(\/.*)?$/); - if (dotMatch && dotMatch[1] === ".vscode") { + const dotMatch = uri.path.match(/^(.*)\/\.vscode(\/.*)?$/); + if (dotMatch) { + const dotvscodeRoot = uri.with({ path: dotMatch[1] || "/" }); + if (!wsServerRootFolders.get(dotvscodeRoot.toString())?.redirectDotvscode) { + return uri; + } let namespace: string; + const andCSP = !isCSPFile(uri) ? "&csp" : ""; const nsMatch = `&${uri.query}&`.match(/&ns=([^&]+)&/); if (nsMatch) { namespace = nsMatch[1].toUpperCase(); - const newQueryString = (("&" + uri.query).replace(`ns=${namespace}`, "ns=%SYS") + "&csp").slice(1); + const newQueryString = (("&" + uri.query).replace(`ns=${namespace}`, "ns=%SYS") + andCSP).slice(1); return uri.with({ path: `/_vscode/${namespace}${dotMatch[2] || ""}`, query: newQueryString }); } else { const parts = uri.authority.split(":"); @@ -648,7 +679,7 @@ export function redirectDotvscodeRoot(uri: vscode.Uri): vscode.Uri { return uri.with({ authority: `${parts[0]}:%SYS`, path: `/_vscode/${namespace}${dotMatch[2] || ""}`, - query: uri.query + "&csp", + query: uri.query + andCSP, }); } } From a999e5eb2efff772eefd8f4d0623662eefe4b5de Mon Sep 17 00:00:00 2001 From: gjsjohnmurray Date: Wed, 12 Feb 2025 23:02:20 +0000 Subject: [PATCH 2/3] Changes after PR comments --- src/extension.ts | 4 ++-- src/utils/index.ts | 13 ++++++++----- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index fbe55575..16c90beb 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -803,7 +803,7 @@ export async function activate(context: vscode.ExtensionContext): Promise { continue; } } - for await (const workspaceFolder of vscode.workspace.workspaceFolders) { + for await (const workspaceFolder of vscode.workspace.workspaceFolders ?? []) { await addWsServerRootFolderData(workspaceFolder.uri); } @@ -1344,7 +1344,7 @@ export async function activate(context: vscode.ExtensionContext): Promise { } // Check connections sequentially for each workspace folder let refreshFilesExplorer = false; - for await (const folder of vscode.workspace.workspaceFolders) { + for await (const folder of vscode.workspace.workspaceFolders ?? []) { if (schemas.includes(folder.uri.scheme)) { refreshFilesExplorer = true; } diff --git a/src/utils/index.ts b/src/utils/index.ts index a7691b8d..4929d35c 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -633,12 +633,15 @@ export async function addWsServerRootFolderData(uri: vscode.Uri): Promise const value: WSServerRootFolderData = { redirectDotvscode: true, }; - if (isCSPFile(uri)) { - // A CSP-type root folder that already has a .vscode/settings.json file must not redirect .vscode/* references + if (isCSPFile(uri) && !["", "/"].includes(uri.path)) { + // A CSP-type root folder for a specific webapp that already has a .vscode/settings.json file must not redirect .vscode/* references const api = new AtelierAPI(uri); - api.getDoc(`${uri.path}/.vscode/settings.json`).then(() => { - value.redirectDotvscode = false; - }); + api + .headDoc(`${uri.path}/.vscode/settings.json`) + .then(() => { + value.redirectDotvscode = false; + }) + .catch(() => {}); } wsServerRootFolders.set(uri.toString(), value); } From 36a479ccfcb9780201137f1bc11ec2c28fd13e0f Mon Sep 17 00:00:00 2001 From: gjsjohnmurray Date: Thu, 13 Feb 2025 16:44:14 +0000 Subject: [PATCH 3/3] Handle optional trailing slash on path --- src/utils/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/index.ts b/src/utils/index.ts index 4929d35c..3df1485d 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -637,7 +637,7 @@ export async function addWsServerRootFolderData(uri: vscode.Uri): Promise // A CSP-type root folder for a specific webapp that already has a .vscode/settings.json file must not redirect .vscode/* references const api = new AtelierAPI(uri); api - .headDoc(`${uri.path}/.vscode/settings.json`) + .headDoc(`${uri.path}${!uri.path.endsWith("/") ? "/" : ""}.vscode/settings.json`) .then(() => { value.redirectDotvscode = false; })