Skip to content

Commit

Permalink
Merge pull request #762 from pulsar-edit/fix-autocomplete-v5
Browse files Browse the repository at this point in the history
Fixed filtering of suggestions with ranges
  • Loading branch information
confused-Techie authored Oct 15, 2023
2 parents 418b6f0 + 4995c7a commit 34a5c5b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
11 changes: 6 additions & 5 deletions packages/autocomplete-plus/lib/autocomplete-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -377,14 +377,15 @@ class AutocompleteManager {
const text = (suggestion.snippet || suggestion.text)
const suggestionPrefix = suggestion.replacementPrefix != null ? suggestion.replacementPrefix : prefix
const prefixIsEmpty = !suggestionPrefix || suggestionPrefix === ' '
const firstCharIsMatch = !prefixIsEmpty && suggestionPrefix[0].toLowerCase() === text[0].toLowerCase()

if (prefixIsEmpty) {
results.push(suggestion)
}
if (firstCharIsMatch && (score = fuzzaldrinProvider.score(text, suggestionPrefix)) > 0) {
suggestion.score = score * suggestion.sortScore
results.push(suggestion)
} else {
const keepMatching = suggestion.ranges || suggestionPrefix[0].toLowerCase() === text[0].toLowerCase()
if (keepMatching && (score = fuzzaldrinProvider.score(text, suggestionPrefix)) > 0) {
suggestion.score = score * suggestion.sortScore
results.push(suggestion)
}
}
}

Expand Down
20 changes: 20 additions & 0 deletions packages/autocomplete-plus/spec/provider-api-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -327,5 +327,25 @@ describe('Provider API', () => {

expect(editor.getText()).toEqual("ohai, world\n")
})

it('ignores `prefix` if `range` is present', async () => {
testProvider = {
scopeSelector: '.source.js',
filterSuggestions: true,
getSuggestions (options) {
return [
{text: 'notmatch/foololohairange', ranges: [[[0, 0], [0, 5]]]},
{text: 'notmatch/foololohaiprefix'},
{text: 'foololohaiprefix2'}
]
}
}
registration = atom.packages.serviceHub.provide('autocomplete.provider', '5.0.0', testProvider)
editor.insertText('foololohai')
await triggerAutocompletion()
expect(document.querySelector('autocomplete-suggestion-list').innerText).toMatch(/notmatch\/foololohairange/)
expect(document.querySelector('autocomplete-suggestion-list').innerText).toMatch(/foololohaiprefix2/)
expect(document.querySelector('autocomplete-suggestion-list').innerText).toNotMatch(/notmatch\/foololohaiprefix/)
})
})
})

0 comments on commit 34a5c5b

Please sign in to comment.