Skip to content

Commit d378a86

Browse files
committed
fix lsp response possibly return a chunk with empty string and pretty logging strings
1 parent cee0fa3 commit d378a86

File tree

3 files changed

+24
-13
lines changed

3 files changed

+24
-13
lines changed

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

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { selectFrom } from '../../shared/utilities/tsUtils'
1717
import { checkLeftContextKeywordsForJson } from './commonUtil'
1818
import { CodeWhispererSupplementalContext } from '../models/model'
1919
import { getOptOutPreference } from '../../shared/telemetry/util'
20+
import { indent } from '../../shared'
2021

2122
let tabSize: number = getTabSizeSetting()
2223

@@ -202,18 +203,26 @@ function logSupplementalContext(supplementalContext: CodeWhispererSupplementalCo
202203
return
203204
}
204205

205-
let logString = `CodeWhispererSupplementalContext:
206-
isUtg: ${supplementalContext.isUtg},
207-
isProcessTimeout: ${supplementalContext.isProcessTimeout},
208-
contentsLength: ${supplementalContext.contentsLength},
209-
latency: ${supplementalContext.latency},
210-
`
206+
let logString = indent(
207+
`CodeWhispererSupplementalContext:
208+
isUtg: ${supplementalContext.isUtg},
209+
isProcessTimeout: ${supplementalContext.isProcessTimeout},
210+
contentsLength: ${supplementalContext.contentsLength},
211+
latency: ${supplementalContext.latency}`,
212+
4,
213+
true
214+
).trimStart()
215+
211216
supplementalContext.supplementalContextItems.forEach((context, index) => {
212-
logString += `Chunk ${index}:
213-
Path: ${context.filePath}
214-
Content: ${index}:${context.content}
215-
Score: ${context.score}
216-
-----------------------------------------------`
217+
logString += indent(
218+
`\nChunk ${index}:
219+
Path: ${context.filePath}
220+
Length: ${context.content}
221+
Score: ${context.score}
222+
-----------------------------------------------`,
223+
8,
224+
true
225+
)
217226
})
218227

219228
getLogger().debug(logString)

packages/core/src/codewhisperer/util/supplementalContext/crossFileContextUtil.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ export async function fetchSupplementalContextForSrcV1(
152152
// DO NOT send code chunk with empty content
153153
getLogger().debug(`CodeWhisperer finished fetching crossfile context out of ${relevantCrossFilePaths.length} files`)
154154
return {
155-
supplementalContextItems: supplementalContexts.filter((item) => item.content.trim().length !== 0),
155+
supplementalContextItems: supplementalContexts,
156156
strategy: 'OpenTabs_BM25',
157157
}
158158
}

packages/core/src/codewhisperer/util/supplementalContext/supplementalContextUtil.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ export async function fetchSupplementalContext(
3939
return {
4040
isUtg: isUtg,
4141
isProcessTimeout: false,
42-
supplementalContextItems: value.supplementalContextItems,
42+
supplementalContextItems: value.supplementalContextItems.filter(
43+
(item) => item.content.trim().length !== 0
44+
),
4345
contentsLength: value.supplementalContextItems.reduce((acc, curr) => acc + curr.content.length, 0),
4446
latency: performance.now() - timesBeforeFetching,
4547
strategy: value.strategy,

0 commit comments

Comments
 (0)