Skip to content

Commit e8c4b63

Browse files
authored
Merge branch 'master' into notification
2 parents af5b318 + b753e82 commit e8c4b63

File tree

19 files changed

+355
-76
lines changed

19 files changed

+355
-76
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type": "Bug Fix",
3+
"description": "Fix broken inline suggestion auto-trigger on Systemverfilog files if users dont have systemverilog extension installed and enabled"
4+
}

packages/amazonq/test/unit/codewhisperer/util/runtimeLanguageContext.test.ts

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55

66
import assert from 'assert'
7-
import { resetCodeWhispererGlobalVariables } from 'aws-core-vscode/test'
7+
import { resetCodeWhispererGlobalVariables, toTextDocument } from 'aws-core-vscode/test'
88
import { runtimeLanguageContext, RuntimeLanguageContext, PlatformLanguageId } from 'aws-core-vscode/codewhisperer'
99
import * as codewhispererClient from 'aws-core-vscode/codewhisperer'
1010
import { CodewhispererLanguage } from 'aws-core-vscode/shared'
@@ -61,6 +61,61 @@ describe('runtimeLanguageContext', function () {
6161
assert.strictEqual(actual, expected)
6262
})
6363
})
64+
65+
describe('test isLanguageSupported with document as the argument', function () {
66+
const cases: [string, boolean][] = [
67+
['helloJava.java', true],
68+
['helloPython.py', true],
69+
['helloJavascript.js', true],
70+
['helloJsx.jsx', true],
71+
['helloTypescript.ts', true],
72+
['helloTsx.tsx', true],
73+
['helloCsharp.cs', true],
74+
['helloC.c', true],
75+
['helloC.h', true],
76+
['helloCpp.cpp', true],
77+
['helloCpp.cc', true],
78+
['helloGo.go', true],
79+
['helloKotlin.kt', true],
80+
['helloPhp.php', true],
81+
['helloRuby.rb', true],
82+
['helloRust.rs', true],
83+
['helloScala.scala', true],
84+
['helloShellscript.sh', true],
85+
['helloSql.sql', true],
86+
['helloSystemVerilog.svh', true],
87+
['helloSystemVerilog.sv', true],
88+
['helloSystemVerilog.vh', true],
89+
['helloDart.dart', true],
90+
['helloLua.lua', true],
91+
['helloLua.wlua', true],
92+
['helloSwift.swift', true],
93+
['helloVue.vue', true],
94+
['helloPowerShell.ps1', true],
95+
['helloPowerShell.psm1', true],
96+
['helloR.r', true],
97+
['helloJson.json', true],
98+
['helloYaml.yaml', true],
99+
['helloYaml.yml', true],
100+
['helloTf.tf', true],
101+
['helloPlaintext.txt', false],
102+
['helloHtml.html', false],
103+
['helloCss.css', false],
104+
['helloUnknown', false],
105+
['helloFoo.foo', false],
106+
]
107+
108+
cases.forEach((tuple) => {
109+
const fileName = tuple[0]
110+
const expected = tuple[1]
111+
112+
it(`pass document ${fileName} as argument should first try determine by languageId then file extensions`, async function () {
113+
const doc = await toTextDocument('', fileName)
114+
const actual = languageContext.isLanguageSupported(doc)
115+
assert.strictEqual(actual, expected)
116+
})
117+
})
118+
})
64119
})
65120

