sublimelsp / LSP

Client implementation of the Language Server Protocol for Sublime Text
https://lsp.sublimetext.io/
MIT License
1.65k stars 179 forks source link

[Completion Regression] text_edit_text returns None constantly #645

Closed ayoub-benali closed 5 years ago

ayoub-benali commented 5 years ago

Not sure when the regression happened but this column check:

            if edit_range.start.col <= word_col:
                # if edit starts at current word, we can use it.
                # if edit starts before current word, use the whole thing and we'll fix it up later.
                return edit_text

here returns always False now. Which leads the completion to fallback to label instead of using textEdit. As you can see bellow:

autocomplete-3

Logs with some debug variables:

item: {'textEdit': {'newText': 'apply($0)', 'range': {'end': {'line': 3, 'character': 7}, 'start': {'line': 3, 'character': 7}}}, 'label': 'apply[A](xs: A*): List[A]', 'sortText': '00000', 'preselect': True, 'insertTextFormat': 2, 'filterText': 'apply', 'data': {'symbol': 'scala/collection/immutable/List.apply().', 'target': 'file:/home/ayoub/workspace/testproject/?id=root'}, 'kind': 2}

LSP start: {'line': 3, 'character': 7}
_last_row: 3, last_col: 6
LSP: textEdit from col 7, 7 applied at col 6
edit_range.start.col: 7, word_col: 6

For me the condition here is incomplete and doesn't handle the case when the completion happens after last word beginning. In this case a .

I think we are safe to remove the condition.

I can make a PR but wanted first to confirm the issue with @tomv564

tomv564 commented 5 years ago

Thanks for reporting. I think word_col is incorrectly provided to format_completion by plugin/completion.py

The logic there looks up the start of the current word being completed. In your example sublime tells us that the . is a word - we should probably only use the start-of-word lookup if the cursor is at a word, see is_at_word.

Can have a look at a fix for this soon, or feel free to open a PR.

ayoub-benali commented 5 years ago

we should probably only use the start-of-word lookup if the cursor is at a word

You mean in the text_edit_text function ?

tomv564 commented 5 years ago

No, the needed check was in CompletionHandler's handle_response method - see the merged PR above.