Skip to content

Commit

Permalink
Improve sorting of completion candidates based on numeric values.
Browse files Browse the repository at this point in the history
  • Loading branch information
manateelazycat committed Apr 24, 2023
1 parent 7e1e6a4 commit 9004306
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions core/handler/completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,24 @@ def process_request(self, lsp_server, position, char, prefix) -> dict:
self.position = position
self.prefix = prefix
return dict(position=position, context=context)

def parse_sort_value(self, sort_text):
if sort_text == "":
return sort_text
else:
sort_text = ''.join(c for c in sort_text if c.isdigit() or c == '.')

if sort_text.endswith("."):
sort_text = sort_text[:-1]

return sort_text

def compare_candidates(self, x, y):
prefix = self.prefix.lower()
x_label : str = x["label"].lower()
y_label : str = y["label"].lower()
x_sort_text : str = x["sortText"]
y_sort_text : str = y["sortText"]
x_sort_text : str = self.parse_sort_value(x["sortText"])
y_sort_text : str = self.parse_sort_value(y["sortText"])
x_include_prefix = x_label.startswith(prefix)
y_include_prefix = y_label.startswith(prefix)

Expand Down

0 comments on commit 9004306

Please sign in to comment.