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

feat(links): only fetch links on documeng changed #4690

Merged
merged 1 commit into from
Aug 31, 2023
Merged
Show file tree
Hide file tree
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
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