Skip to content

Commit 05aec74

Browse files
Will-ShaoHualaileni-aws
authored andcommitted
chore: supplemental context log (#2185)
1 parent 722fa78 commit 05aec74

File tree

3 files changed

+24
-7
lines changed

3 files changed

+24
-7
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,8 @@ export class CodeWhispererServiceToken extends CodeWhispererServiceBase {
444444
"endpoint": ${this.codeWhispererEndpoint},
445445
"predictionType": ${request.predictionTypes?.toString() ?? 'Not specified (COMPLETIONS)'},
446446
"filename": ${request.fileContext.filename},
447+
"leftContextLength": ${request.fileContext.leftFileContent.length},
448+
rightContextLength: ${request.fileContext.rightFileContent.length},
447449
"language": ${request.fileContext.programmingLanguage.languageName},
448450
"supplementalContextCount": ${request.supplementalContexts?.length ?? 0},
449451
"request.nextToken": ${request.nextToken},

server/aws-lsp-codewhisperer/src/shared/supplementalContextUtil/crossFileContextUtil.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,13 @@ export async function fetchSupplementalContextForSrc(
7171
const supplementalContextConfig = getSupplementalContextConfig(document.languageId)
7272

7373
if (supplementalContextConfig === undefined) {
74-
return supplementalContextConfig
74+
return undefined
7575
}
76-
//TODO: add logic for other strategies once available
76+
7777
if (supplementalContextConfig === 'codemap') {
7878
return await codemapContext(document, position, workspace, cancellationToken, openTabFiles)
7979
}
80+
8081
return { supplementalContextItems: [], strategy: 'Empty' }
8182
}
8283

@@ -264,10 +265,7 @@ function getInputChunk(document: TextDocument, cursorPosition: Position, chunkSi
264265
* @returns specifically returning undefined if the langueage is not supported,
265266
* otherwise true/false depending on if the language is fully supported or not belonging to the user group
266267
*/
267-
function getSupplementalContextConfig(
268-
languageId: TextDocument['languageId'],
269-
_userGroup?: any
270-
): SupplementalContextStrategy | undefined {
268+
function getSupplementalContextConfig(languageId: TextDocument['languageId']): SupplementalContextStrategy | undefined {
271269
return isCrossFileSupported(languageId) ? 'codemap' : undefined
272270
}
273271

server/aws-lsp-codewhisperer/src/shared/supplementalContextUtil/supplementalContextUtil.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,24 @@ export async function fetchSupplementalContext(
9191
strategy: supplementalContextValue.strategy,
9292
}
9393

94-
return truncateSupplementalContext(resBeforeTruncation)
94+
const r = truncateSupplementalContext(resBeforeTruncation)
95+
96+
let logstr = `@@supplemental context@@
97+
\tisUtg: ${r.isUtg},
98+
\tisProcessTimeout: ${r.isProcessTimeout},
99+
\tcontents.length: ${r.contentsLength},
100+
\tlatency: ${r.latency},
101+
\tstrategy: ${r.strategy},
102+
`
103+
r.supplementalContextItems.forEach((item, index) => {
104+
logstr += `\tChunk [${index}th]:\n`
105+
logstr += `\t\tPath: ${item.filePath}\n`
106+
logstr += `\t\tLength: ${item.content.length}\n`
107+
logstr += `\t\tScore: ${item.score}\n`
108+
})
109+
logging.info(logstr)
110+
111+
return r
95112
} else {
96113
return undefined
97114
}

0 commit comments

Comments
 (0)