Skip to content

Commit d83c70b

Browse files
RelatedInformationService shouldn't throw on timeout (microsoft#196643)
It should just return no results. Fixes microsoft/vscode-copilot#2237
1 parent 30c4bb1 commit d83c70b

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

src/vs/workbench/services/aiRelatedInformation/common/aiRelatedInformationService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ export class AiRelatedInformationService implements IAiRelatedInformationService
8383
AiRelatedInformationService.DEFAULT_TIMEOUT,
8484
() => {
8585
cancellablePromises.forEach(p => p.cancel());
86-
throw new Error('Related information provider timed out');
86+
this.logService.warn('[AiRelatedInformationService]: Related information provider timed out');
8787
}
8888
);
8989
if (!results) {

src/vs/workbench/services/aiRelatedInformation/test/common/aiRelatedInformationService.test.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import * as assert from 'assert';
7+
import * as sinon from 'sinon';
78
import { AiRelatedInformationService } from 'vs/workbench/services/aiRelatedInformation/common/aiRelatedInformationService';
89
import { NullLogService } from 'vs/platform/log/common/log';
910
import { CommandInformationResult, IAiRelatedInformationProvider, RelatedInformationType, SettingInformationResult } from 'vs/workbench/services/aiRelatedInformation/common/aiRelatedInformation';
@@ -66,4 +67,28 @@ suite('AiRelatedInformationService', () => {
6667
assert.strictEqual((result[0] as CommandInformationResult).command, command);
6768
assert.strictEqual((result[1] as SettingInformationResult).setting, setting);
6869
});
70+
71+
test('should return empty array on timeout', async () => {
72+
const clock = sinon.useFakeTimers({
73+
shouldAdvanceTime: true,
74+
});
75+
const provider: IAiRelatedInformationProvider = {
76+
provideAiRelatedInformation: () => new Promise((resolve) => {
77+
setTimeout(() => {
78+
resolve([{ type: RelatedInformationType.CommandInformation, command: 'command', weight: 1 }]);
79+
}, AiRelatedInformationService.DEFAULT_TIMEOUT + 100);
80+
})
81+
};
82+
83+
service.registerAiRelatedInformationProvider(RelatedInformationType.CommandInformation, provider);
84+
85+
try {
86+
const promise = service.getRelatedInformation('query', [RelatedInformationType.CommandInformation], CancellationToken.None);
87+
clock.tick(AiRelatedInformationService.DEFAULT_TIMEOUT + 200);
88+
const result = await promise;
89+
assert.strictEqual(result.length, 0);
90+
} finally {
91+
clock.restore();
92+
}
93+
});
6994
});

0 commit comments

Comments
 (0)