Skip to content

Commit fa1e51e

Browse files
justinmk3abhikuhikarandrewyuqJaden Simonleigaol
committed
CodeWhisperer release for April 13, 2023
Co-authored-by: Abhilash Kuhikar <[email protected]> Co-authored-by: Andrew Yu <[email protected]> Co-authored-by: Jaden Simon <[email protected]> Co-authored-by: Lei Gao <[email protected]> Co-authored-by: Meghana Gunuganti <[email protected]> Co-authored-by: Pappu Chaudhary <[email protected]> Co-authored-by: Prateek Chauhan <[email protected]> Co-authored-by: Rachel Cross <[email protected]> Co-authored-by: Shao-Hua Lo <[email protected]> Co-authored-by: Stephen Yuan <[email protected]> Co-authored-by: Tianxing Cheng <[email protected]> Co-authored-by: Wade Fang <[email protected]> Co-authored-by: Walker Cheng <[email protected]> Co-authored-by: Will Lo <[email protected]> Co-authored-by: Zoe Lin <[email protected]>
1 parent e57fac5 commit fa1e51e

File tree

66 files changed

+2833
-1127
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+2833
-1127
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type": "Feature",
3+
"description": "CodeWhisperer: Now also provides import recommendations"
4+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type": "Feature",
3+
"description": "CodeWhisperer: new code scan features: \n1. highlighting scanned files \n2. stop security scan"
4+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type": "Feature",
3+
"description": "CodeWhisperer: new supported programming languages: c, cpp, go, kotlin, php, ruby, rust, scala, shell, sql. "
4+
}

