Skip to content

Commit

Permalink
chore: eslint config to catch floating-promises (#728)
Browse files Browse the repository at this point in the history
* chore: eslint config to catch floating-promises

* chore: fix prettier

* chore(release): release packages from branch main (#729)

* chore(release): release packages from branch main

* chore: trigger github actions for release please

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Ege Ozcan <[email protected]>

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Ege Ozcan <[email protected]>
  • Loading branch information
3 people authored Jan 17, 2025
1 parent 5aa9933 commit 1c38b0c
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 56 deletions.
7 changes: 6 additions & 1 deletion server/aws-lsp-codewhisperer/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
module.exports = {
root: true,
parser: '@typescript-eslint/parser',
plugins: ['import'],
parserOptions: {
projectService: true,
tsconfigRootDir: __dirname,
},
plugins: ['import', '@typescript-eslint'],
rules: {
'import/no-nodejs-modules': 'warn',
'@typescript-eslint/no-floating-promises': 'error',
},
ignorePatterns: ['**/*.test.ts', 'out/', 'src.gen/', 'src/client/**/*.d.ts'],
overrides: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ export class ChatController implements ChatHandlers {
}

metric.setDimension('codewhispererCustomizationArn', requestInput.conversationState?.customizationArn)
this.#telemetryController.emitAddMessageMetric(params.tabId, metric.metric)
await this.#telemetryController.emitAddMessageMetric(params.tabId, metric.metric)

this.#telemetryController.updateTriggerInfo(params.tabId, {
lastMessageTrigger: {
Expand Down Expand Up @@ -373,7 +373,7 @@ export class ChatController implements ChatHandlers {
// this is the only way we can detect a follow up action
// we can reuse previous trigger information
if (lastMessageTrigger?.followUpActions?.has(params.prompt?.prompt ?? '')) {
this.#telemetryController.emitInteractWithMessageMetric(params.tabId, {
await this.#telemetryController.emitInteractWithMessageMetric(params.tabId, {
cwsprChatMessageId: lastMessageTrigger.messageId!,
cwsprChatInteractionType: ChatInteractionType.ClickFollowUp,
})
Expand Down Expand Up @@ -413,7 +413,7 @@ export class ChatController implements ChatHandlers {
}

if (!isNullish(partialResultToken)) {
this.#features.lsp.sendProgress(chatRequestType, partialResultToken, result.data.chatResult)
await this.#features.lsp.sendProgress(chatRequestType, partialResultToken, result.data.chatResult)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export class ChatTelemetryController {
}

public emitModifyCodeMetric(entry: AcceptedSuggestionChatEntry, percentage: number) {
this.#telemetryService.emitChatUserModificationEvent({
return this.#telemetryService.emitChatUserModificationEvent({
conversationId: entry.conversationId,
messageId: entry.messageId,
modificationPercentage: percentage,
Expand Down Expand Up @@ -165,7 +165,14 @@ export class ChatTelemetryController {

public emitAddMessageMetric(tabId: string, metric: Partial<CombinedConversationEvent>) {
const conversationId = this.getConversationId(tabId)
this.#telemetryService.emitChatAddMessage(
// Store the customization value associated with the message
if (metric.cwsprChatMessageId && metric.codewhispererCustomizationArn) {
this.#customizationInfoByTabAndMessageId[tabId] = {
...this.#customizationInfoByTabAndMessageId[tabId],
[metric.cwsprChatMessageId]: metric.codewhispererCustomizationArn,
}
}
return this.#telemetryService.emitChatAddMessage(
{
conversationId: conversationId,
messageId: metric.cwsprChatMessageId,
Expand All @@ -191,13 +198,6 @@ export class ChatTelemetryController {
chatActiveEditorImportCount: metric.cwsprChatActiveEditorImportCount,
}
)
// Store the customization value associated with the message
if (metric.cwsprChatMessageId && metric.codewhispererCustomizationArn) {
this.#customizationInfoByTabAndMessageId[tabId] = {
...this.#customizationInfoByTabAndMessageId[tabId],
[metric.cwsprChatMessageId]: metric.codewhispererCustomizationArn,
}
}
}

public emitStartConversationMetric(tabId: string, metric: Partial<CombinedConversationEvent>) {
Expand All @@ -220,7 +220,7 @@ export class ChatTelemetryController {
tabId: string,
metric: Omit<InteractWithMessageEvent, 'cwsprChatConversationId'>
) {
this.#telemetryService.emitChatInteractWithMessage(metric, {
return this.#telemetryService.emitChatInteractWithMessage(metric, {
conversationId: this.getConversationId(tabId),
})
}
Expand Down Expand Up @@ -291,7 +291,7 @@ export class ChatTelemetryController {
}
}

#handleClientTelemetry(params: unknown) {
async #handleClientTelemetry(params: unknown) {
if (isClientTelemetryEvent(params)) {
switch (params.name) {
case ChatUIEventName.AddMessage:
Expand Down Expand Up @@ -327,7 +327,7 @@ export class ChatTelemetryController {
: ChatInteractionType.Downvote,
codewhispererCustomizationArn: this.getCustomizationId(params.tabId, params.messageId),
}
this.#telemetryService.emitChatInteractWithMessage(voteData, {
await this.#telemetryService.emitChatInteractWithMessage(voteData, {
conversationId: this.getConversationId(params.tabId),
})
break
Expand All @@ -349,7 +349,7 @@ export class ChatTelemetryController {
cwsprChatTotalCodeBlocks: params.totalCodeBlocks,
codewhispererCustomizationArn: this.getCustomizationId(params.tabId, params.messageId),
}
this.#telemetryService.emitChatInteractWithMessage(interactData, {
await this.#telemetryService.emitChatInteractWithMessage(interactData, {
conversationId: this.getConversationId(params.tabId),
acceptedLineCount:
params.name === ChatUIEventName.InsertToCursorPosition
Expand All @@ -365,7 +365,7 @@ export class ChatTelemetryController {
cwsprChatInteractionTarget: params.link,
codewhispererCustomizationArn: this.getCustomizationId(params.tabId, params.messageId),
}
this.emitInteractWithMessageMetric(params.tabId, clickBodyLinkData)
await this.emitInteractWithMessageMetric(params.tabId, clickBodyLinkData)
break
case ChatUIEventName.SourceLinkClick:
const clickLinkData: Omit<InteractWithMessageEvent, 'cwsprChatConversationId'> = {
Expand All @@ -374,13 +374,14 @@ export class ChatTelemetryController {
cwsprChatInteractionTarget: params.link,
codewhispererCustomizationArn: this.getCustomizationId(params.tabId, params.messageId),
}
this.emitInteractWithMessageMetric(params.tabId, clickLinkData)
await this.emitInteractWithMessageMetric(params.tabId, clickLinkData)
break
}
}
}

