提交 63021129 编写于 作者: J Johannes Rieken

use async module loading for typescript, #33141

上级 02782175
......@@ -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);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册