Skip to content

Commit 24578d6

Browse files
authored
refactor: create helper to identify remote workspaces (#4915)
Problem: - We are constantly making the same remote workspace check Solution: - Extract it
1 parent bb5c707 commit 24578d6

File tree

4 files changed

+11
-6
lines changed

4 files changed

+11
-6
lines changed

packages/core/src/codecatalyst/commands.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import { CreateDevEnvironmentRequest, UpdateDevEnvironmentRequest } from 'aws-sd
2626
import { Auth } from '../auth/auth'
2727
import { SsoConnection } from '../auth/connection'
2828
import { getShowManageConnections } from '../auth/ui/vue/show'
29-
import { isInDevEnv } from '../shared/vscode/env'
29+
import { isInDevEnv, isRemoteWorkspace } from '../shared/vscode/env'
3030

3131
/** "List CodeCatalyst Commands" command. */
3232
export async function listCommands(): Promise<void> {
@@ -231,7 +231,7 @@ export class CodeCatalystCommands {
231231
}
232232

233233
public createDevEnv(): Promise<void> {
234-
if (vscode.env.remoteName === 'ssh-remote' && isInDevEnv()) {
234+
if (isRemoteWorkspace() && isInDevEnv()) {
235235
throw new RemoteContextError()
236236
}
237237
return this.withClient(showCreateDevEnv, globals.context, CodeCatalystCommands.declared)
@@ -280,7 +280,7 @@ export class CodeCatalystCommands {
280280
targetPath?: string,
281281
connection?: { startUrl: string; region: string }
282282
): Promise<void> {
283-
if (vscode.env.remoteName === 'ssh-remote' && isInDevEnv()) {
283+
if (isRemoteWorkspace() && isInDevEnv()) {
284284
throw new RemoteContextError()
285285
}
286286

packages/core/src/codewhisperer/commands/basicCommands.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import { SecurityIssueCodeActionProvider } from '../service/securityIssueCodeAct
4141
import { SsoAccessTokenProvider } from '../../auth/sso/ssoAccessTokenProvider'
4242
import { SystemUtilities } from '../../shared/systemUtilities'
4343
import { ToolkitError } from '../../shared/errors'
44+
import { isRemoteWorkspace } from '../../shared/vscode/env'
4445

4546
export const toggleCodeSuggestions = Commands.declare(
4647
{ id: 'aws.amazonq.toggleCodeSuggestion', compositeKey: { 1: 'source' } },
@@ -301,7 +302,7 @@ export const fetchFeatureConfigsCmd = Commands.declare(
301302
export const installAmazonQExtension = Commands.declare(
302303
{ id: 'aws.toolkit.installAmazonQExtension', logging: true },
303304
() => async () => {
304-
if (vscode.env.remoteName === 'ssh-remote') {
305+
if (isRemoteWorkspace()) {
305306
/**
306307
* due to a bug in https://github.com/microsoft/vscode/pull/206381/files#diff-efa08c29460835c0ffa740d751c34078033fd6cb6c7b031500fb31f524655de2R360
307308
* installExtension will fail on remote environments when the amazon q extension is already installed locally.

packages/core/src/shared/telemetry/util.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { env, Memento, version } from 'vscode'
88
import { getLogger } from '../logger'
99
import { fromExtensionManifest, migrateSetting, Settings } from '../settings'
1010
import { shared } from '../utilities/functionUtils'
11-
import { isInDevEnv, extensionVersion, isAutomation } from '../vscode/env'
11+
import { isInDevEnv, extensionVersion, isAutomation, isRemoteWorkspace } from '../vscode/env'
1212
import { addTypeName } from '../utilities/typeConstructors'
1313
import globals, { isWeb } from '../extensionGlobals'
1414
import { mapMetadata } from './telemetryLogger'
@@ -154,7 +154,7 @@ export function getComputeEnvType(): EnvType {
154154
return 'codecatalyst'
155155
} else if (isSageMaker()) {
156156
return 'sagemaker'
157-
} else if (env.remoteName === 'ssh-remote' && !isInDevEnv()) {
157+
} else if (isRemoteWorkspace() && !isInDevEnv()) {
158158
return 'ec2'
159159
} else if (env.remoteName) {
160160
return 'wsl'

packages/core/src/shared/vscode/env.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ export function isInDevEnv(): boolean {
9292
return !!getCodeCatalystDevEnvId()
9393
}
9494

95+
export function isRemoteWorkspace(): boolean {
96+
return vscode.env.remoteName === 'ssh-remote'
97+
}
98+
9599
export function getCodeCatalystProjectName(): string | undefined {
96100
return process.env['__DEV_ENVIRONMENT_PROJECT_NAME']
97101
}

0 commit comments

Comments
 (0)