Skip to content

Commit a802605

Browse files
authored
Remove unused code (aws#735)
Removing unused code associated with selectLambdaNode. It used to be required for a command that was launched from the Command Palette, which is no longer the case. Also: * Formatter Changes * variable renames
1 parent 94a03e4 commit a802605

File tree

5 files changed

+49
-163
lines changed

5 files changed

+49
-163
lines changed

src/awsexplorer/awsExplorer.ts

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export class AwsExplorer implements vscode.TreeDataProvider<AWSTreeNodeBase>, Re
4040
private readonly regionProvider: RegionProvider,
4141
private readonly resourceFetcher: ResourceFetcher,
4242
private readonly getExtensionAbsolutePath: (relativeExtensionPath: string) => string,
43-
private readonly lambdaOutputChannel: vscode.OutputChannel = vscode.window.createOutputChannel('AWS Lambda'),
43+
private readonly lambdaOutputChannel: vscode.OutputChannel = vscode.window.createOutputChannel('AWS Lambda')
4444
) {
4545
this._onDidChangeTreeData = new vscode.EventEmitter<AWSTreeNodeBase | undefined>()
4646
this.onDidChangeTreeData = this._onDidChangeTreeData.event
@@ -55,12 +55,13 @@ export class AwsExplorer implements vscode.TreeDataProvider<AWSTreeNodeBase>, Re
5555

5656
registerCommand({
5757
command: 'aws.deleteLambda',
58-
callback: async (node: LambdaFunctionNode) => await deleteLambda({
59-
deleteParams: { functionName: node.configuration.FunctionName || '' },
60-
lambdaClient: ext.toolkitClientBuilder.createLambdaClient(node.regionCode),
61-
outputChannel: this.lambdaOutputChannel,
62-
onRefresh: () => this.refresh(node.parent)
63-
}),
58+
callback: async (node: LambdaFunctionNode) =>
59+
await deleteLambda({
60+
deleteParams: { functionName: node.configuration.FunctionName || '' },
61+
lambdaClient: ext.toolkitClientBuilder.createLambdaClient(node.regionCode),
62+
outputChannel: this.lambdaOutputChannel,
63+
onRefresh: () => this.refresh(node.parent)
64+
}),
6465
telemetryName: {
6566
namespace: TelemetryNamespace.Lambda,
6667
name: 'delete'
@@ -69,10 +70,8 @@ export class AwsExplorer implements vscode.TreeDataProvider<AWSTreeNodeBase>, Re
6970

7071
registerCommand({
7172
command: 'aws.deleteCloudFormation',
72-
callback: async (node: CloudFormationStackNode) => await deleteCloudFormation(
73-
() => this.refresh(node.parent),
74-
node
75-
),
73+
callback: async (node: CloudFormationStackNode) =>
74+
await deleteCloudFormation(() => this.refresh(node.parent), node),
7675
telemetryName: {
7776
namespace: TelemetryNamespace.Cloudformation,
7877
name: 'delete'
@@ -86,12 +85,13 @@ export class AwsExplorer implements vscode.TreeDataProvider<AWSTreeNodeBase>, Re
8685

8786
registerCommand({
8887
command: 'aws.invokeLambda',
89-
callback: async (node: FunctionNodeBase) => await invokeLambda({
90-
awsContext: this.awsContext,
91-
element: node,
92-
outputChannel: this.lambdaOutputChannel,
93-
resourceFetcher: this.resourceFetcher
94-
}),
88+
callback: async (node: FunctionNodeBase) =>
89+
await invokeLambda({
90+
awsContext: this.awsContext,
91+
functionNode: node,
92+
outputChannel: this.lambdaOutputChannel,
93+
resourceFetcher: this.resourceFetcher
94+
}),
9595
telemetryName: {
9696
namespace: TelemetryNamespace.Lambda,
9797
name: 'invokeremote'
@@ -134,7 +134,7 @@ export class AwsExplorer implements vscode.TreeDataProvider<AWSTreeNodeBase>, Re
134134
'Unable to load Lambda Functions, click here to retry'
135135
),
136136
'aws.refreshAwsExplorerNode',
137-
[this, element],
137+
[this, element]
138138
)
139139
]
140140
}
@@ -148,7 +148,8 @@ export class AwsExplorer implements vscode.TreeDataProvider<AWSTreeNodeBase>, Re
148148
localize('AWS.explorerNode.signIn', 'Connect to AWS...'),
149149
'aws.login',
150150
undefined,
151-
localize('AWS.explorerNode.signIn.tooltip', 'Connect to AWS using a credential profile'))
151+
localize('AWS.explorerNode.signIn.tooltip', 'Connect to AWS using a credential profile')
152+
)
152153
]
153154
}
154155

@@ -159,10 +160,10 @@ export class AwsExplorer implements vscode.TreeDataProvider<AWSTreeNodeBase>, Re
159160
this.regionNodes,
160161
intersection(regionMap.keys(), explorerRegionCodes),
161162
key => this.regionNodes.get(key)!.update(regionMap.get(key)!),
162-
key => new DefaultRegionNode(
163-
regionMap.get(key)!,
164-
relativeExtensionPath => this.getExtensionAbsolutePath(relativeExtensionPath)
165-
)
163+
key =>
164+
new DefaultRegionNode(regionMap.get(key)!, relativeExtensionPath =>
165+
this.getExtensionAbsolutePath(relativeExtensionPath)
166+
)
166167
)
167168

168169
if (this.regionNodes.size > 0) {
@@ -174,7 +175,8 @@ export class AwsExplorer implements vscode.TreeDataProvider<AWSTreeNodeBase>, Re
174175
localize('AWS.explorerNode.addRegion', 'Click to add a region to view functions...'),
175176
'aws.showRegion',
176177
undefined,
177-
localize('AWS.explorerNode.addRegion.tooltip', 'Configure a region to show available functions'))
178+
localize('AWS.explorerNode.addRegion.tooltip', 'Configure a region to show available functions')
179+
)
178180
]
179181
}
180182
}

