mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-09-11 11:15:24 +03:00
Fixed filtering of suggestions with ranges
This commit is contained in:
parent
3cea42c614
commit
4995c7a1e6
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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/)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user