@@ -13,6 +13,7 @@ import {
1313 documentContentProvider ,
1414 filesystemSchemas ,
1515 outputLangId ,
16+ OBJECTSCRIPTXML_FILE_SCHEMA ,
1617} from "../extension" ;
1718import { getCategory } from "../commands/export" ;
1819import { isCSP , isfsDocumentName } from "../providers/FileSystemProvider/FileSystemProvider" ;
@@ -334,14 +335,21 @@ export function connectionTarget(uri?: vscode.Uri): ConnectionTarget {
334335 ? vscode . window . activeTextEditor . document . uri
335336 : undefined ;
336337 if ( uri ) {
337- if ( notIsfs ( uri ) ) {
338- const folder = vscode . workspace . getWorkspaceFolder ( uri ) ;
338+ if ( uri . scheme == OBJECTSCRIPT_FILE_SCHEMA ) {
339+ // For objectscript:// files the authority is the workspace folder name
340+ result . apiTarget = uri ;
341+ result . configName = uri . authority ;
342+ } else if ( notIsfs ( uri ) ) {
343+ const folder = vscode . workspace . getWorkspaceFolder (
344+ // For XML preview files the fragment contains the URI for connection purposes
345+ uri . scheme == OBJECTSCRIPTXML_FILE_SCHEMA ? vscode . Uri . parse ( uri . fragment ) : uri
346+ ) ;
339347 // Active document might not be from any folder in the workspace (e.g. user's settings.json)
340348 if ( folder ) {
341349 result . configName = folder . name ;
342350 result . apiTarget = result . configName ;
343351 }
344- } else if ( schemas . includes ( uri . scheme ) ) {
352+ } else {
345353 result . apiTarget = uri ;
346354 const parts = uri . authority . split ( ":" ) ;
347355 result . configName = parts . length === 2 ? parts [ 0 ] : uri . authority ;
@@ -390,10 +398,14 @@ export function currentWorkspaceFolder(document?: vscode.TextDocument): string {
390398}
391399
392400export function workspaceFolderOfUri ( uri : vscode . Uri ) : string {
393- if ( notIsfs ( uri ) ) {
394- if ( vscode . workspace . getWorkspaceFolder ( uri ) ) {
395- return vscode . workspace . getWorkspaceFolder ( uri ) . name ;
396- }
401+ if ( uri . scheme == OBJECTSCRIPT_FILE_SCHEMA ) {
402+ // For objectscript:// files the authority is the workspace folder name
403+ return uri . authority ;
404+ } else if ( uri . scheme == OBJECTSCRIPTXML_FILE_SCHEMA ) {
405+ // For XML preview files the fragment contains the URI of the original XML file
406+ return vscode . workspace . getWorkspaceFolder ( vscode . Uri . parse ( uri . fragment ) ) ?. name ?? "" ;
407+ } else if ( notIsfs ( uri ) ) {
408+ return vscode . workspace . getWorkspaceFolder ( uri ) ?. name ?? "" ;
397409 } else {
398410 const rootUri = uri . with ( { path : "/" } ) . toString ( ) ;
399411 const foundFolder = vscode . workspace . workspaceFolders . find (
0 commit comments