public dispose() {
// eslint-disable-next-line @typescript-eslint/no-floating-promises
this.#codeDiffTracker.shutdown()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ const emitPerceivedLatencyTelemetry = (telemetry: Telemetry, session: CodeWhispe
})
}

const emitUserTriggerDecisionTelemetry = (
const emitUserTriggerDecisionTelemetry = async (
telemetry: Telemetry,
telemetryService: TelemetryService,
session: CodeWhispererSession,
Expand All @@ -173,7 +173,7 @@ const emitUserTriggerDecisionTelemetry = (
return
}

emitAggregatedUserTriggerDecisionTelemetry(telemetryService, session, timeSinceLastUserModification)
await emitAggregatedUserTriggerDecisionTelemetry(telemetryService, session, timeSinceLastUserModification)
emitUserDecisionTelemetry(telemetry, session)

session.reportedUserDecision = true
Expand All @@ -184,7 +184,7 @@ const emitAggregatedUserTriggerDecisionTelemetry = (
session: CodeWhispererSession,
timeSinceLastUserModification?: number
) => {
telemetryService.emitUserTriggerDecision(session, timeSinceLastUserModification)
return telemetryService.emitUserTriggerDecision(session, timeSinceLastUserModification)
}

const emitUserDecisionTelemetry = (telemetry: Telemetry, session: CodeWhispererSession) => {
Expand Down Expand Up @@ -310,8 +310,8 @@ export const CodewhispererServerFactory =
const codeDiffTracker: CodeDiffTracker<AcceptedInlineSuggestionEntry> = new CodeDiffTracker(
workspace,
logging,
(entry: AcceptedInlineSuggestionEntry, percentage, unmodifiedAcceptedCharacterCount) => {
telemetryService.emitUserModificationEvent({
async (entry: AcceptedInlineSuggestionEntry, percentage, unmodifiedAcceptedCharacterCount) => {
await telemetryService.emitUserModificationEvent({
sessionId: entry.sessionId,
requestId: entry.requestId,
languageId: entry.languageId,
Expand Down Expand Up @@ -404,7 +404,7 @@ export const CodewhispererServerFactory =
if (currentSession && currentSession.state === 'ACTIVE') {
// Emit user trigger decision at session close time for active session
sessionManager.discardSession(currentSession)
emitUserTriggerDecisionTelemetry(
await emitUserTriggerDecisionTelemetry(
telemetry,
telemetryService,
currentSession,
Expand Down Expand Up @@ -439,7 +439,7 @@ export const CodewhispererServerFactory =
.replaceAll('\r\n', '\n'),
},
})
.then(suggestionResponse => {
.then(async suggestionResponse => {
codePercentageTracker.countInvocation(inferredLanguageId)

// Populate the session with information from codewhisperer response
Expand All @@ -458,7 +458,7 @@ export const CodewhispererServerFactory =
if (newSession.state === 'CLOSED' || newSession.state === 'DISCARD') {
// Force Discard user decision on every received suggestion
newSession.suggestions.forEach(s => newSession.setSuggestionState(s.itemId, 'Discard'))
emitUserTriggerDecisionTelemetry(
await emitUserTriggerDecisionTelemetry(
telemetry,
telemetryService,
newSession,
Expand Down Expand Up @@ -518,7 +518,7 @@ export const CodewhispererServerFactory =
// If after all server-side filtering no suggestions can be displayed, close session and return empty results
if (suggestionsWithRightContext.length === 0) {
sessionManager.closeSession(newSession)
emitUserTriggerDecisionTelemetry(
await emitUserTriggerDecisionTelemetry(
telemetry,
telemetryService,
newSession,
Expand Down Expand Up @@ -606,7 +606,7 @@ export const CodewhispererServerFactory =

// Always emit user trigger decision at session close
sessionManager.closeSession(session)
emitUserTriggerDecisionTelemetry(telemetry, telemetryService, session, timeSinceLastUserModification)
await emitUserTriggerDecisionTelemetry(telemetry, telemetryService, session, timeSinceLastUserModification)
}

const updateConfiguration = async () => {
Expand All @@ -619,9 +619,9 @@ export const CodewhispererServerFactory =
`Inline completion configuration updated to use ${codeWhispererService.customizationArn}`
)
/*
The flag enableTelemetryEventsToDestination is set to true temporarily. It's value will be determined through destination
configuration post all events migration to STE. It'll be replaced by qConfig['enableTelemetryEventsToDestination'] === true
*/
The flag enableTelemetryEventsToDestination is set to true temporarily. It's value will be determined through destination
configuration post all events migration to STE. It'll be replaced by qConfig['enableTelemetryEventsToDestination'] === true
*/
// const enableTelemetryEventsToDestination = true
// telemetryService.updateEnableTelemetryEventsToDestination(enableTelemetryEventsToDestination)
const optOutTelemetryPreference = qConfig['optOutTelemetry'] === true ? 'OPTOUT' : 'OPTIN'
Expand Down Expand Up @@ -672,9 +672,9 @@ export const CodewhispererServerFactory =

logging.log('Amazon Q Inline Suggestion server has been initialised')

return () => {
return async () => {
codePercentageTracker.dispose()
codeDiffTracker.shutdown()
await codeDiffTracker.shutdown()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ export class ArtifactManager {
.pipe(stream)

stream.on('close', () => resolve())
archive.finalize()
return archive.finalize()
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class SecurityScanDiagnosticsProvider {
await Promise.all(
this.findings.map(finding => {
this.logging.log(`reset diagnostics for: ${finding.filePath}`)
this.publishDiagnostics(finding.filePath, [])
return this.publishDiagnostics(finding.filePath, [])
})
)
this.diagnostics = new Map()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,25 @@ export class CodePercentageTracker {
}

private startListening() {
return setInterval(() => {
this.getEventDataAndRotate().forEach(event => {
this.telemetryService.emitCodeCoverageEvent(
{
languageId: event.codewhispererLanguage as CodewhispererLanguage,
customizationArn: this.customizationArn,
totalCharacterCount: event.codewhispererTotalTokens,
acceptedCharacterCount: event.codewhispererSuggestedTokens,
},
{
percentage: event.codewhispererPercentage,
successCount: event.successCount,
}
return setInterval(async () => {
const events = this.getEventDataAndRotate()
await Promise.all(
events.map(
async event =>
await this.telemetryService.emitCodeCoverageEvent(
{
languageId: event.codewhispererLanguage as CodewhispererLanguage,
customizationArn: this.customizationArn,
totalCharacterCount: event.codewhispererTotalTokens,
acceptedCharacterCount: event.codewhispererSuggestedTokens,
},
{
percentage: event.codewhispererPercentage,
successCount: event.successCount,
}
)
)
})
)
}, CODE_PERCENTAGE_INTERVAL)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ export class TelemetryService extends CodeWhispererServiceToken {
perceivedLatencyMilliseconds: perceivedLatencyMilliseconds,
acceptedCharacterCount: acceptedCharacterCount,
}
this.invokeSendTelemetryEvent({
return this.invokeSendTelemetryEvent({
userTriggerDecisionEvent: event,
})
}
Expand Down Expand Up @@ -258,7 +258,7 @@ export class TelemetryService extends CodeWhispererServiceToken {
if (metric.codewhispererCustomizationArn) {
event.customizationArn = metric.codewhispererCustomizationArn
}
this.invokeSendTelemetryEvent({
return this.invokeSendTelemetryEvent({
chatInteractWithMessageEvent: event,
})
}
Expand All @@ -281,7 +281,7 @@ export class TelemetryService extends CodeWhispererServiceToken {
},
})
}
this.invokeSendTelemetryEvent({
return this.invokeSendTelemetryEvent({
chatUserModificationEvent: params,
})
}
Expand All @@ -296,7 +296,7 @@ export class TelemetryService extends CodeWhispererServiceToken {
acceptedCharacterCount: number
unmodifiedAcceptedCharacterCount: number
}) {
this.invokeSendTelemetryEvent({
return this.invokeSendTelemetryEvent({
userModificationEvent: {
sessionId: params.sessionId,
requestId: params.requestId,
Expand Down Expand Up @@ -347,7 +347,7 @@ export class TelemetryService extends CodeWhispererServiceToken {
}
if (params.customizationArn) event.customizationArn = params.customizationArn

this.invokeSendTelemetryEvent({
return this.invokeSendTelemetryEvent({
codeCoverageEvent: event,
})
}
Expand Down Expand Up @@ -434,7 +434,7 @@ export class TelemetryService extends CodeWhispererServiceToken {
languageName: getRuntimeLanguage(params.programmingLanguage),
}
}
this.invokeSendTelemetryEvent({
return this.invokeSendTelemetryEvent({
chatAddMessageEvent: event,
})
}
Expand Down

0 comments on commit 1c38b0c

Please sign in to comment.