Skip to content

Commit afe1a39

Browse files
authored
fix(codecatalyst): menu command fails after using tree node aws#4870
Problem: The codecatalyst commands: "Open Dev Environment" "Clone Repository" fail if their menu forms are used AFTER the treenode forms. Steps to reproduce: 1. click the "Open Dev Environment" tree node in the codecatalyst panel. 2. close the wizard. 3. in the codecatalyst panel, expand the "..." root menu and choose "Open CodeCatalyst Dev Environment" 4. it fails because the TreeNode from step (1) is passed as the first arg, which breaks `openDevEnv()`. Solution: Follow the instructions from the `VsCodeCommandArg` docstring: https://github.com/aws/aws-toolkit-vscode/blob/4decdf6341a38c58db0e9f778ba57b5514434b0b/packages/core/src/shared/vscode/commands2.ts#L23-L41 TODO: Note that the bug does NOT occur if you use the "..." menu command FIRST. It seems like the TreeNode is stored as state on the `CommandResource`; is that actually necessary?
1 parent 4d22231 commit afe1a39

File tree

5 files changed

+16
-9
lines changed

5 files changed

+16
-9
lines changed

packages/core/src/codecatalyst/commands.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import * as vscode from 'vscode'
1212
import { selectCodeCatalystRepository, selectCodeCatalystResource } from './wizards/selectResource'
1313
import { openCodeCatalystUrl } from './utils'
1414
import { CodeCatalystAuthenticationProvider } from './auth'
15-
import { Commands, placeholder } from '../shared/vscode/commands2'
15+
import { Commands, VsCodeCommandArg, placeholder } from '../shared/vscode/commands2'
1616
import { CodeCatalystClient, CodeCatalystResource, createClient } from '../shared/clients/codecatalystClient'
1717
import { DevEnvironmentId, getConnectedDevEnv, openDevEnv } from './model'
1818
import { showConfigureDevEnv } from './vue/configure/backend'
@@ -226,11 +226,11 @@ export class CodeCatalystCommands {
226226
return listCommands()
227227
}
228228

229-
public cloneRepository(...args: WithClient<typeof cloneCodeCatalystRepo>) {
229+
public cloneRepo(_?: VsCodeCommandArg, ...args: WithClient<typeof cloneCodeCatalystRepo>) {
230230
return this.withClient(cloneCodeCatalystRepo, ...args)
231231
}
232232

233-
public createDevEnv(): Promise<void> {
233+
public createDevEnv(_?: VsCodeCommandArg): Promise<void> {
234234
if (isRemoteWorkspace() && isInDevEnv()) {
235235
throw new RemoteContextError()
236236
}
@@ -276,6 +276,7 @@ export class CodeCatalystCommands {
276276
}
277277

278278
public async openDevEnv(
279+
_?: VsCodeCommandArg,
279280
id?: DevEnvironmentId,
280281
targetPath?: string,
281282
connection?: { startUrl: string; region: string }
@@ -337,7 +338,7 @@ export class CodeCatalystCommands {
337338
deleteDevEnv: Commands.from(this).declareDeleteDevEnv('aws.codecatalyst.deleteDevEnv'),
338339
openDevEnvSettings: Commands.from(this).declareOpenDevEnvSettings('aws.codecatalyst.openDevEnvSettings'),
339340
openDevfile: Commands.from(this).declareOpenDevfile('aws.codecatalyst.openDevfile'),
340-
cloneRepo: Commands.from(this).declareCloneRepository({
341+
cloneRepo: Commands.from(this).declareCloneRepo({
341342
id: 'aws.codecatalyst.cloneRepo',
342343
telemetryName: 'codecatalyst_localClone',
343344
}),

packages/core/src/codecatalyst/uriHandlers.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,15 @@ export function register(
2727
) {
2828
async function cloneHandler(params: ReturnType<typeof parseCloneParams>) {
2929
if (params.url.authority.endsWith(getCodeCatalystConfig().gitHostname)) {
30-
await commands.cloneRepo.execute(params.url)
30+
await commands.cloneRepo.execute(undefined, params.url)
3131
} else {
3232
await vscode.commands.executeCommand('git.clone', params.url.toString())
3333
}
3434
}
3535

3636
async function connectHandler(params: ConnectParams) {
3737
await commands.openDevEnv.execute(
38+
undefined,
3839
{
3940
id: params.devEnvironmentId,
4041
org: { name: params.spaceName },

packages/core/src/codecatalyst/vue/create/backend.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ export class CodeCatalystCreateWebview extends VueWebview {
183183

184184
public async submit(settings: DevEnvironmentSettings, source: SourceResponse) {
185185
const devenv = await this.createDevEnvOfType(settings, source)
186-
void this.commands.openDevEnv.execute(devenv)
186+
void this.commands.openDevEnv.execute(undefined, devenv)
187187
}
188188

189189
public async createDevEnvOfType(settings: DevEnvironmentSettings, source: SourceResponse) {

packages/core/src/shared/logger/activation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export async function activate(
6363
'debugConsole'
6464
)
6565

66-
getLogger().debug(`Logging started: ${logUri}`)
66+
getLogger().debug(`Logging started: ${logUri ?? '(no file)'}`)
6767

6868
Logging.init(logUri, mainLogger, contextPrefix)
6969
extensionContext.subscriptions.push(Logging.instance.viewLogs, Logging.instance.viewLogsAtMessage)

packages/core/src/test/codecatalyst/uriHandlers.test.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ describe('CodeCatalyst handlers', function () {
100100
it('returns builder ID SSO if IdC params are not present', async function () {
101101
await handler.handleUri(createConnectUri(params))
102102
assert.ok(
103-
openDevEnvMock.calledWith(devenvId, undefined, {
103+
openDevEnvMock.calledWith(sinon.match.any, devenvId, undefined, {
104104
startUrl: builderIdStartUrl,
105105
region: defaultSsoRegion,
106106
})
@@ -111,7 +111,12 @@ describe('CodeCatalyst handlers', function () {
111111
const ssoStartUrl = 'https://my-url'
112112
const ssoRegion = 'us-west-2'
113113
await handler.handleUri(createConnectUri({ ...params, sso_start_url: ssoStartUrl, sso_region: ssoRegion }))
114-
assert.ok(openDevEnvMock.calledWith(devenvId, undefined, { startUrl: ssoStartUrl, region: ssoRegion }))
114+
assert.ok(
115+
openDevEnvMock.calledWith(sinon.match.any, devenvId, undefined, {
116+
startUrl: ssoStartUrl,
117+
region: ssoRegion,
118+
})
119+
)
115120
})
116121

117122
it('checks that the environment exists', async function () {

0 commit comments

Comments
 (0)