Skip to content

Commit

Permalink
Bug fixes for intelephense and CCLS (#524)
Browse files Browse the repository at this point in the history
* Complete using text edit by default
* Support both SymbolInformation as well as DocumentSymbol for textDocument/documentSymbol
* Woops. Forgot to import debug. Also hail mypy
* Add tests for textEdit completions
* Add more tests for textEdit completions
* Don't use KeyError exception for control-flow
* Do a better job of describing the completion tests
* Get rid of the noqa: E501 lines in test_completion.py By just adding a newline in the appropriate places
  • Loading branch information
rwols committed Mar 2, 2019
1 parent cee39d7 commit ca0fc71
Show file tree
Hide file tree
Showing 8 changed files with 1,107 additions and 41 deletions.
26 changes: 12 additions & 14 deletions plugin/completion.py
Expand Up @@ -282,20 +282,18 @@ def format_completion(self, item: dict) -> 'Tuple[str, str]':
return "\t ".join((trigger, hint)) if hint else trigger, insert_text

def text_edit_text(self, item) -> 'Optional[str]':
if settings.complete_using_text_edit:
# try to handle textEdit if present
text_edit = item.get("textEdit")
if text_edit:
edit_range, edit_text = text_edit.get("range"), text_edit.get("newText")
if edit_range and edit_text:
edit_range = Range.from_lsp(edit_range)
last_start = self.last_location - len(self.last_prefix)
last_row, last_col = self.view.rowcol(last_start)
if last_row == edit_range.start.row == edit_range.end.row and edit_range.start.col <= last_col:
# sublime does not support explicit replacement with completion
# at given range, but we try to trim the textEdit range and text
# to the start location of the completion
return edit_text[last_col - edit_range.start.col:]
text_edit = item.get("textEdit")
if text_edit:
edit_range, edit_text = text_edit.get("range"), text_edit.get("newText")
if edit_range and edit_text:
edit_range = Range.from_lsp(edit_range)
last_start = self.last_location - len(self.last_prefix)
last_row, last_col = self.view.rowcol(last_start)
if last_row == edit_range.start.row == edit_range.end.row and edit_range.start.col <= last_col:
# sublime does not support explicit replacement with completion
# at given range, but we try to trim the textEdit range and text
# to the start location of the completion
return edit_text[last_col - edit_range.start.col:]
return None

def handle_response(self, response: 'Optional[Dict]'):
Expand Down
1 change: 0 additions & 1 deletion plugin/core/settings.py
Expand Up @@ -63,7 +63,6 @@ def update_settings(settings: Settings, settings_obj: sublime.Settings):
settings.only_show_lsp_completions = read_bool_setting(settings_obj, "only_show_lsp_completions", False)
settings.complete_all_chars = read_bool_setting(settings_obj, "complete_all_chars", True)
settings.completion_hint_type = read_str_setting(settings_obj, "completion_hint_type", "auto")
settings.complete_using_text_edit = read_bool_setting(settings_obj, "complete_using_text_edit", False)
settings.resolve_completion_for_snippets = read_bool_setting(settings_obj, "resolve_completion_for_snippets", False)
settings.show_references_in_quick_panel = read_bool_setting(settings_obj, "show_references_in_quick_panel", False)
settings.log_debug = read_bool_setting(settings_obj, "log_debug", False)
Expand Down
1 change: 0 additions & 1 deletion plugin/core/types.py
Expand Up @@ -33,7 +33,6 @@ def __init__(self) -> None:
self.show_code_actions_bulb = False
self.complete_all_chars = False
self.completion_hint_type = "auto"
self.complete_using_text_edit = False
self.resolve_completion_for_snippets = False
self.show_references_in_quick_panel = False
self.log_debug = True
Expand Down
10 changes: 7 additions & 3 deletions plugin/symbols.py
@@ -1,7 +1,7 @@

from .core.logging import debug
from .core.protocol import Request, Range
from .core.protocol import SymbolKind
from .core.registry import client_for_view, LspTextCommand
from .core.protocol import Request, Range
from .core.url import filename_to_uri
from .core.views import range_to_region

Expand Down Expand Up @@ -81,7 +81,11 @@ def handle_response(self, response: 'Optional[List]') -> None:

def on_symbol_selected(self, symbol_index):
selected_symbol = self.symbols[symbol_index]
range = selected_symbol['location']['range']
range = selected_symbol.get('location', selected_symbol.get('range'))
range = range.get('range', range)
if not range:
debug('could not recognize the type: expected either SymbolInformation or DocumentSymbol')
return
region = range_to_region(Range.from_lsp(range), self.view)
self.view.show_at_center(region)
self.view.sel().clear()
Expand Down

0 comments on commit ca0fc71

Please sign in to comment.