summaryrefslogtreecommitdiff
path: root/rplugin
diff options
context:
space:
mode:
authorShougo Matsushita <Shougo.Matsu@gmail.com>2020-03-17 21:12:28 +0900
committerShougo Matsushita <Shougo.Matsu@gmail.com>2020-03-17 21:12:28 +0900
commit73ded90a5bf6e7b164c72efd5c72ecdb8d6e30b8 (patch)
treec1abab41f26944bc72032566ede42f7328319e1d /rplugin
parent479e1fd81a612f9987a0179a8b35c8da35943fd8 (diff)
downloaddeoplete.nvim-73ded90a5bf6e7b164c72efd5c72ecdb8d6e30b8.zip
Fix #1085 implement locality in sorter_rank
Diffstat (limited to 'rplugin')
-rw-r--r--rplugin/python3/deoplete/filter/sorter_rank.py33
1 files changed, 18 insertions, 15 deletions
diff --git a/rplugin/python3/deoplete/filter/sorter_rank.py b/rplugin/python3/deoplete/filter/sorter_rank.py
index b64a20b..41a33f2 100644
--- a/rplugin/python3/deoplete/filter/sorter_rank.py
+++ b/rplugin/python3/deoplete/filter/sorter_rank.py
@@ -12,8 +12,7 @@ from deoplete.util import getlines
from deoplete.util import Nvim, UserContext, Candidates, Candidate
-LINES_ABOVE = 100
-LINES_BELOW = 100
+LINES_MAX = 150
class Filter(Base):
@@ -23,26 +22,30 @@ class Filter(Base):
self.name = 'sorter_rank'
self.description = 'rank sorter'
- self._cache: typing.Dict[str, int] = {}
+ self._cache: typing.Dict[str, typing.Set[int]] = {}
def on_event(self, context: UserContext) -> None:
- line = context['position'][1]
- lines = getlines(self.vim,
- max([1, line - LINES_ABOVE]), line + LINES_BELOW)
-
self._cache = {}
- for m in re.finditer(context['keyword_pattern'], '\n'.join(lines)):
- k = m.group(0)
- if k in self._cache:
- self._cache[k] += 1
- else:
- self._cache[k] = 1
+ start = max([1, context['position'][1] - LINES_MAX])
+ linenr = start
+ for line in getlines(self.vim, start, start + LINES_MAX):
+ for m in re.finditer(context['keyword_pattern'], line):
+ k = m.group(0)
+ if k not in self._cache:
+ self._cache[k] = set()
+ self._cache[k].add(linenr)
+ linenr += 1
def filter(self, context: UserContext) -> Candidates:
complete_str = context['complete_str'].lower()
+ linenr = context['position'][1]
def compare(x: Candidate) -> int:
matched = int(complete_str in x['word'].lower())
- mru = self._cache.get(x['word'], 0)
- return -(matched * 40 + mru * 20)
+ score = -matched * 40
+ if x['word'] in self._cache:
+ mru = min([abs(x - linenr) for x in self._cache[x['word']]])
+ mru -= LINES_MAX
+ score += mru * 10
+ return score
return sorted(context['candidates'], key=compare)