Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ensure removed extraLibs are not used in tsWorker #4544

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 47 additions & 2 deletions src/language/typescript/tsWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ export class TypeScriptWorker implements ts.LanguageServiceHost, ITypeScriptWork

private _ctx: worker.IWorkerContext;
private _extraLibs: IExtraLibs = Object.create(null);
/** Extra libs may have been opened as models, so we track previously removed libs to ensure they are not considered */
private _removedExtraLibs: { uri: string; version: number }[] = [];
private _languageService = ts.createLanguageService(this);
private _compilerOptions: ts.CompilerOptions;
private _inlayHintsOptions?: ts.UserPreferences;
Expand All @@ -63,8 +65,48 @@ export class TypeScriptWorker implements ts.LanguageServiceHost, ITypeScriptWork
}

getScriptFileNames(): string[] {
const allModels = this._ctx.getMirrorModels().map((model) => model.uri);
const models = allModels.filter((uri) => !fileNameIsLib(uri)).map((uri) => uri.toString());
const allModels = this._ctx.getMirrorModels();
const models = allModels
// remove default libs
.filter((model) => !fileNameIsLib(model.uri))
// remove extra libs
.filter((model) => {
const modelUri = model.uri.toString();
if (this._extraLibs[modelUri]) {
return false;
}
// Extra libs passed with no schema get a file:/// prefix from the model but not in the _extraLibs map
if (
modelUri.startsWith('file:///') &&
this._extraLibs[modelUri.replace('file:///', '')]?.version
) {
return false;
}
return true;
})
// remove previously removed libs
.filter((model) => {
const modelUri = model.uri.toString();
if (
this._removedExtraLibs.some(
(removed) => removed.uri === modelUri && removed.version === model.version
)
) {
return false;
}
// if the extra lib was passed with no schema, it gets a file:/// prefix from the model
if (
modelUri.startsWith('file:///') &&
this._removedExtraLibs.some(
(removed) =>
removed.uri === modelUri.replace('file:///', '') && removed.version === model.version
)
) {
return false;
}
return true;
})
.map((model) => model.uri.toString());
return models.concat(Object.keys(this._extraLibs));
}

Expand Down Expand Up @@ -450,6 +492,9 @@ export class TypeScriptWorker implements ts.LanguageServiceHost, ITypeScriptWork
}

async updateExtraLibs(extraLibs: IExtraLibs): Promise<void> {
this._removedExtraLibs.push(
...Object.entries(this._extraLibs).map(([uri, lib]) => ({ uri, version: lib.version }))
);
this._extraLibs = extraLibs;
}

Expand Down
Loading