diff --git a/LSP.sublime-settings b/LSP.sublime-settings index 9d5e9d8dc..091047e2c 100644 --- a/LSP.sublime-settings +++ b/LSP.sublime-settings @@ -366,9 +366,6 @@ // Disable Sublime Text's explicit and word completion. "only_show_lsp_completions": false, - // Resolve completions and apply snippet if received. - "resolve_completion_for_snippets": false, - // When presenting completions, prefer the "label" over the "filterText" key // in the CompletionItem. By default, the "filterText" is chosen over the // "label". If the "filterText" is not present, fall back to the "label". diff --git a/docs/index.md b/docs/index.md index 9a242f3c6..ae1f7e965 100644 --- a/docs/index.md +++ b/docs/index.md @@ -9,7 +9,6 @@ Global plugin settings and settings defined at project level are merged together * `complete_all_chars` `true` *request completions for all characters, not just trigger characters* * `only_show_lsp_completions` `false` *disable sublime word completion and snippets from autocomplete lists* * `completion_hint_type` `"auto"` *override automatic completion hints with "detail", "kind" or "none"* -* `resolve_completion_for_snippets` `false` *resolve completions and apply snippet if received* * `prefer_label_over_filter_text` `false` *always use the "label" key instead of the "filterText" key in CompletionItems* * `show_references_in_quick_panel` `false` *show symbol references in Sublime's quick panel instead of the bottom panel* * `quick_panel_monospace_font` `false` *use monospace font for the quick panel* @@ -230,12 +229,12 @@ See [github:rust-lang-nursery/rls](https://github.com/rust-lang-nursery/rls) for * **[Metals](https://scalameta.org/metals/)**: Most complete LSP server for Scala, see instructions [here](https://scalameta.org/metals/docs/editors/sublime.html) for installation. * **[SBT](https://www.scala-sbt.org/)**: Version 1.x supports limited and *unmaintained* language server functionalities, setup is described [here](http://eed3si9n.com/sbt-server-with-sublime-text3). -* **[Dotty](http://dotty.epfl.ch/)**: The future Scala compiler [contains LSP support](http://dotty.epfl.ch/docs/usage/ide-support.html). -It is developed against VS Code, so ignore instructions related to VS Code. -Get the project compiling with dotty first (see [instructions](https://github.com/lampepfl/dotty-example-project#using-dotty-in-an-existing-project)). +* **[Dotty](http://dotty.epfl.ch/)**: The future Scala compiler [contains LSP support](http://dotty.epfl.ch/docs/usage/ide-support.html). +It is developed against VS Code, so ignore instructions related to VS Code. +Get the project compiling with dotty first (see [instructions](https://github.com/lampepfl/dotty-example-project#using-dotty-in-an-existing-project)). At this point LSP should complain in the logs -`java.util.concurrent.CompletionException: java.io.FileNotFoundException: /Users/tomv/Projects/tomv564/dottytest/finagle/doc/src/sphinx/code/quickstart/.dotty-ide.json` -Then run `sbt configureIDE` to create the `.dotty-ide.json` file +`java.util.concurrent.CompletionException: java.io.FileNotFoundException: /Users/tomv/Projects/tomv564/dottytest/finagle/doc/src/sphinx/code/quickstart/.dotty-ide.json` +Then run `sbt configureIDE` to create the `.dotty-ide.json` file Then the LSP plugin should launch as configured in `LSP.sublime-settings` using coursier. diff --git a/plugin/completion.py b/plugin/completion.py index 8da6fa7bf..ecd1d7d45 100644 --- a/plugin/completion.py +++ b/plugin/completion.py @@ -10,7 +10,7 @@ from .core.protocol import Request from .core.events import global_events from .core.settings import settings, client_configs -from .core.logging import debug, exception_log +from .core.logging import debug from .core.protocol import CompletionItemKind, Range from .core.registry import session_for_view, client_for_view from .core.configurations import is_supported_syntax @@ -28,90 +28,6 @@ class CompletionState(object): CANCELLING = 3 -resolvable_completion_items = [] # type: List[Any] - - -def find_completion_item(label: str) -> 'Optional[Any]': - matches = list(filter(lambda i: i.get("label") == label, resolvable_completion_items)) - return matches[0] if matches else None - - -class CompletionContext(object): - - def __init__(self, begin): - self.begin = begin # type: Optional[int] - self.end = None # type: Optional[int] - self.region = None # type: Optional[sublime.Region] - self.committing = False - - def committed_at(self, end): - self.end = end - self.region = sublime.Region(self.begin, self.end) - self.committing = False - - -current_completion = None # type: Optional[CompletionContext] - - -def has_resolvable_completions(view): - session = session_for_view(view) - if session: - completionProvider = session.get_capability( - 'completionProvider') - if completionProvider: - if completionProvider.get('resolveProvider', False): - return True - return False - - -class CompletionSnippetHandler(sublime_plugin.EventListener): - - def on_query_completions(self, view, prefix, locations): - global current_completion - if settings.resolve_completion_for_snippets and has_resolvable_completions(view): - current_completion = CompletionContext(view.sel()[0].begin()) - - def on_text_command(self, view, command_name, args): - if settings.resolve_completion_for_snippets and current_completion: - current_completion.committing = command_name in ('commit_completion', 'insert_best_completion') - - def on_modified(self, view): - global current_completion - - if settings.resolve_completion_for_snippets and view.file_name(): - if current_completion and current_completion.committing: - current_completion.committed_at(view.sel()[0].end()) - inserted = view.substr(current_completion.region) - item = find_completion_item(inserted) - if item: - self.resolve_completion(item, view) - else: - current_completion = None - - def resolve_completion(self, item, view): - session = session_for_view(view) - if not session: - return - if not session.client: - return - - session.client.send_request( - Request.resolveCompletionItem(item), - lambda response: self.handle_resolve_response(response, view)) - - def handle_resolve_response(self, response, view): - # replace inserted text if a snippet was returned. - if current_completion and response.get('insertTextFormat') == 2: # snippet - insertText = response.get('insertText') - try: - sel = view.sel() - sel.clear() - sel.add(current_completion.region) - view.run_command("insert_snippet", {"contents": insertText}) - except Exception as err: - exception_log("Error inserting snippet: " + insertText, err) - - last_text_command = None @@ -127,8 +43,6 @@ def __init__(self, view): self.initialized = False self.enabled = False self.trigger_chars = [] # type: List[str] - self.resolve = False - self.resolve_details = [] # type: List[Tuple[str, str]] self.state = CompletionState.IDLE self.completions = [] # type: List[Any] self.next_request = None # type: Optional[Tuple[str, List[int]]] @@ -153,7 +67,6 @@ def initialize(self): self.enabled = True self.trigger_chars = completionProvider.get( 'triggerCharacters') or [] - self.has_resolve_provider = completionProvider.get('resolveProvider', False) if self.trigger_chars: self.register_trigger_chars(session) @@ -299,7 +212,6 @@ def text_edit_text(self, item) -> 'Optional[str]': return None def handle_response(self, response: 'Optional[Dict]'): - global resolvable_completion_items if self.state == CompletionState.REQUESTING: items = [] # type: List[Dict] @@ -310,9 +222,6 @@ def handle_response(self, response: 'Optional[Dict]'): items = sorted(items, key=lambda item: item.get("sortText") or item["label"]) self.completions = list(self.format_completion(item) for item in items) - if self.has_resolve_provider: - resolvable_completion_items = items - # if insert_best_completion was just ran, undo it before presenting new completions. prev_char = self.view.substr(self.view.sel()[0].begin() - 1) if prev_char.isspace(): diff --git a/plugin/core/settings.py b/plugin/core/settings.py index 2eb3678f8..4a295fb1a 100644 --- a/plugin/core/settings.py +++ b/plugin/core/settings.py @@ -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.resolve_completion_for_snippets = read_bool_setting(settings_obj, "resolve_completion_for_snippets", False) settings.prefer_label_over_filter_text = read_bool_setting(settings_obj, "prefer_label_over_filter_text", False) settings.show_references_in_quick_panel = read_bool_setting(settings_obj, "show_references_in_quick_panel", False) settings.quick_panel_monospace_font = read_bool_setting(settings_obj, "quick_panel_monospace_font", False) diff --git a/plugin/core/types.py b/plugin/core/types.py index 2c831e2d0..bd6f56b00 100644 --- a/plugin/core/types.py +++ b/plugin/core/types.py @@ -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.resolve_completion_for_snippets = False self.prefer_label_over_filter_text = False self.show_references_in_quick_panel = False self.quick_panel_monospace_font = False