Skip to content

Commit

Permalink
refactor: move some gumby out of CW files (aws#4425)
Browse files Browse the repository at this point in the history
We are moving gumby commands since this causes CW
to import gumby, and gumby code uses fs-extra, and
this breaks browser mode

Signed-off-by: nkomonen <[email protected]>
  • Loading branch information
nkomonen-amazon authored Feb 13, 2024
1 parent 772c53f commit a8a6d6b
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ import * as vscode from 'vscode'
import * as nls from 'vscode-nls'
import { Commands, placeholder } from '../../shared/vscode/commands2'
import { getIcon } from '../../shared/icons'
import { reconnect, showTransformByQ } from '../../codewhisperer/commands/basicCommands'
import { reconnect } from '../../codewhisperer/commands/basicCommands'
import { transformByQState } from '../../codewhisperer/models/model'
import * as CodeWhispererConstants from '../../codewhisperer/models/constants'
import { amazonQHelpUrl } from '../../shared/constants'
import { cwTreeNodeSource } from '../../codewhisperer/commands/types'
import { telemetry } from '../../shared/telemetry/telemetry'
import { focusAmazonQPanel } from '../../auth/ui/vue/show'
import { showTransformByQ } from '../../amazonqGumby/commands'

const localize = nls.loadMessageBundle()

Expand Down
2 changes: 1 addition & 1 deletion packages/toolkit/src/amazonqGumby/activation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import * as vscode from 'vscode'
import { Commands } from '../shared/vscode/commands2'
import { TransformationHubViewProvider } from '../codewhisperer/service/transformationHubViewProvider'
import { showTransformByQ, showTransformationHub } from '../codewhisperer/commands/basicCommands'
import { showTransformByQ, showTransformationHub } from './commands'
import { ExtContext } from '../shared/extensions'
import { startTransformByQWithProgress, confirmStopTransformByQ } from '../codewhisperer/commands/startTransformByQ'
import { transformByQState } from '../codewhisperer/models/model'
Expand Down
47 changes: 47 additions & 0 deletions packages/toolkit/src/amazonqGumby/commands.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*!
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/

import * as vscode from 'vscode'
import { telemetry } from '../shared/telemetry/telemetry'
import { ExtContext } from '../shared/extensions'
import { Commands } from '../shared/vscode/commands2'
import * as CodeWhispererConstants from '../codewhisperer/models/constants'
import { startTransformByQWithProgress, confirmStopTransformByQ } from '../codewhisperer/commands/startTransformByQ'
import { transformByQState } from '../codewhisperer/models/model'
import { AuthUtil } from '../codewhisperer/util/authUtil'
import { CancelActionPositions, logCodeTransformInitiatedMetric } from './telemetry/codeTransformTelemetry'

export const showTransformByQ = Commands.declare(
{ id: 'aws.awsq.transform', compositeKey: { 0: 'source' } },
(context: ExtContext) => async (source: string) => {
if (AuthUtil.instance.isConnectionExpired()) {
await AuthUtil.instance.notifyReauthenticate()
}

if (transformByQState.isNotStarted()) {
logCodeTransformInitiatedMetric(source)
await startTransformByQWithProgress()
} else if (transformByQState.isCancelled()) {
void vscode.window.showInformationMessage(CodeWhispererConstants.cancellationInProgressMessage)
} else if (transformByQState.isRunning()) {
await confirmStopTransformByQ(transformByQState.getJobId(), CancelActionPositions.DevToolsSidePanel)
}
// emit telemetry if clicked from tree node
if (source === CodeWhispererConstants.transformTreeNode) {
telemetry.ui_click.emit({
elementId: 'amazonq_transform',
passive: false,
})
}
await Commands.tryExecute('aws.codeWhisperer.refresh')
}
)

export const showTransformationHub = Commands.declare(
{ id: 'aws.amazonq.showTransformationHub', compositeKey: { 0: 'source' } },
() => async (source: string) => {
await vscode.commands.executeCommand('workbench.view.extension.aws-codewhisperer-transformation-hub')
}
)
40 changes: 1 addition & 39 deletions packages/toolkit/src/codewhisperer/commands/basicCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ import { Commands, VsCodeCommandArg } from '../../shared/vscode/commands2'
import * as CodeWhispererConstants from '../models/constants'
import { DefaultCodeWhispererClient } from '../client/codewhisperer'
import { startSecurityScanWithProgress, confirmStopSecurityScan } from './startSecurityScan'
import { startTransformByQWithProgress, confirmStopTransformByQ } from './startTransformByQ'
import { SecurityPanelViewProvider } from '../views/securityPanelViewProvider'
import { CodeScanIssue, codeScanState, CodeSuggestionsState, transformByQState } from '../models/model'
import { CodeScanIssue, codeScanState, CodeSuggestionsState } from '../models/model'
import { connectToEnterpriseSso, getStartUrl } from '../util/getStartUrl'
import { showCodeWhispererConnectionPrompt } from '../util/showSsoPrompt'
import { ReferenceLogViewProvider } from '../service/referenceLogViewProvider'
Expand All @@ -32,10 +31,6 @@ import { fsCommon } from '../../srcShared/fs'
import { Mutable } from '../../shared/utilities/tsUtils'
import { CodeWhispererSource } from './types'
import { showManageConnections } from '../../auth/ui/vue/show'
import {
CancelActionPositions,
logCodeTransformInitiatedMetric,
} from '../../amazonqGumby/telemetry/codeTransformTelemetry'
import { FeatureConfigProvider } from '../service/featureConfigProvider'

export const toggleCodeSuggestions = Commands.declare(
Expand Down Expand Up @@ -113,39 +108,6 @@ export const showSecurityScan = Commands.declare(
}
)

export const showTransformByQ = Commands.declare(
{ id: 'aws.awsq.transform', compositeKey: { 0: 'source' } },
(context: ExtContext) => async (source: string) => {
if (AuthUtil.instance.isConnectionExpired()) {
await AuthUtil.instance.notifyReauthenticate()
}

if (transformByQState.isNotStarted()) {
logCodeTransformInitiatedMetric(source)
await startTransformByQWithProgress()
} else if (transformByQState.isCancelled()) {
void vscode.window.showInformationMessage(CodeWhispererConstants.cancellationInProgressMessage)
} else if (transformByQState.isRunning()) {
await confirmStopTransformByQ(transformByQState.getJobId(), CancelActionPositions.DevToolsSidePanel)
}
// emit telemetry if clicked from tree node
if (source === CodeWhispererConstants.transformTreeNode) {
telemetry.ui_click.emit({
elementId: 'amazonq_transform',
passive: false,
})
}
await Commands.tryExecute('aws.codeWhisperer.refresh')
}
)

export const showTransformationHub = Commands.declare(
{ id: 'aws.amazonq.showTransformationHub', compositeKey: { 0: 'source' } },
() => async (source: string) => {
await vscode.commands.executeCommand('workbench.view.extension.aws-codewhisperer-transformation-hub')
}
)

export const selectCustomizationPrompt = Commands.declare(
{ id: 'aws.codeWhisperer.selectCustomization', compositeKey: { 1: 'source' } },
() => async (_: VsCodeCommandArg, source: CodeWhispererSource) => {
Expand Down

0 comments on commit a8a6d6b

Please sign in to comment.