Skip to content

Commit

Permalink
Some documentation and formatting for completions
Browse files Browse the repository at this point in the history
  • Loading branch information
tomv564 committed Jun 7, 2019
1 parent 85af377 commit 8c7102c
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions plugin/completion.py
Expand Up @@ -124,6 +124,7 @@ def find_completion_item(self, inserted: str):
Matches exactly or up to first snippet placeholder ($s)
"""
# TODO: candidate for extracting and thorough testing.
if self.completions:
for index, item in enumerate(self.completions):
trigger, replacement = item
Expand Down Expand Up @@ -154,17 +155,19 @@ def on_modified(self):
self.on_completion_inserted()

def on_completion_inserted(self):
# get text inserted from last completion
word = self.view.word(self.last_location)
region = sublime.Region(word.begin(), self.view.sel()[0].end())
inserted = self.view.substr(region)

item = self.find_completion_item(inserted)
if item:
# the newText is already inserted, now we need to check where it should start.
edit = item.get('textEdit')
if edit:
parsed_edit = parse_text_edit(edit)
start, end, newText = parsed_edit
row, col = start
edit_start_loc = self.view.text_point(row, col)
edit_start_loc = self.view.text_point(*start)

# if the edit started before the word, we need to trim back to the start of the edit.
if edit_start_loc < word.begin():
Expand Down Expand Up @@ -261,10 +264,12 @@ def apply_additional_edits(self, additional_edits: 'List[Dict]') -> None:

def handle_response(self, response: 'Optional[Union[Dict,List]]'):
if self.state == CompletionState.REQUESTING:
word = self.view.word(self.last_location)

# where does the current word start?
word = self.view.word(self.last_location)
last_start = word.begin()
last_row, last_col = self.view.rowcol(last_start)
_last_row, last_col = self.view.rowcol(last_start)

self.response = parse_completion_response(response)
self.completions = list(format_completion(item, last_col, settings) for item in self.response)

Expand Down

0 comments on commit 8c7102c

Please sign in to comment.