File tree Expand file tree Collapse file tree 2 files changed +33
-2
lines changed Expand file tree Collapse file tree 2 files changed +33
-2
lines changed Original file line number Diff line number Diff line change 1
1
import * as vscode from "vscode" ;
2
2
import { AtelierAPI } from "../api" ;
3
3
import { config , FILESYSTEM_SCHEMA } from "../extension" ;
4
- import { outputChannel , outputConsole , currentFile } from "../utils" ;
4
+ import { outputChannel , outputConsole , currentFile , getServerName } from "../utils" ;
5
5
import { DocumentContentProvider } from "../providers/DocumentContentProvider" ;
6
6
import { ClassNode } from "../explorer/models/classNode" ;
7
7
import { PackageNode } from "../explorer/models/packageNode" ;
@@ -68,7 +68,7 @@ class StudioActions {
68
68
if ( uriOrNode instanceof vscode . Uri ) {
69
69
const uri : vscode . Uri = uriOrNode ;
70
70
this . uri = uri ;
71
- this . name = this . uri . path . slice ( 1 ) . replace ( / \/ / g , "." ) ;
71
+ this . name = getServerName ( uri ) ;
72
72
this . api = new AtelierAPI ( uri ) ;
73
73
} else if ( uriOrNode ) {
74
74
const node : NodeBase = uriOrNode ;
Original file line number Diff line number Diff line change @@ -181,6 +181,37 @@ export function connectionTarget(uri?: vscode.Uri): ConnectionTarget {
181
181
return result ;
182
182
}
183
183
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
+
184
215
export function currentWorkspaceFolder ( document ?: vscode . TextDocument ) : string {
185
216
document = document ? document : vscode . window . activeTextEditor && vscode . window . activeTextEditor . document ;
186
217
if ( document ) {
You can’t perform that action at this time.
0 commit comments