Skip to content

Make a webapp ISFS folder fall back to the folder-specific settings of its namespace #1479

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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