Skip to content

Commit

Permalink
Make a webapp ISFS folder fall back to the folder-specific settings o…
Browse files Browse the repository at this point in the history
…f its namespace (intersystems-community#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
  • Loading branch information
gjsjohnmurray authored Feb 13, 2025
1 parent aae0541 commit 8f78f91
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 5 deletions.
9 changes: 8 additions & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ import {
cspApps,
otherDocExts,
getWsServerConnection,
addWsServerRootFolderData,
} from "./utils";
import { ObjectScriptDiagnosticProvider } from "./providers/ObjectScriptDiagnosticProvider";
import { DocumentLinkProvider } from "./providers/DocumentLinkProvider";
Expand Down Expand Up @@ -802,6 +803,9 @@ export async function activate(context: vscode.ExtensionContext): Promise<any> {
continue;
}
}
for await (const workspaceFolder of vscode.workspace.workspaceFolders ?? []) {
await addWsServerRootFolderData(workspaceFolder.uri);
}

xmlContentProvider = new XmlContentProvider();

Expand Down Expand Up @@ -1321,6 +1325,9 @@ export async function activate(context: vscode.ExtensionContext): Promise<any> {
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")) {
Expand All @@ -1337,7 +1344,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<any> {
}
// 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;
}
Expand Down
42 changes: 38 additions & 4 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,35 @@ export async function shellWithDocker(): Promise<vscode.Terminal> {
return terminal;
}

interface WSServerRootFolderData {
redirectDotvscode: boolean;
}

const wsServerRootFolders = new Map<string, WSServerRootFolderData>();

/**
* Add uri to the wsServerRootFolders map if eligible
*/
export async function addWsServerRootFolderData(uri: vscode.Uri): Promise<void> {
if (!schemas.includes(uri.scheme)) {
return;
}
const value: WSServerRootFolderData = {
redirectDotvscode: true,
};
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
.headDoc(`${uri.path}${!uri.path.endsWith("/") ? "/" : ""}.vscode/settings.json`)
.then(() => {
value.redirectDotvscode = false;
})
.catch(() => {});
}
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`
Expand All @@ -633,13 +662,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(":");
Expand All @@ -648,7 +682,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,
});
}
}
Expand Down

0 comments on commit 8f78f91

Please sign in to comment.