Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
7 changes: 7 additions & 0 deletions 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 Down
39 changes: 35 additions & 4 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,32 @@ 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)) {
// 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`
Expand All @@ -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(":");
Expand All @@ -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,
});
}
}
Expand Down