Skip to content

XML Import/Export commands shouldn't assume a server connection in a multi-root workspace #1387

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 1 commit into from
Jun 26, 2024
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
35 changes: 16 additions & 19 deletions src/commands/compile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -812,25 +812,22 @@ interface XMLQuickPickItem extends vscode.QuickPickItem {

export async function importXMLFiles(): Promise<any> {
try {
// Use the server connection from the active document if possible
let connectionUri = currentFile()?.uri;
if (!connectionUri) {
// Use the server connection from a workspace folder
const workspaceFolders = vscode.workspace.workspaceFolders || [];
if (workspaceFolders.length == 0) {
vscode.window.showErrorMessage("'Import XML Files...' command requires an open workspace.", "Dismiss");
} else if (workspaceFolders.length == 1) {
// Use the current connection
connectionUri = workspaceFolders[0].uri;
} else {
// Pick from the workspace folders
connectionUri = (
await vscode.window.showWorkspaceFolderPick({
ignoreFocusOut: true,
placeHolder: "Pick the workspace folder to get server connection information from",
})
)?.uri;
}
// Use the server connection from a workspace folder
let connectionUri: vscode.Uri;
const workspaceFolders = vscode.workspace.workspaceFolders || [];
if (workspaceFolders.length == 0) {
vscode.window.showErrorMessage("'Import XML Files...' command requires an open workspace.", "Dismiss");
} else if (workspaceFolders.length == 1) {
// Use the current connection
connectionUri = workspaceFolders[0].uri;
} else {
// Pick from the workspace folders
connectionUri = (
await vscode.window.showWorkspaceFolderPick({
ignoreFocusOut: true,
placeHolder: "Pick the workspace folder to get server connection information from",
})
)?.uri;
}
if (connectionUri) {
const api = new AtelierAPI(connectionUri);
Expand Down
41 changes: 19 additions & 22 deletions src/commands/export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -385,28 +385,25 @@ export async function exportCurrentFile(): Promise<any> {

export async function exportDocumentsToXMLFile(): Promise<void> {
try {
// Use the server connection from the active document if possible
let connectionUri = currentFile()?.uri;
if (!connectionUri) {
// Use the server connection from a workspace folder
const workspaceFolders = vscode.workspace.workspaceFolders || [];
if (workspaceFolders.length == 0) {
vscode.window.showErrorMessage(
"'Export Documents to XML File...' command requires an open workspace.",
"Dismiss"
);
} else if (workspaceFolders.length == 1) {
// Use the current connection
connectionUri = workspaceFolders[0].uri;
} else {
// Pick from the workspace folders
connectionUri = (
await vscode.window.showWorkspaceFolderPick({
ignoreFocusOut: true,
placeHolder: "Pick the workspace folder to get server connection information from",
})
)?.uri;
}
// Use the server connection from a workspace folder
let connectionUri: vscode.Uri;
const workspaceFolders = vscode.workspace.workspaceFolders || [];
if (workspaceFolders.length == 0) {
vscode.window.showErrorMessage(
"'Export Documents to XML File...' command requires an open workspace.",
"Dismiss"
);
} else if (workspaceFolders.length == 1) {
// Use the current connection
connectionUri = workspaceFolders[0].uri;
} else {
// Pick from the workspace folders
connectionUri = (
await vscode.window.showWorkspaceFolderPick({
ignoreFocusOut: true,
placeHolder: "Pick the workspace folder to get server connection information from",
})
)?.uri;
}
if (connectionUri) {
const api = new AtelierAPI(connectionUri);
Expand Down