Skip to content

Commit fac718b

Browse files
Merge staging into feature/redshift
2 parents c7fc629 + 30169a2 commit fac718b

File tree

3 files changed

+40
-6
lines changed

3 files changed

+40
-6
lines changed

src/codewhisperer/service/recommendationHandler.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import { AuthUtil } from '../util/authUtil'
3838
import { CodeWhispererUserGroupSettings } from '../util/userGroupUtil'
3939
import { CWInlineCompletionItemProvider } from './inlineCompletionItemProvider'
4040
import { application } from '../util/codeWhispererApplication'
41+
import { indent } from '../../shared/utilities/textUtilities'
4142

4243
/**
4344
* This class is for getRecommendation/listRecommendation API calls and its states
@@ -270,8 +271,9 @@ export class RecommendationHandler {
270271
}
271272
} finally {
272273
const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone
273-
getLogger().debug(
274-
`Request ID: ${requestId},
274+
275+
let msg = indent(
276+
`codewhisperer: request-id: ${requestId},
275277
timestamp(epoch): ${Date.now()},
276278
timezone: ${timezone},
277279
datetime: ${new Date().toLocaleString([], { timeZone: timezone })},
@@ -281,12 +283,16 @@ export class RecommendationHandler {
281283
left context of line: '${session.leftContextOfCurrentLine}',
282284
line number: ${session.startPos.line},
283285
character location: ${session.startPos.character},
284-
latency: ${latency} ms.`
285-
)
286-
getLogger().verbose('Recommendations:')
286+
latency: ${latency} ms.
287+
Recommendations:`,
288+
4,
289+
true
290+
).trimStart()
287291
recommendations.forEach((item, index) => {
288-
getLogger().verbose(`[${index}]\n${item.content.trimRight()}`)
292+
msg += `\n ${index.toString().padStart(2, '0')}: ${indent(item.content, 8, true).trim()}`
289293
})
294+
getLogger().debug(msg)
295+
290296
if (invocationResult === 'Succeeded') {
291297
CodeWhispererCodeCoverageTracker.getTracker(session.language)?.incrementServiceInvocationCount()
292298
}

src/shared/utilities/textUtilities.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,25 @@ export function truncate(s: string, n: number, suffix?: string): string {
3030
return n < 0 ? suffix + truncated : truncated + suffix
3131
}
3232

33+
/**
34+
* Indents a string.
35+
*
36+
* @param size Indent width (number of space chars).
37+
* @param clear Clear existing whitespace, if any.
38+
* @param s Text to indent.
39+
*/
40+
export function indent(s: string, size: number = 4, clear: boolean = false): string {
41+
const n = Math.abs(size)
42+
const spaces = ''.padEnd(n, ' ')
43+
if (size < 0) {
44+
throw Error() // TODO: implement "dedent" for negative size.
45+
}
46+
if (clear) {
47+
return s.replace(/^[ \t]*([^\n])/, `${spaces}$1`).replace(/(\n+)[ \t]*([^ \t\n])/g, `$1${spaces}$2`)
48+
}
49+
return spaces + s.replace(/(\n+)(.)/g, `$1${spaces}$2`)
50+
}
51+
3352
/**
3453
* Creates a (shallow) clone of `obj` and truncates its top-level string properties.
3554
*

src/test/shared/utilities/textUtilities.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
removeAnsi,
1111
truncate,
1212
truncateProps,
13+
indent,
1314
} from '../../../shared/utilities/textUtilities'
1415

1516
describe('textUtilities', async function () {
@@ -59,6 +60,14 @@ describe('textUtilities', async function () {
5960
assert.deepStrictEqual(truncate('abc 123', 99), 'abc 123')
6061
assert.deepStrictEqual(truncate('abc 123', -99), 'abc 123')
6162
})
63+
64+
it('indent()', async function () {
65+
assert.deepStrictEqual(indent('abc\n123', 2, false), ' abc\n 123')
66+
assert.deepStrictEqual(indent('abc\n 123\n', 2, false), ' abc\n 123\n')
67+
assert.deepStrictEqual(indent('abc\n 123\n', 2, true), ' abc\n 123\n')
68+
assert.deepStrictEqual(indent(' abc\n\n \n123\nfoo\n', 4, false), ' abc\n\n \n 123\n foo\n')
69+
assert.deepStrictEqual(indent(' abc\n\n \n123\nfoo\n', 4, true), ' abc\n\n \n 123\n foo\n')
70+
})
6271
})
6372

6473
describe('removeAnsi', async function () {

0 commit comments

Comments
 (0)