Skip to content
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

Enable Attach Emulator on Linux #2450

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
1 change: 1 addition & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*--------------------------------------------------------------------------------------------*/

export const isWindows: boolean = /^win/.test(process.platform);
export const isLinux: boolean = /^linux/.test(process.platform);

import * as fs from 'fs';
import assert from 'node:assert';
Expand Down
7 changes: 4 additions & 3 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import {
type ITreeItemPickerContext,
} from '@microsoft/vscode-azext-utils';
import { AzExtResourceType, getAzureResourcesExtensionApi } from '@microsoft/vscode-azureresources-api';
import { platform } from 'os';
import * as vscode from 'vscode';
import { findTreeItem } from './commands/api/findTreeItem';
import { pickTreeItem } from './commands/api/pickTreeItem';
Expand All @@ -36,6 +35,8 @@ import {
cosmosMongoFilter,
cosmosTableFilter,
doubleClickDebounceDelay,
isLinux,
isWindows,
sqlFilter,
} from './constants';
import { DatabasesFileSystem } from './DatabasesFileSystem';
Expand Down Expand Up @@ -142,10 +143,10 @@ export async function activateInternal(
},
);
registerCommandWithTreeNodeUnwrapping('cosmosDB.attachEmulator', async (actionContext: IActionContext) => {
if (platform() !== 'win32') {
if (!isWindows && !isLinux) {
actionContext.errorHandling.suppressReportIssue = true;
throw new Error(
localize('emulatorNotSupported', 'The Cosmos DB emulator is only supported on Windows.'),
localize('emulatorNotSupported', 'The Cosmos DB emulator is only supported on Windows and Linux.'),
);
}

Expand Down
7 changes: 4 additions & 3 deletions src/tree/AttachedAccountsTreeItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { type MongoClient } from 'mongodb';
import * as vscode from 'vscode';
import { API, getExperienceFromApi, getExperienceQuickPick, getExperienceQuickPicks } from '../AzureDBExperiences';
import { removeTreeItemFromCache } from '../commands/api/apiCache';
import { emulatorPassword, isWindows } from '../constants';
import { emulatorPassword, isLinux, isWindows } from '../constants';
import { parseDocDBConnectionString } from '../docdb/docDBConnectionStrings';
import { type CosmosDBCredential } from '../docdb/getCosmosClient';
import { DocDBAccountTreeItem } from '../docdb/tree/DocDBAccountTreeItem';
Expand Down Expand Up @@ -47,7 +47,8 @@ export const MONGO_CONNECTION_EXPECTED: string = 'Connection string must start w
const localMongoConnectionString: string = 'mongodb://127.0.0.1:27017';

export class AttachedAccountsTreeItem extends AzExtParentTreeItem {
public static contextValue: string = 'cosmosDBAttachedAccounts' + (isWindows ? 'WithEmulator' : 'WithoutEmulator');
public static contextValue: string =
'cosmosDBAttachedAccounts' + (isWindows || isLinux ? 'WithEmulator' : 'WithoutEmulator');
public readonly contextValue: string = AttachedAccountsTreeItem.contextValue;
public readonly label: string = 'Attached Database Accounts';
public childTypeLabel: string = 'Account';
Expand Down Expand Up @@ -141,7 +142,7 @@ export class AttachedAccountsTreeItem extends AzExtParentTreeItem {
commandId: 'cosmosDB.attachEmulator',
includeInTreeItemPicker: true,
});
return isWindows ? [attachDatabaseAccount, attachEmulator] : [attachDatabaseAccount];
return isWindows || isLinux ? [attachDatabaseAccount, attachEmulator] : [attachDatabaseAccount];
}

public isAncestorOfImpl(contextValue: string): boolean {
Expand Down