Skip to content

Commit

Permalink
perf: return early in around and buffer source (#4721)
Browse files Browse the repository at this point in the history
  • Loading branch information
UncleBill committed Aug 8, 2023
1 parent eba04ac commit fab97c7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
9 changes: 5 additions & 4 deletions src/completion/native/around.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,18 @@ export class Around extends Source {

public async doComplete(opt: CompleteOption, token: CancellationToken): Promise<CompleteResult<ExtendedCompleteItem>> {
let { bufnr, input, word, linenr, triggerForInComplete } = opt
if (input.length === 0) return null
let buf = this.keywords.getItem(bufnr)
if (!buf) return null
await waitImmediate()
if (!triggerForInComplete) this.noMatchWords = new Set()
if (input.length === 0 || !buf || token.isCancellationRequested) return null
if (token.isCancellationRequested) return null
let iterable = buf.matchWords(linenr - 1)
let items: Set<string> = new Set()
let isIncomplete = await this.getResults([iterable], input, word, items, token)
return {
isIncomplete, items: Array.from(items).map(s => {
return { word: s }
})
isIncomplete,
items: Array.from(items, word => ({ word }))
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/completion/native/buffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ export class Buffer extends Source {

public async doComplete(opt: CompleteOption, token: CancellationToken): Promise<CompleteResult<ExtendedCompleteItem>> {
let { bufnr, input, word, triggerForInComplete } = opt
if (input.length === 0) return null
await waitImmediate()
if (!triggerForInComplete) this.noMatchWords = new Set()
if (input.length === 0 || token.isCancellationRequested) return null
if (token.isCancellationRequested) return null
let iterables: Iterable<string>[] = []
for (let buf of this.keywords.items) {
if (buf.bufnr === bufnr || (this.ignoreGitignore && buf.gitIgnored)) continue
Expand Down

0 comments on commit fab97c7

Please sign in to comment.