Skip to content

Commit

Permalink
feat(links): only fetch links on documeng changed (#4690)
Browse files Browse the repository at this point in the history
closes #4687
  • Loading branch information
fannheyward committed Aug 31, 2023
1 parent ed89997 commit d432de2
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
6 changes: 0 additions & 6 deletions src/__tests__/handler/documentLinks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
Expand All @@ -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)
})
})
5 changes: 4 additions & 1 deletion src/handler/links.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[] = []
Expand Down Expand Up @@ -215,7 +216,9 @@ class LinkBuffer implements SyncItem {
}

public async getLinks(): Promise<void> {
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
Expand Down

0 comments on commit d432de2

Please sign in to comment.