Skip to content

Commit cdc143a

Browse files
committed
Merge remote-tracking branch 'upstream/master' into fix-client-side
2 parents f5cf5f0 + 8f78f91 commit cdc143a

File tree

3 files changed

+47
-6
lines changed

3 files changed

+47
-6
lines changed

src/commands/addServerNamespaceToWorkspace.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ export async function addServerNamespaceToWorkspace(resource?: vscode.Uri): Prom
146146
const params = new URLSearchParams(uri.query);
147147
const project = params.get("project");
148148
const csp = params.has("csp");
149-
const name = `${project ? `${project} - ` : ""}${serverName}:${namespace}${csp ? " web files" : ""}${
149+
const name = `${project ? `${project} - ${serverName}:${namespace}` : !csp ? `${serverName}:${namespace}` : ["", "/"].includes(uri.path) ? `${serverName}:${namespace} web files` : `${serverName} (${uri.path})`}${
150150
scheme == FILESYSTEM_READONLY_SCHEMA && !project ? " (read-only)" : ""
151151
}`;
152152
// Append it to the workspace

src/extension.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ import {
102102
otherDocExts,
103103
getWsServerConnection,
104104
isClassOrRtn,
105+
addWsServerRootFolderData,
105106
} from "./utils";
106107
import { ObjectScriptDiagnosticProvider } from "./providers/ObjectScriptDiagnosticProvider";
107108
import { DocumentLinkProvider } from "./providers/DocumentLinkProvider";
@@ -803,6 +804,9 @@ export async function activate(context: vscode.ExtensionContext): Promise<any> {
803804
continue;
804805
}
805806
}
807+
for await (const workspaceFolder of vscode.workspace.workspaceFolders ?? []) {
808+
await addWsServerRootFolderData(workspaceFolder.uri);
809+
}
806810

807811
xmlContentProvider = new XmlContentProvider();
808812

@@ -1322,6 +1326,9 @@ export async function activate(context: vscode.ExtensionContext): Promise<any> {
13221326
const serverName = notIsfs(uri) ? config("conn", configName).server : configName;
13231327
await resolveConnectionSpec(serverName);
13241328
}
1329+
for await (const workspaceFolder of added) {
1330+
await addWsServerRootFolderData(workspaceFolder.uri);
1331+
}
13251332
}),
13261333
vscode.workspace.onDidChangeConfiguration(async ({ affectsConfiguration }) => {
13271334
if (affectsConfiguration("objectscript.conn") || affectsConfiguration("intersystems.servers")) {
@@ -1338,7 +1345,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<any> {
13381345
}
13391346
// Check connections sequentially for each workspace folder
13401347
let refreshFilesExplorer = false;
1341-
for await (const folder of vscode.workspace.workspaceFolders) {
1348+
for await (const folder of vscode.workspace.workspaceFolders ?? []) {
13421349
if (schemas.includes(folder.uri.scheme)) {
13431350
refreshFilesExplorer = true;
13441351
}

src/utils/index.ts

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,35 @@ 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) && !["", "/"].includes(uri.path)) {
637+
// A CSP-type root folder for a specific webapp that already has a .vscode/settings.json file must not redirect .vscode/* references
638+
const api = new AtelierAPI(uri);
639+
api
640+
.headDoc(`${uri.path}${!uri.path.endsWith("/") ? "/" : ""}.vscode/settings.json`)
641+
.then(() => {
642+
value.redirectDotvscode = false;
643+
})
644+
.catch(() => {});
645+
}
646+
wsServerRootFolders.set(uri.toString(), value);
647+
}
648+
620649
/**
621650
* Alter isfs-type uri.path of /.vscode/* files or subdirectories.
622651
* Rewrite `/.vscode/path/to/file` as `/_vscode/XYZ/path/to/file`
@@ -633,13 +662,18 @@ export function redirectDotvscodeRoot(uri: vscode.Uri): vscode.Uri {
633662
if (!schemas.includes(uri.scheme)) {
634663
return uri;
635664
}
636-
const dotMatch = uri.path.match(/^\/(\.[^/]*)(\/.*)?$/);
637-
if (dotMatch && dotMatch[1] === ".vscode") {
665+
const dotMatch = uri.path.match(/^(.*)\/\.vscode(\/.*)?$/);
666+
if (dotMatch) {
667+
const dotvscodeRoot = uri.with({ path: dotMatch[1] || "/" });
668+
if (!wsServerRootFolders.get(dotvscodeRoot.toString())?.redirectDotvscode) {
669+
return uri;
670+
}
638671
let namespace: string;
672+
const andCSP = !isCSPFile(uri) ? "&csp" : "";
639673
const nsMatch = `&${uri.query}&`.match(/&ns=([^&]+)&/);
640674
if (nsMatch) {
641675
namespace = nsMatch[1].toUpperCase();
642-
const newQueryString = (("&" + uri.query).replace(`ns=${namespace}`, "ns=%SYS") + "&csp").slice(1);
676+
const newQueryString = (("&" + uri.query).replace(`ns=${namespace}`, "ns=%SYS") + andCSP).slice(1);
643677
return uri.with({ path: `/_vscode/${namespace}${dotMatch[2] || ""}`, query: newQueryString });
644678
} else {
645679
const parts = uri.authority.split(":");
@@ -648,7 +682,7 @@ export function redirectDotvscodeRoot(uri: vscode.Uri): vscode.Uri {
648682
return uri.with({
649683
authority: `${parts[0]}:%SYS`,
650684
path: `/_vscode/${namespace}${dotMatch[2] || ""}`,
651-
query: uri.query + "&csp",
685+
query: uri.query + andCSP,
652686
});
653687
}
654688
}

0 commit comments

Comments
 (0)