src/lambda/commands/invokeLambda.ts

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import { sampleRequestManifestPath, sampleRequestPath } from '../constants'
2020
import { FunctionNodeBase } from '../explorer/functionNode'
2121
import { SampleRequest } from '../models/sampleRequest'
2222
import { LambdaTemplates } from '../templates/lambdaTemplates'
23-
import { selectLambdaNode } from '../utils'
2423

2524
interface SampleRequestManifest {
2625
requests: {
@@ -43,19 +42,18 @@ export async function invokeLambda(params: {
4342
* invokeParams: {functionArn: string} // or Lambda.Types.InvocationRequest (see: lambda.d.ts)
4443
* }
4544
*/
46-
awsContext: AwsContext, // TODO: Consider replacing 'awsContext' with something specific and meaningful
47-
outputChannel: vscode.OutputChannel,
48-
resourceFetcher: ResourceFetcher,
49-
element?: FunctionNodeBase, // TODO: Consider replacing 'element'' with something specific and meaningful
45+
awsContext: AwsContext // TODO: Consider replacing 'awsContext' with something specific and meaningful
46+
outputChannel: vscode.OutputChannel
47+
resourceFetcher: ResourceFetcher
48+
functionNode: FunctionNodeBase // TODO: Consider replacing 'element'' with something specific and meaningful
5049
}) {
51-
5250
const logger: Logger = getLogger()
5351

5452
try {
55-
const fn: FunctionNodeBase = await selectLambdaNode(params.awsContext, params.element)
53+
const functionNode = params.functionNode
5654
const view = vscode.window.createWebviewPanel(
5755
'html',
58-
`Invoked ${fn.configuration.FunctionName}`,
56+
`Invoked ${functionNode.configuration.FunctionName}`,
5957
vscode.ViewColumn.One,
6058
{
6159
// Enable scripts in the webview
@@ -93,7 +91,7 @@ export async function invokeLambda(params: {
9391
return
9492
}
9593

96-
_.forEach(result.requests.request, (r) => {
94+
_.forEach(result.requests.request, r => {
9795
inputs.push({ name: r.name, filename: r.filename })
9896
})
9997
})
@@ -105,20 +103,20 @@ export async function invokeLambda(params: {
105103

106104
view.webview.html = baseTemplateFn({
107105
content: invokeTemplateFn({
108-
FunctionName: fn.configuration.FunctionName,
106+
FunctionName: functionNode.configuration.FunctionName,
109107
InputSamples: inputs,
110108
Scripts: loadScripts,
111109
Libraries: loadLibs
112-
}),
110+
})
113111
})
114112

115113
view.webview.onDidReceiveMessage(
116114
createMessageReceivedFunc({
117-
fn,
115+
fn: functionNode,
118116
outputChannel: params.outputChannel,
119117
resourceFetcher: params.resourceFetcher,
120118
resourcePath: resourcePath,
121-
onPostMessage: message => view.webview.postMessage(message)
119+
onPostMessage: message => view.webview.postMessage(message)
122120
}),
123121
undefined,
124122
ext.context.subscriptions
@@ -132,15 +130,18 @@ export async function invokeLambda(params: {
132130
}
133131
}
134132

135-
function createMessageReceivedFunc({fn, outputChannel, ...restParams}: {
133+
function createMessageReceivedFunc({
134+
fn,
135+
outputChannel,
136+
...restParams
137+
}: {
136138
// TODO: Consider passing lambdaClient: LambdaClient
137-
fn: FunctionNodeBase, // TODO: Replace w/ invokeParams: {functionArn: string} // or Lambda.Types.InvocationRequest
139+
fn: FunctionNodeBase // TODO: Replace w/ invokeParams: {functionArn: string} // or Lambda.Types.InvocationRequest
138140
outputChannel: vscode.OutputChannel
139-
resourceFetcher: ResourceFetcher,
140-
resourcePath: string,
141+
resourceFetcher: ResourceFetcher
142+
resourcePath: string
141143
onPostMessage(message: any): Thenable<boolean>
142144
}) {
143-
144145
const logger: Logger = getLogger()
145146

146147
return async (message: CommandMessage) => {
@@ -172,13 +173,8 @@ function createMessageReceivedFunc({fn, outputChannel, ...restParams}: {
172173
throw new Error(`Could not determine ARN for function ${fn.configuration.FunctionName}`)
173174
}
174175
const client: LambdaClient = ext.toolkitClientBuilder.createLambdaClient(fn.regionCode)
175-
const funcResponse = await client.invoke(
176-
fn.configuration.FunctionArn,
177-
message.value
178-
)
179-
const logs = funcResponse.LogResult ?
180-
Buffer.from(funcResponse.LogResult, 'base64').toString() :
181-
''
176+
const funcResponse = await client.invoke(fn.configuration.FunctionArn, message.value)
177+
const logs = funcResponse.LogResult ? Buffer.from(funcResponse.LogResult, 'base64').toString() : ''
182178
const payload = funcResponse.Payload ? funcResponse.Payload : JSON.stringify({})
183179

184180
outputChannel.appendLine(`Invocation result for ${fn.configuration.FunctionArn}`)

src/lambda/commands/quickPickLambda.ts

Lines changed: 0 additions & 52 deletions
This file was deleted.

src/lambda/utils.ts

Lines changed: 2 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -8,48 +8,8 @@ const localize = nls.loadMessageBundle()
88

99
import { CloudFormation, Lambda } from 'aws-sdk'
1010
import * as vscode from 'vscode'
11-
import { AwsContext } from '../shared/awsContext'
1211
import { CloudFormationClient } from '../shared/clients/cloudFormationClient'
1312
import { LambdaClient } from '../shared/clients/lambdaClient'
14-
import { ext } from '../shared/extensionGlobals'
15-
import { getLogger, Logger } from '../shared/logger'
16-
import { toArrayAsync } from '../shared/utilities/collectionUtils'
17-
import { quickPickLambda } from './commands/quickPickLambda'
18-
import { FunctionNodeBase } from './explorer/functionNode'
19-
20-
export async function selectLambdaNode(
21-
awsContext: AwsContext,
22-
element?: FunctionNodeBase
23-
): Promise<FunctionNodeBase> {
24-
25-
const logger: Logger = getLogger()
26-
27-
if (element && element.configuration) {
28-
logger.info('returning preselected node...')
29-
30-
return element
31-
}
32-
33-
logger.info('prompting for lambda selection...')
34-
35-
// TODO: we need to change this into a multi-step command to first obtain the region,
36-
// then query the lambdas in the region
37-
const regions = await awsContext.getExplorerRegions()
38-
if (regions.length === 0) {
39-
throw new Error('No regions defined for explorer, required until we have a multi-stage picker')
40-
}
41-
const client: LambdaClient = ext.toolkitClientBuilder.createLambdaClient(regions[0])
42-
const lambdas: Lambda.FunctionConfiguration[] = await toArrayAsync(listLambdaFunctions(client))
43-
44-
// used to show a list of lambdas and allow user to select.
45-
// this is useful for calling commands from the command palette
46-
const selection = await quickPickLambda(lambdas, regions[0])
47-
if (selection && selection.configuration) {
48-
return selection
49-
}
50-
51-
throw new Error('No lambda found.')
52-
}
5313

5414
export async function* listCloudFormationStacks(
5515
client: CloudFormationClient
@@ -68,13 +28,12 @@ export async function* listCloudFormationStacks(
6828
}
6929

7030
export async function* listLambdaFunctions(client: LambdaClient): AsyncIterableIterator<Lambda.FunctionConfiguration> {
71-
7231
const status = vscode.window.setStatusBarMessage(
73-
localize('AWS.message.statusBar.loading.lambda', 'Loading Lambdas...'))
32+
localize('AWS.message.statusBar.loading.lambda', 'Loading Lambdas...')
33+
)
7434

7535
try {
7636
yield* client.listFunctions()
77-
7837
} finally {
7938
if (!!status) {
8039
status.dispose()

src/shared/quickPickNode.ts

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)