Merge pull request #3236 from continuedev/nate/bugfix

fix ImportDefinitionsService bug
This commit is contained in:
Nate Sesti 2024-12-06 19:08:10 -08:00 • committed by GitHub
commit 893092a626
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 17 additions and 4 deletions

View file

@ -29,14 +29,23 @@ export class ImportDefinitionsService {
return this.cache.get(filepath);
}
private async _getFileInfo(filepath: string): Promise<FileInfo> {
private async _getFileInfo(filepath: string): Promise<FileInfo | null> {
const parser = await getParserForFile(filepath);
if (!parser) {
return {
imports: {},
};
}
const ast = parser.parse(await this.ide.readFile(filepath), undefined, {
let fileContents: string | undefined = undefined;
try {
fileContents = await this.ide.readFile(filepath);
} catch (err) {
// File removed
return null;
}
const ast = parser.parse(fileContents, undefined, {
includedRanges: [
{
startIndex: 0,

View file

@ -1,7 +1,7 @@
export class PrecalculatedLruCache<V> {
private items: [string, V][] = [];
constructor(
private readonly calculateValue: (key: string) => Promise<V>,
private readonly calculateValue: (key: string) => Promise<V | null>,
private readonly N: number,
) {}
@ -11,7 +11,11 @@ export class PrecalculatedLruCache<V> {
if (index < 0) {
// Calculate info for new file
const value: V = await this.calculateValue(key);
const value: V | null = await this.calculateValue(key);
if (value === null) {
return;
}
this.items.push([key, value]);
if (this.items.length > this.N) {