From 8475089850c04b5e1a37badfdbd1215362385113 Mon Sep 17 00:00:00 2001 From: Sumner Evans Date: Sat, 1 Aug 2020 11:28:30 -0600 Subject: [PATCH] Make search result calculation even more robust --- CHANGELOG.rst | 7 +++++++ sublime/__init__.py | 2 +- sublime/adapters/api_objects.py | 33 ++++++++++++++++++--------------- 3 files changed, 26 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 773105c..7d13812 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,3 +1,10 @@ +v0.11.6 +======= + +**Bug Fixes** + +* Fixes more bugs with search not working in certain situations. (#253) + v0.11.5 ======= diff --git a/sublime/__init__.py b/sublime/__init__.py index 91df974..be37974 100644 --- a/sublime/__init__.py +++ b/sublime/__init__.py @@ -1 +1 @@ -__version__ = "0.11.5" +__version__ = "0.11.6" diff --git a/sublime/adapters/api_objects.py b/sublime/adapters/api_objects.py index cf34310..c4cf629 100644 --- a/sublime/adapters/api_objects.py +++ b/sublime/adapters/api_objects.py @@ -181,21 +181,24 @@ class SearchResult: self, it: Dict[str, _S], transform: Callable[[_S], Tuple[Optional[str], ...]], ) -> List[_S]: assert self.query - all_results = sorted( - ( - ( - max( - self.similiarity_partial(t.lower()) - for t in transform(x) - if t is not None - ), - x, - ) - for x in it.values() - ), - key=lambda rx: rx[0], - reverse=True, - ) + all_results = [] + for value in it.values(): + transformed = transform(value) + if any(t is None for t in transformed): + continue + + max_similarity = max( + self.similiarity_partial(t.lower()) + for t in transformed + if t is not None + ) + if max_similarity < 60: + continue + + all_results.append((max_similarity, value)) + + all_results.sort(key=lambda rx: rx[0], reverse=True) + result: List[SearchResult._S] = [] for ratio, x in all_results: if ratio >= 60 and len(result) < 20: