diff --git a/src/__tests__/handler/documentLinks.test.ts b/src/__tests__/handler/documentLinks.test.ts index f66ee240aa1..6294cfb1c21 100644 --- a/src/__tests__/handler/documentLinks.test.ts +++ b/src/__tests__/handler/documentLinks.test.ts @@ -258,10 +258,8 @@ describe('LinkBuffer', () => { }) it('should do highlight', async () => { - let empty = false disposables.push(languages.registerDocumentLinkProvider([{ language: '*' }], { provideDocumentLinks: (doc: TextDocument) => { - if (empty) return [] let links: DocumentLink[] = [] for (let i = 0; i < doc.lineCount - 1; i++) { links.push(DocumentLink.create(Range.create(i, 0, i, 1), 'test:///bar')) @@ -286,9 +284,5 @@ describe('LinkBuffer', () => { doc._forceSync() let hls = await buf.buffer.getHighlights('links') expect(hls.length).toBe(2) - empty = true - await buf.getLinks() - hls = await buf.buffer.getHighlights('links') - expect(hls.length).toBe(0) }) }) diff --git a/src/handler/links.ts b/src/handler/links.ts index 6a55f1e726f..91654df0f45 100644 --- a/src/handler/links.ts +++ b/src/handler/links.ts @@ -145,6 +145,7 @@ export default class Links implements Disposable { } class LinkBuffer implements SyncItem { + private currentVersion = -1 private tokenSource: CancellationTokenSource | undefined private _config: LinkConfig | undefined public links: DocumentLink[] = [] @@ -215,7 +216,9 @@ class LinkBuffer implements SyncItem { } public async getLinks(): Promise { - if (!this.hasProvider || !this.config.enable) return + if (!this.hasProvider || !this.config.enable || this.currentVersion === this.doc.version) return + this.currentVersion = this.doc.version + this.cancel() let tokenSource = this.tokenSource = new CancellationTokenSource() let token = tokenSource.token