fix ImportDefinitionsService bug
This commit is contained in:
parent
b488fe1bad
commit
85e8492fb3
2 changed files with 17 additions and 4 deletions
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue