Skip to content

Commit 18d86d4

Browse files
authored
fix: address bugs impacting indexing disabled functionality (#1293)
1 parent 170113f commit 18d86d4

File tree

4 files changed

+45
-10
lines changed

4 files changed

+45
-10
lines changed

server/aws-lsp-codewhisperer/src/language-server/agenticChat/agenticChatController.test.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1120,11 +1120,7 @@ describe('AgenticChatController', () => {
11201120
]
11211121

11221122
sinon.stub(LocalProjectContextController, 'getInstance').resolves(localProjectContextController)
1123-
1124-
Object.defineProperty(localProjectContextController, 'isEnabled', {
1125-
get: () => true,
1126-
})
1127-
1123+
sinon.stub(localProjectContextController, 'isIndexingEnabled').returns(true)
11281124
sinon.stub(localProjectContextController, 'queryVectorIndex').resolves(mockRelevantDocs)
11291125

11301126
await chatController.onChatPrompt(

server/aws-lsp-codewhisperer/src/language-server/agenticChat/context/agenticChatTriggerContext.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ export class AgenticChatTriggerContext {
262262
chatResultStream?: AgenticChatResultStream
263263
): Promise<RelevantTextDocumentAddition[]> {
264264
const localProjectContextController = await LocalProjectContextController.getInstance()
265-
if (!localProjectContextController.isIndexingEnabled && chatResultStream) {
265+
if (!localProjectContextController.isIndexingEnabled() && chatResultStream) {
266266
await chatResultStream.writeResultBlock({
267267
body: `To add your workspace as context, enable local indexing in your IDE settings. After enabling, add @workspace to your question, and I'll generate a response using your workspace as context.`,
268268
buttons: [

server/aws-lsp-codewhisperer/src/shared/localProjectContextController.test.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { Dirent } from 'fs'
66
import * as path from 'path'
77
import { URI } from 'vscode-uri'
88
import { TestFeatures } from '@aws/language-server-runtimes/testing'
9+
import sinon from 'ts-sinon'
910

1011
class LoggingMock {
1112
public error: SinonStub
@@ -118,6 +119,19 @@ describe('LocalProjectContextController', () => {
118119
})
119120

120121
it('should return empty array when vector library is not initialized', async () => {
122+
sinon.stub(controller, 'isIndexingEnabled').returns(true)
123+
const uninitializedController = new LocalProjectContextController(
124+
'testClient',
125+
mockWorkspaceFolders,
126+
logging as any
127+
)
128+
129+
const result = await uninitializedController.queryVectorIndex({ query: 'test' })
130+
assert.deepStrictEqual(result, [])
131+
})
132+
133+
it('should return empty array when indexing is disabled', async () => {
134+
sinon.stub(controller, 'isIndexingEnabled').returns(false)
121135
const uninitializedController = new LocalProjectContextController(
122136
'testClient',
123137
mockWorkspaceFolders,
@@ -129,11 +143,13 @@ describe('LocalProjectContextController', () => {
129143
})
130144

131145
it('should return chunks from vector library', async () => {
146+
sinon.stub(controller, 'isIndexingEnabled').returns(true)
132147
const result = await controller.queryVectorIndex({ query: 'test' })
133148
assert.deepStrictEqual(result, ['mockChunk1', 'mockChunk2'])
134149
})
135150

136151
it('should handle query errors', async () => {
152+
sinon.stub(controller, 'isIndexingEnabled').returns(true)
137153
const vecLib = await vectorLibMock.start()
138154
vecLib.queryVectorIndex.rejects(new Error('Query failed'))
139155

@@ -149,6 +165,23 @@ describe('LocalProjectContextController', () => {
149165
})
150166

151167
it('should return empty array when vector library is not initialized', async () => {
168+
sinon.stub(controller, 'isIndexingEnabled').returns(true)
169+
const uninitializedController = new LocalProjectContextController(
170+
'testClient',
171+
mockWorkspaceFolders,
172+
logging as any
173+
)
174+
175+
const result = await uninitializedController.queryInlineProjectContext({
176+
query: 'test',
177+
filePath: 'test.java',
178+
target: 'test',
179+
})
180+
assert.deepStrictEqual(result, [])
181+
})
182+
183+
it('should return empty array when indexing is disabled', async () => {
184+
sinon.stub(controller, 'isIndexingEnabled').returns(false)
152185
const uninitializedController = new LocalProjectContextController(
153186
'testClient',
154187
mockWorkspaceFolders,
@@ -164,6 +197,7 @@ describe('LocalProjectContextController', () => {
164197
})
165198

166199
it('should return context from vector library', async () => {
200+
sinon.stub(controller, 'isIndexingEnabled').returns(true)
167201
const result = await controller.queryInlineProjectContext({
168202
query: 'test',
169203
filePath: 'test.java',
@@ -173,6 +207,7 @@ describe('LocalProjectContextController', () => {
173207
})
174208

175209
it('should handle query errors', async () => {
210+
sinon.stub(controller, 'isIndexingEnabled').returns(true)
176211
const vecLib = await vectorLibMock.start()
177212
vecLib.queryInlineProjectContext.rejects(new Error('Query failed'))
178213

@@ -188,6 +223,7 @@ describe('LocalProjectContextController', () => {
188223

189224
describe('updateIndex', () => {
190225
beforeEach(async () => {
226+
sinon.stub(controller, 'isIndexingEnabled').returns(true)
191227
await controller.init({ vectorLib: vectorLibMock })
192228
})
193229

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,9 @@ export class LocalProjectContextController {
141141
if (enableIndexing && !this._isIndexingEnabled) {
142142
void this.buildIndex()
143143
}
144+
if (!enableIndexing && this._isIndexingEnabled) {
145+
void this._vecLib?.clear?.()
146+
}
144147
this._isIndexingEnabled = enableIndexing
145148
return
146149
}
@@ -184,7 +187,7 @@ export class LocalProjectContextController {
184187
}
185188

186189
public async updateIndex(filePaths: string[], operation: UpdateMode): Promise<void> {
187-
if (!this._vecLib) {
190+
if (!this.isIndexingEnabled()) {
188191
return
189192
}
190193

@@ -245,7 +248,7 @@ export class LocalProjectContextController {
245248
public async queryInlineProjectContext(
246249
request: QueryInlineProjectContextRequestV2
247250
): Promise<InlineProjectContext[]> {
248-
if (!this._vecLib) {
251+
if (!this.isIndexingEnabled()) {
249252
return []
250253
}
251254

@@ -259,7 +262,7 @@ export class LocalProjectContextController {
259262
}
260263

261264
public async queryVectorIndex(request: QueryRequest): Promise<Chunk[]> {
262-
if (!this._vecLib) {
265+
if (!this.isIndexingEnabled()) {
263266
return []
264267
}
265268

@@ -351,7 +354,7 @@ export class LocalProjectContextController {
351354
}
352355

353356
public isIndexingEnabled(): boolean {
354-
return this._isIndexingEnabled
357+
return this._vecLib !== undefined && this._isIndexingEnabled
355358
}
356359

357360
private fileMeetsFileSizeConstraints(filePath: string, sizeConstraints: SizeConstraints): boolean {

0 commit comments

Comments
 (0)