package.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,10 @@
216216
"remoteConnected": {
217217
"type": "boolean",
218218
"default": false
219+
},
220+
"codeWhispererConnectionExpired": {
221+
"type": "boolean",
222+
"default": false
219223
}
220224
},
221225
"additionalProperties": false
@@ -239,6 +243,11 @@
239243
"description": "%AWS.configuration.description.codewhisperer%",
240244
"default": true
241245
},
246+
"aws.codeWhisperer.importRecommendation": {
247+
"type": "boolean",
248+
"description": "%AWS.configuration.description.codewhisperer.importRecommendation%",
249+
"default": true
250+
},
242251
"aws.codeWhisperer.shareCodeWhispererContentWithAWS": {
243252
"type": "boolean",
244253
"markdownDescription": "%AWS.configuration.description.codewhisperer.shareCodeWhispererContentWithAWS%",

package.nls.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@
7070
"AWS.configuration.description.awssam.debug.snippets.api.label.cn": "Amazon SAM: API Gateway lambda invoke",
7171
"AWS.configuration.description.awssam.debug.snippets.api.description.cn": "A new configuration for invoking an Amazon Lambda in a CloudFormation template, simulating API Gateway",
7272
"AWS.configuration.description.codewhisperer": "When checked, CodeWhisperer will include suggestions with code references",
73-
"AWS.configuration.description.codewhisperer.shareCodeWhispererContentWithAWS": "When checked, your content processed by CodeWhisperer may be used for service improvement. Unchecking this box will cause AWS to delete any of your content used for that purpose. The information used to provide the CodeWhisperer service to you will not be affected. See the Preview terms and [Service Terms](https://aws.amazon.com/service-terms/) for more detail.",
73+
"AWS.configuration.description.codewhisperer.shareCodeWhispererContentWithAWS": "When checked, your content processed by CodeWhisperer may be used for service improvement (except for content processed by the Enterprise CodeWhisperer service tier). Unchecking this box will cause AWS to delete any of your content used for that purpose. The information used to provide the CodeWhisperer service to you will not be affected. See the [Service Terms](https://aws.amazon.com/service-terms) for more detail.",
74+
"AWS.configuration.description.codewhisperer.importRecommendation": "CodeWhisperer will add import statements with code suggestions when necessary",
7475
"AWS.command.apig.copyUrl": "Copy URL",
7576
"AWS.command.apig.invokeRemoteRestApi": "Invoke on AWS",
7677
"AWS.command.apig.invokeRemoteRestApi.cn": "Invoke on Amazon",

resources/markdown/WelcomeToCodeWhisperer.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
## Using Amazon CodeWhisperer
22

3-
CodeWhisperer uses machine learning to generate code suggestions from the existing code and comments in your IDE. Supported languages include **Java, Python, JavaScript, C# and TypeScript**.
3+
CodeWhisperer uses machine learning to generate code suggestions from the existing code and comments in your IDE. Supported languages include **Java, Python, JavaScript, C# , TypeScript, C, C++, Go, Rust, PHP, Scala, Kotlin, Ruby, Shell and SQL**.
44

55
---
66

@@ -20,6 +20,12 @@ You can request suggestions at any time. Use **Option-C** on Mac or **ALT-C** on
2020

2121
---
2222

23+
**Customizing keyboard shortcuts**
24+
25+
You can change CodeWhisperer keyboard shortcuts in [Keyboard Shortcuts Editor](https://code.visualstudio.com/docs/getstarted/keybindings). To open Keyboard Shortcuts Editor, go to Settings, and click on Keyboard shortcuts.
26+
27+
---
28+
2329
**Getting the best recommendations**
2430

2531
For best results, follow these practices.

src/codewhisperer/activation.ts

Lines changed: 67 additions & 149 deletions
Large diffs are not rendered by default.

src/codewhisperer/client/codewhisperer.ts

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
* Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
33
* SPDX-License-Identifier: Apache-2.0
44
*/
5-
65
import { AWSError, CognitoIdentityCredentials, Service } from 'aws-sdk'
76
import apiConfig = require('./service-2.json')
87
import userApiConfig = require('./user-service-2.json')
@@ -17,15 +16,10 @@ import { CodeWhispererSettings } from '../util/codewhispererSettings'
1716
import { getCognitoCredentials } from '../util/cognitoIdentity'
1817
import { PromiseResult } from 'aws-sdk/lib/request'
1918
import { getLogger } from '../../shared/logger'
20-
import { throttle } from 'lodash'
2119
import { Credentials } from 'aws-sdk'
2220
import { AuthUtil } from '../util/authUtil'
2321
import { TelemetryHelper } from '../util/telemetryHelper'
24-
25-
const refreshCredentials = throttle(() => {
26-
getLogger().verbose('codewhisperer: invalidating expired credentials')
27-
globals.awsContext.credentialsShim?.refresh()
28-
}, 60000)
22+
import { isSsoConnection } from '../../credentials/auth'
2923

3024
export type ProgrammingLanguage = Readonly<
3125
CodeWhispererClient.ProgrammingLanguage | CodeWhispererUserClient.ProgrammingLanguage
@@ -41,6 +35,7 @@ export type ListRecommendationsResponse =
4135
| CodeWhispererUserClient.GenerateCompletionsResponse
4236
export type GenerateRecommendationsResponse = CodeWhispererClient.GenerateRecommendationsResponse
4337
export type Recommendation = CodeWhispererClient.Recommendation | CodeWhispererUserClient.Completion
38+
export type Completion = CodeWhispererUserClient.Completion
4439
export type Reference = CodeWhispererClient.Reference | CodeWhispererUserClient.Reference
4540
export type References = CodeWhispererClient.References | CodeWhispererUserClient.References
4641
export type CreateUploadUrlRequest = Readonly<
@@ -66,7 +61,8 @@ export type CreateUploadUrlResponse =
6661
export type CreateCodeScanResponse =
6762
| CodeWhispererClient.CreateCodeScanResponse
6863
| CodeWhispererUserClient.StartCodeAnalysisResponse
69-
64+
export type Import = CodeWhispererUserClient.Import
65+
export type Imports = CodeWhispererUserClient.Imports
7066
export class DefaultCodeWhispererClient {
7167
private credentials?: CognitoIdentityCredentials
7268

@@ -93,7 +89,7 @@ export class DefaultCodeWhispererClient {
9389
{
9490
apiConfig: apiConfig,
9591
region: CodeWhispererConstants.region,
96-
credentials: this.credentials,
92+
credentials: this.credentials ?? (await AuthUtil.instance.getCredentials()),
9793
endpoint: CodeWhispererConstants.endpoint,
9894
onRequestSetup: [
9995
req => {
@@ -121,7 +117,7 @@ export class DefaultCodeWhispererClient {
121117
resp.error?.code === 'AccessDeniedException' &&
122118
resp.error.message.match(/expired/i)
123119
) {
124-
refreshCredentials()
120+
AuthUtil.instance.reauthenticate()
125121
resp.error.retryable = true
126122
}
127123
})
@@ -165,12 +161,11 @@ export class DefaultCodeWhispererClient {
165161
}
166162

167163
private isBearerTokenAuth(): boolean {
168-
// return true if access token is cleared because of SSO code path
169164
const accessToken = globals.context.globalState.get<string | undefined>(CodeWhispererConstants.accessToken)
170-
if (!accessToken) {
171-
return true
165+
if (accessToken) {
166+
return false
172167
}
173-
return AuthUtil.instance.isConnected()
168+
return isSsoConnection(AuthUtil.instance.conn)
174169
}
175170

176171
public async generateRecommendations(
@@ -196,9 +191,9 @@ export class DefaultCodeWhispererClient {
196191
request: CreateUploadUrlRequest
197192
): Promise<PromiseResult<CreateUploadUrlResponse, AWSError>> {
198193
if (this.isBearerTokenAuth()) {
199-
return (await this.createUserSdkClient()).createArtifactUploadUrl(request).promise()
194+
return (await this.createUserSdkClient()).createUploadUrl(request).promise()
200195
}
201-
return (await this.createSdkClient()).createUploadUrl(request).promise()
196+
return (await this.createSdkClient()).createCodeScanUploadUrl(request).promise()
202197
}
203198

204199
public async createCodeScan(
Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
{
22
"pagination": {
3-
"ListRecommendations": {
3+
"ListCodeScanFindings": {
4+
"input_token": "nextToken",
5+
"output_token": "nextToken"
6+
},
7+
"ListProfiles": {
48
"input_token": "nextToken",
59
"output_token": "nextToken",
6-
"limit_key": "maxResults"
10+
"limit_key": "maxResults",
11+
"result_key": "profiles"
712
},
8-
"ListSecurityIssues": {
13+
"ListRecommendations": {
914
"input_token": "nextToken",
10-
"output_token": "nextToken"
15+
"output_token": "nextToken",
16+
"limit_key": "maxResults"
1117
}
1218
}
1319
}

0 commit comments

Comments
 (0)