Skip to content

Commit 08426ad

Browse files
committed
feat(amazonq): support import adder setting
1 parent ee842c8 commit 08426ad

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

server/aws-lsp-codewhisperer/src/language-server/amazonQServiceManager/AmazonQTokenServiceManager.ts

+10
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,11 @@ export class AmazonQTokenServiceManager implements BaseAmazonQServiceManager {
302302
includeSuggestionsWithCodeReferences
303303
)
304304

305+
const includeImportsWithCodeReferences =
306+
vscConfig['importRecommendationForInlineCodeSuggestions'] === true
307+
this.log(`Read сonfiguration includeImportsWithCodeReferences=${includeImportsWithCodeReferences}`)
308+
this.configurationCache.set('includeImportsWithCodeReferences', includeImportsWithCodeReferences)
309+
305310
const customizationArn = textUtils.undefinedIfEmpty(params?.settings['customization'])
306311
if (customizationArn) {
307312
this.log(`Read configuration customizationArn=${customizationArn}`)
@@ -603,6 +608,11 @@ export class AmazonQTokenServiceManager implements BaseAmazonQServiceManager {
603608
service.shareCodeWhispererContentWithAWS =
604609
this.configurationCache.get('shareCodeWhispererContentWithAWS') === true
605610

611+
service.includeSuggestionsWithCodeReferences =
612+
this.configurationCache.get('includeSuggestionsWithCodeReferences') === true
613+
service.includeImportsWithCodeReferences =
614+
this.configurationCache.get('includeImportsWithCodeReferences') === true
615+
606616
this.log('Configured CodeWhispererServiceToken instance settings:')
607617
this.log(
608618
`customUserAgent=${customUserAgent}, customizationArn=${service.customizationArn}, shareCodeWhispererContentWithAWS=${service.shareCodeWhispererContentWithAWS}`

server/aws-lsp-codewhisperer/src/language-server/codeWhispererServer.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ const emitAggregatedUserTriggerDecisionTelemetry = (
198198
const mergeSuggestionsWithRightContext = (
199199
rightFileContext: string,
200200
suggestions: Suggestion[],
201+
includeImportsWithCodeReferences: boolean,
201202
range?: Range
202203
): InlineCompletionItemWithReferences[] => {
203204
return suggestions.map(suggestion => {
@@ -228,7 +229,9 @@ const mergeSuggestionsWithRightContext = (
228229
insertText: insertText,
229230
range,
230231
references: references?.length ? references : undefined,
231-
mostRelevantMissingImports: suggestion.mostRelevantMissingImports,
232+
mostRelevantMissingImports: includeImportsWithCodeReferences
233+
? suggestion.mostRelevantMissingImports
234+
: undefined,
232235
}
233236
})
234237
}
@@ -288,6 +291,7 @@ export const CodewhispererServerFactory =
288291
// right before returning and is only guaranteed to be consistent within
289292
// the context of a single response.
290293
let includeSuggestionsWithCodeReferences = false
294+
let includeImportsWithCodeReferences = false
291295

292296
// CodePercentage and codeDiff tracker have a dependency on TelemetryService, so initialization is also delayed to `onInitialized` handler
293297
let codePercentageTracker: CodePercentageTracker
@@ -305,6 +309,8 @@ export const CodewhispererServerFactory =
305309
sessionManager.discardSession(currentSession)
306310
}
307311
const codeWhispererService = amazonQServiceManager.getCodewhispererService()
312+
includeSuggestionsWithCodeReferences = codeWhispererService.includeSuggestionsWithCodeReferences
313+
includeImportsWithCodeReferences = codeWhispererService.includeImportsWithCodeReferences
308314

309315
// prettier-ignore
310316
return workspace.getTextDocument(params.textDocument.uri).then(async textDocument => {
@@ -533,6 +539,7 @@ export const CodewhispererServerFactory =
533539
const suggestionsWithRightContext = mergeSuggestionsWithRightContext(
534540
session.requestContext.fileContext.rightFileContent,
535541
filteredSuggestions,
542+
includeImportsWithCodeReferences,
536543
selectionRange
537544
).filter(suggestion => {
538545
// Discard suggestions that have empty string insertText after right context merge and can't be displayed anymore

server/aws-lsp-codewhisperer/src/language-server/codeWhispererService.ts

+2
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ export abstract class CodeWhispererServiceBase {
5252
protected readonly codeWhispererRegion
5353
protected readonly codeWhispererEndpoint
5454
public shareCodeWhispererContentWithAWS = false
55+
public includeSuggestionsWithCodeReferences = false
56+
public includeImportsWithCodeReferences = false
5557
public customizationArn?: string
5658
public profileArn?: string
5759
abstract client: CodeWhispererSigv4Client | CodeWhispererTokenClient

0 commit comments

Comments
 (0)