66121
describe('test getLanguageContext', function () {

packages/core/src/codewhisperer/activation.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ export async function activate(context: ExtContext): Promise<void> {
478478
if (e.document !== editor.document) {
479479
return
480480
}
481-
if (!runtimeLanguageContext.isLanguageSupported(e.document.languageId)) {
481+
if (!runtimeLanguageContext.isLanguageSupported(e.document)) {
482482
return
483483
}
484484

@@ -549,7 +549,7 @@ export async function activate(context: ExtContext): Promise<void> {
549549
if (e.document !== editor.document) {
550550
return
551551
}
552-
if (!runtimeLanguageContext.isLanguageSupported(e.document.languageId)) {
552+
if (!runtimeLanguageContext.isLanguageSupported(e.document)) {
553553
return
554554
}
555555
/**

packages/core/src/codewhisperer/models/model.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,8 @@ export class TransformByQState {
413413

414414
private metadataPathSQL: string = ''
415415

416+
private linesOfCodeSubmitted: number | undefined = undefined
417+
416418
private planFilePath: string = ''
417419
private summaryFilePath: string = ''
418420
private preBuildLogFilePath: string = ''
@@ -485,6 +487,10 @@ export class TransformByQState {
485487
return this.customBuildCommand
486488
}
487489

490+
public getLinesOfCodeSubmitted() {
491+
return this.linesOfCodeSubmitted
492+
}
493+
488494
public getPreBuildLogFilePath() {
489495
return this.preBuildLogFilePath
490496
}
@@ -645,6 +651,10 @@ export class TransformByQState {
645651
this.customBuildCommand = command
646652
}
647653

654+
public setLinesOfCodeSubmitted(lines: number) {
655+
this.linesOfCodeSubmitted = lines
656+
}
657+
648658
public setStartTime(time: string) {
649659
this.startTime = time
650660
}

packages/core/src/codewhisperer/service/transformByQ/transformApiHandler.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,7 @@ export async function getTransformationPlan(jobId: string) {
573573
const linesOfCode = Number(
574574
jobStatistics.find((stat: { name: string; value: string }) => stat.name === 'linesOfCode').value
575575
)
576+
transformByQState.setLinesOfCodeSubmitted(linesOfCode)
576577
if (authType === 'iamIdentityCenter' && linesOfCode > CodeWhispererConstants.codeTransformLocThreshold) {
577578
plan += CodeWhispererConstants.codeTransformBillingText(linesOfCode)
578579
}

packages/core/src/codewhisperer/service/transformByQ/transformationResultsViewProvider.ts

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { parsePatch, applyPatches, ParsedDiff } from 'diff'
1010
import path from 'path'
1111
import vscode from 'vscode'
1212
import { ExportIntent } from '@amzn/codewhisperer-streaming'
13-
import { TransformByQReviewStatus, transformByQState } from '../../models/model'
13+
import { TransformationType, TransformByQReviewStatus, transformByQState } from '../../models/model'
1414
import { ExportResultArchiveStructure, downloadExportResultArchive } from '../../../shared/utilities/download'
1515
import { getLogger } from '../../../shared/logger'
1616
import { telemetry } from '../../../shared/telemetry/telemetry'
@@ -20,6 +20,7 @@ import * as CodeWhispererConstants from '../../models/constants'
2020
import { createCodeWhispererChatStreamingClient } from '../../../shared/clients/codewhispererChatClient'
2121
import { ChatSessionManager } from '../../../amazonqGumby/chat/storages/chatSession'
2222
import { setContext } from '../../../shared/vscode/setContext'
23+
import * as codeWhisperer from '../../client/codewhisperer'
2324

2425
export abstract class ProposedChangeNode {
2526
abstract readonly resourcePath: string
@@ -402,6 +403,33 @@ export class ProposedTransformationExplorer {
402403
`${CodeWhispererConstants.errorDeserializingDiffNotification} ${deserializeErrorMessage}`
403404
)
404405
}
406+
407+
try {
408+
const metricsPath = path.join(pathContainingArchive, ExportResultArchiveStructure.PathToMetrics)
409+
const metricsData = JSON.parse(fs.readFileSync(metricsPath, 'utf8'))
410+
411+
await codeWhisperer.codeWhispererClient.sendTelemetryEvent({
412+
telemetryEvent: {
413+
transformEvent: {
414+
jobId: transformByQState.getJobId(),
415+
timestamp: new Date(),
416+
ideCategory: 'VSCODE',
417+
programmingLanguage: {
418+
languageName:
419+
transformByQState.getTransformationType() === TransformationType.LANGUAGE_UPGRADE
420+
? 'JAVA'
421+
: 'SQL',
422+
},
423+
linesOfCodeChanged: metricsData.linesOfCodeChanged,
424+
charsOfCodeChanged: metricsData.charactersOfCodeChanged,
425+
linesOfCodeSubmitted: transformByQState.getLinesOfCodeSubmitted(), // currently unavailable for SQL conversions
426+
},
427+
},
428+
})
429+
} catch (err: any) {
430+
// log error, but continue to show user diff.patch with results
431+
getLogger().error(`CodeTransformation: SendTelemetryEvent error = ${err.message}`)
432+
}
405433
})
406434

407435
vscode.commands.registerCommand('aws.amazonq.transformationHub.reviewChanges.acceptChanges', async () => {

packages/core/src/codewhisperer/util/runtimeLanguageContext.ts

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6+
import * as vscode from 'vscode'
67
import { getLogger } from '../../shared/logger/logger'
78
import { CodewhispererLanguage } from '../../shared/telemetry/telemetry.gen'
89
import { createConstantMap, ConstantMap } from '../../shared/utilities/tsUtils'
910
import * as codewhispererClient from '../client/codewhisperer'
1011
import * as CodeWhispererConstants from '../models/constants'
12+
import * as path from 'path'
1113

1214
type RuntimeLanguage = Exclude<CodewhispererLanguage, 'jsx' | 'tsx' | 'systemVerilog'> | 'systemverilog'
1315

@@ -106,7 +108,10 @@ export class RuntimeLanguageContext {
106108
})
107109
this.supportedLanguageExtensionMap = createConstantMap<string, CodewhispererLanguage>({
108110
c: 'c',
111+
h: 'c',
109112
cpp: 'cpp',
113+
cc: 'cpp',
114+
'c++': 'cpp',
110115
cs: 'csharp',
111116
go: 'go',
112117
hcl: 'tf',
@@ -251,24 +256,24 @@ export class RuntimeLanguageContext {
251256
}
252257
}
253258

254-
/**
255-
*
256-
* @param languageId: either vscodeLanguageId or CodewhispererLanguage
257-
* @returns true if the language is supported by CodeWhisperer otherwise false
258-
*/
259-
public isLanguageSupported(languageId: string): boolean {
260-
const lang = this.normalizeLanguage(languageId)
261-
switch (lang) {
262-
case undefined:
263-
return false
259+
public isLanguageSupported(languageId: string): boolean
260+
public isLanguageSupported(doc: vscode.TextDocument): boolean
261+
public isLanguageSupported(arg: string | vscode.TextDocument): boolean {
262+
if (typeof arg === 'string') {
263+
const normalizedLanguageId = this.normalizeLanguage(arg)
264+
const byLanguageId = !normalizedLanguageId || normalizedLanguageId === 'plaintext' ? false : true
264265

265-
case 'plaintext':
266-
return false
266+
return byLanguageId
267+
} else {
268+
const normalizedLanguageId = this.normalizeLanguage(arg.languageId)
269+
const byLanguageId = !normalizedLanguageId || normalizedLanguageId === 'plaintext' ? false : true
270+
const extension = path.extname(arg.uri.fsPath)
271+
const byFileExtension = this.isFileFormatSupported(extension.substring(1))
267272

268-
default:
269-
return true
273+
return byLanguageId || byFileExtension
270274
}
271275
}
276+
272277
/**
273278
*
274279
* @param fileFormat : vscode editor filecontext filename extension

packages/core/src/codewhisperer/views/lineAnnotationController.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ export class LineAnnotationController implements vscode.Disposable {
430430
}
431431

432432
// Disable Tips when language is not supported by Amazon Q.
433-
if (!runtimeLanguageContext.isLanguageSupported(editor.document.languageId)) {
433+
if (!runtimeLanguageContext.isLanguageSupported(editor.document)) {
434434
return
435435
}
436436

packages/core/src/codewhispererChat/controllers/chat/controller.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ import { globals, waitUntil } from '../../../shared'
5353
import { telemetry } from '../../../shared/telemetry'
5454
import { Auth } from '../../../auth'
5555
import { isSsoConnection } from '../../../auth/connection'
56+
import { inspect } from '../../../shared/utilities/collectionUtils'
5657

5758
export interface ChatControllerMessagePublishers {
5859
readonly processPromptChatMessage: MessagePublisher<PromptMessage>
@@ -656,7 +657,11 @@ export class ChatController {
656657

657658
const request = triggerPayloadToChatRequest(triggerPayload)
658659
const session = this.sessionStorage.getSession(tabID)
659-
getLogger().info(`request from tab: ${tabID} conversationID: ${session.sessionIdentifier} request: %O`, request)
660+
getLogger().info(
661+
`request from tab: ${tabID} conversationID: ${session.sessionIdentifier} request: ${inspect(request, {
662+
depth: 12,
663+
})}`
664+
)
660665
let response: MessengerResponseType | undefined = undefined
661666
session.createNewTokenSource()
662667
try {
@@ -681,8 +686,7 @@ export class ChatController {
681686
getLogger().info(
682687
`response to tab: ${tabID} conversationID: ${session.sessionIdentifier} requestID: ${
683688
response.$metadata.requestId
684-
} metadata: %O`,
685-
response.$metadata
689+
} metadata: ${inspect(response.$metadata, { depth: 12 })}`
686690
)
687691
await this.messenger.sendAIResponse(response, session, tabID, triggerID, triggerPayload)
688692
} catch (e: any) {

packages/core/src/login/webview/vue/types.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,5 +81,4 @@ export type AuthFormId =
8181
| 'identityCenterCodeWhisperer'
8282
| 'identityCenterCodeCatalyst'
8383
| 'identityCenterExplorer'
84-
| 'aggregateExplorer'
8584
| 'unknown'

0 commit comments

Comments
 (0)