Skip to content

Commit 0014758

Browse files
committed
Fix #347: Pass CSP path for CSP files
1 parent 76858e1 commit 0014758

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

src/commands/studio.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as vscode from "vscode";
22
import { AtelierAPI } from "../api";
33
import { config, FILESYSTEM_SCHEMA } from "../extension";
4-
import { outputChannel, outputConsole, currentFile } from "../utils";
4+
import { outputChannel, outputConsole, currentFile, getServerName } from "../utils";
55
import { DocumentContentProvider } from "../providers/DocumentContentProvider";
66
import { ClassNode } from "../explorer/models/classNode";
77
import { PackageNode } from "../explorer/models/packageNode";
@@ -68,7 +68,7 @@ class StudioActions {
6868
if (uriOrNode instanceof vscode.Uri) {
6969
const uri: vscode.Uri = uriOrNode;
7070
this.uri = uri;
71-
this.name = this.uri.path.slice(1).replace(/\//g, ".");
71+
this.name = getServerName(uri);
7272
this.api = new AtelierAPI(uri);
7373
} else if (uriOrNode) {
7474
const node: NodeBase = uriOrNode;

src/utils/index.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,37 @@ export function connectionTarget(uri?: vscode.Uri): ConnectionTarget {
181181
return result;
182182
}
183183

184+
/**
185+
* Given a URI, returns a server name for it if it is under isfs[-readonly] or null if it is not an isfs file.
186+
* @param uri URI to evaluate
187+
*/
188+
export function getServerName(uri: vscode.Uri): string {
189+
if (!schemas.includes(uri.scheme)) {
190+
return null;
191+
}
192+
if (isCSP(uri)) {
193+
// The full file path is the server name of the file.
194+
return uri.path;
195+
} else {
196+
// Complex case: replace folder slashes with dots.
197+
return uri.path.slice(1).replace(/\//g, ".");
198+
}
199+
}
200+
201+
/**
202+
* Returns true if the specified URI is a CSP file under isfs, false if not.
203+
* @param uri URI to test
204+
*/
205+
export function isCSP(uri: vscode.Uri): boolean {
206+
return (
207+
schemas.includes(uri.scheme) &&
208+
uri.query
209+
.split("&")
210+
.map((e) => e.split("=")[0])
211+
.includes("csp")
212+
);
213+
}
214+
184215
export function currentWorkspaceFolder(document?: vscode.TextDocument): string {
185216
document = document ? document : vscode.window.activeTextEditor && vscode.window.activeTextEditor.document;
186217
if (document) {

0 commit comments

Comments
 (0)