mirror of
https://github.com/Microsoft/vscode
synced 2024-09-13 21:55:38 +00:00
use async module loading for typescript, #33141
This commit is contained in:
parent
0278217594
commit
63021129db
|
@ -25,20 +25,20 @@ const _linkProvider = new class implements vscode.DocumentLinkProvider {
|
|||
private _cachedResult: { key: string; links: vscode.DocumentLink[] };
|
||||
private _linkPattern = /[^!]\[.*?\]\(#(.*?)\)/g;
|
||||
|
||||
provideDocumentLinks(document: vscode.TextDocument, token: vscode.CancellationToken): vscode.DocumentLink[] {
|
||||
async provideDocumentLinks(document: vscode.TextDocument, token: vscode.CancellationToken): Promise<vscode.DocumentLink[]> {
|
||||
const key = `${document.uri.toString()}@${document.version}`;
|
||||
if (!this._cachedResult || this._cachedResult.key !== key) {
|
||||
const links = this._computeDocumentLinks(document);
|
||||
const links = await this._computeDocumentLinks(document);
|
||||
this._cachedResult = { key, links };
|
||||
}
|
||||
return this._cachedResult.links;
|
||||
}
|
||||
|
||||
private _computeDocumentLinks(document: vscode.TextDocument): vscode.DocumentLink[] {
|
||||
private async _computeDocumentLinks(document: vscode.TextDocument): Promise<vscode.DocumentLink[]> {
|
||||
|
||||
const results: vscode.DocumentLink[] = [];
|
||||
const text = document.getText();
|
||||
const lookUp = ast.createNamedNodeLookUp(text);
|
||||
const lookUp = await ast.createNamedNodeLookUp(text);
|
||||
|
||||
this._linkPattern.lastIndex = 0;
|
||||
let match: RegExpMatchArray;
|
||||
|
@ -69,7 +69,9 @@ namespace ast {
|
|||
(dottedName: string): number;
|
||||
}
|
||||
|
||||
export function createNamedNodeLookUp(str: string): NamedNodeLookUp {
|
||||
export async function createNamedNodeLookUp(str: string): Promise<NamedNodeLookUp> {
|
||||
|
||||
const ts = await import('typescript');
|
||||
|
||||
const sourceFile = ts.createSourceFile('fake.d.ts', str, ts.ScriptTarget.Latest);
|
||||
|
||||
|
|
Loading…
Reference in a new issue