Skip to content

Fix resolving of server connection for files opened from InterSystems Explorer or XML preview #1622

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1959,7 +1959,8 @@ export async function activate(context: vscode.ExtensionContext): Promise<any> {
// This function is exported as one of our API functions but is also used internally
// for example to implement the async variant capable of resolving docker port number.
function serverForUri(uri: vscode.Uri): any {
const { apiTarget } = connectionTarget(uri);
const { apiTarget, configName } = connectionTarget(uri);
const configNameLower = configName.toLowerCase();
const api = new AtelierAPI(apiTarget);

// This function intentionally no longer exposes the password for a named server UNLESS it is already exposed as plaintext in settings.
Expand Down Expand Up @@ -1991,7 +1992,18 @@ function serverForUri(uri: vscode.Uri): any {
password:
serverName === ""
? password
: vscode.workspace.getConfiguration(`intersystems.servers.${serverName.toLowerCase()}`, uri).get("password"),
: vscode.workspace
.getConfiguration(
`intersystems.servers.${serverName.toLowerCase()}`,
// objectscript(xml):// URIs are not in any workspace folder,
// so make sure we resolve the server definition with the proper
// granularity. This is needed to prevent other extensions like
// Language Server prompting for a passwoord when it's not needed.
[OBJECTSCRIPT_FILE_SCHEMA, OBJECTSCRIPTXML_FILE_SCHEMA].includes(uri.scheme)
? vscode.workspace.workspaceFolders?.find((f) => f.name.toLowerCase() == configNameLower)?.uri
: uri
)
.get("password"),
namespace: ns,
apiVersion: active ? apiVersion : undefined,
serverVersion: active ? serverVersion : undefined,
Expand Down
26 changes: 19 additions & 7 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
documentContentProvider,
filesystemSchemas,
outputLangId,
OBJECTSCRIPTXML_FILE_SCHEMA,
} from "../extension";
import { getCategory } from "../commands/export";
import { isCSP, isfsDocumentName } from "../providers/FileSystemProvider/FileSystemProvider";
Expand Down Expand Up @@ -334,14 +335,21 @@ export function connectionTarget(uri?: vscode.Uri): ConnectionTarget {
? vscode.window.activeTextEditor.document.uri
: undefined;
if (uri) {
if (notIsfs(uri)) {
const folder = vscode.workspace.getWorkspaceFolder(uri);
if (uri.scheme == OBJECTSCRIPT_FILE_SCHEMA) {
// For objectscript:// files the authority is the workspace folder name
result.apiTarget = uri;
result.configName = uri.authority;
} else if (notIsfs(uri)) {
const folder = vscode.workspace.getWorkspaceFolder(
// For XML preview files the fragment contains the URI for connection purposes
uri.scheme == OBJECTSCRIPTXML_FILE_SCHEMA ? vscode.Uri.parse(uri.fragment) : uri
);
// Active document might not be from any folder in the workspace (e.g. user's settings.json)
if (folder) {
result.configName = folder.name;
result.apiTarget = result.configName;
}
} else if (schemas.includes(uri.scheme)) {
} else {
result.apiTarget = uri;
const parts = uri.authority.split(":");
result.configName = parts.length === 2 ? parts[0] : uri.authority;
Expand Down Expand Up @@ -390,10 +398,14 @@ export function currentWorkspaceFolder(document?: vscode.TextDocument): string {
}

export function workspaceFolderOfUri(uri: vscode.Uri): string {
if (notIsfs(uri)) {
if (vscode.workspace.getWorkspaceFolder(uri)) {
return vscode.workspace.getWorkspaceFolder(uri).name;
}
if (uri.scheme == OBJECTSCRIPT_FILE_SCHEMA) {
// For objectscript:// files the authority is the workspace folder name
return uri.authority;
} else if (uri.scheme == OBJECTSCRIPTXML_FILE_SCHEMA) {
// For XML preview files the fragment contains the URI of the original XML file
return vscode.workspace.getWorkspaceFolder(vscode.Uri.parse(uri.fragment))?.name ?? "";
} else if (notIsfs(uri)) {
return vscode.workspace.getWorkspaceFolder(uri)?.name ?? "";
} else {
const rootUri = uri.with({ path: "/" }).toString();
const foundFolder = vscode.workspace.workspaceFolders.find(
Expand Down