Skip to content

Commit e271d13

Browse files
authored
Fix resolving of server connection for files opened from InterSystems Explorer or XML preview (#1622)
1 parent 445046f commit e271d13

File tree

2 files changed

+33
-9
lines changed

2 files changed

+33
-9
lines changed

src/extension.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1959,7 +1959,8 @@ export async function activate(context: vscode.ExtensionContext): Promise<any> {
19591959
// This function is exported as one of our API functions but is also used internally
19601960
// for example to implement the async variant capable of resolving docker port number.
19611961
function serverForUri(uri: vscode.Uri): any {
1962-
const { apiTarget } = connectionTarget(uri);
1962+
const { apiTarget, configName } = connectionTarget(uri);
1963+
const configNameLower = configName.toLowerCase();
19631964
const api = new AtelierAPI(apiTarget);
19641965

19651966
// This function intentionally no longer exposes the password for a named server UNLESS it is already exposed as plaintext in settings.
@@ -1991,7 +1992,18 @@ function serverForUri(uri: vscode.Uri): any {
19911992
password:
19921993
serverName === ""
19931994
? password
1994-
: vscode.workspace.getConfiguration(`intersystems.servers.${serverName.toLowerCase()}`, uri).get("password"),
1995+
: vscode.workspace
1996+
.getConfiguration(
1997+
`intersystems.servers.${serverName.toLowerCase()}`,
1998+
// objectscript(xml):// URIs are not in any workspace folder,
1999+
// so make sure we resolve the server definition with the proper
2000+
// granularity. This is needed to prevent other extensions like
2001+
// Language Server prompting for a passwoord when it's not needed.
2002+
[OBJECTSCRIPT_FILE_SCHEMA, OBJECTSCRIPTXML_FILE_SCHEMA].includes(uri.scheme)
2003+
? vscode.workspace.workspaceFolders?.find((f) => f.name.toLowerCase() == configNameLower)?.uri
2004+
: uri
2005+
)
2006+
.get("password"),
19952007
namespace: ns,
19962008
apiVersion: active ? apiVersion : undefined,
19972009
serverVersion: active ? serverVersion : undefined,

src/utils/index.ts

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
documentContentProvider,
1414
filesystemSchemas,
1515
outputLangId,
16+
OBJECTSCRIPTXML_FILE_SCHEMA,
1617
} from "../extension";
1718
import { getCategory } from "../commands/export";
1819
import { 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

392400
export 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

Comments
 (0)