Skip to content

Commit

Permalink
Order the completion by frequency of the words in the view.
Browse files Browse the repository at this point in the history
  • Loading branch information
edelvalle committed Jul 28, 2017
1 parent 2c9a5e4 commit 55739e2
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions super_elixir/autocomplete.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import sublime
import sublime_plugin

from .utils import is_elixir, get_buffer_line_column
from .sense_client import get_elixir_sense

Expand All @@ -17,9 +18,6 @@ def on_query_completions(self, view, prefix, locations):
sense = get_elixir_sense(view)
suggestions = sense.suggestions(buffer, line, column)

# from pprint import pprint
# pprint(suggestions)

completions = []
for s in suggestions:
if s['type'] == 'hint':
Expand Down Expand Up @@ -58,22 +56,27 @@ def on_query_completions(self, view, prefix, locations):

completions.append(c)

completions = self._sort_by_frequency_in_view(buffer, completions)
completions = [
['{show}\t{hint}'.format(**c), c['completion']]
for c in completions
]
return completions

def _sort_by_frequency_in_view(self, buffer, completions):
for completion in completions:
completion['count'] = buffer.count(completion['name'])

completions.sort(key=lambda c: (-c['count'], c['name']))
return completions

def on_hover(self, view, point, hover_zone):
if hover_zone == sublime.HOVER_TEXT and is_elixir(view):

buffer, line, column = get_buffer_line_column(view, point)
sense = get_elixir_sense(view)
docs = sense.docs(buffer, line, column)

# from pprint import pprint
# pprint(docs)

types = docs['docs']['types']
types = ''.join(re.compile(r'`([^`]+)`').findall(types))

Expand Down

0 comments on commit 55739e2

Please sign in to comment.