Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow third-party packages to open abstract URIs as well #1781

Merged
merged 2 commits into from
Jul 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion boot.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

# Please keep this list sorted (Edit -> Sort Lines)
from .plugin.code_actions import LspCodeActionsCommand
from .plugin.code_lens import LspCodeLensCommand
from .plugin.completion import LspResolveDocsCommand
from .plugin.completion import LspSelectCompletionItemCommand
from .plugin.configuration import LspDisableLanguageServerGloballyCommand
Expand All @@ -21,6 +22,7 @@
from .plugin.core.panels import LspUpdatePanelCommand
from .plugin.core.panels import LspUpdateServerPanelCommand
from .plugin.core.panels import WindowPanelListener
from .plugin.core.protocol import Location
from .plugin.core.protocol import Response
from .plugin.core.protocol import WorkspaceFolder
from .plugin.core.registry import LspRecheckSessionsCommand
Expand All @@ -36,8 +38,8 @@
from .plugin.core.transports import kill_all_subprocesses
from .plugin.core.types import ClientConfig
from .plugin.core.typing import Any, Optional, List, Type, Callable, Dict, Tuple
from .plugin.core.views import get_uri_and_position_from_location
from .plugin.core.views import LspRunTextCommandHelperCommand
from .plugin.code_lens import LspCodeLensCommand
from .plugin.documents import DocumentSyncListener
from .plugin.documents import TextChangeListener
from .plugin.edit import LspApplyDocumentEditCommand
Expand Down Expand Up @@ -227,3 +229,32 @@ def on_post_window_command(self, window: sublime.Window, command_name: str, args
view = window.active_view()
if view:
view.run_command("lsp_hover", {"only_diagnostics": True})


class LspOpenLocationCommand(sublime_plugin.TextCommand):
"""
A command to be used by third-party ST packages that need to open an URI with some abstract scheme.
"""

def run(
self,
_: sublime.Edit,
location: Location,
session_name: Optional[str] = None,
flags: int = 0,
group: int = -1
) -> None:
sublime.set_timeout_async(lambda: self._run_async(location, session_name, flags, group))

def _run_async(self, location: Location, session_name: Optional[str], flags: int = 0, group: int = -1) -> None:
window = self.view.window()
if not window:
return
windows.lookup(window).open_location_async(location, session_name, self.view, flags, group).then(
lambda success: self._handle_continuation(location, success))

def _handle_continuation(self, location: Location, success: bool) -> None:
if not success:
uri, _ = get_uri_and_position_from_location(location)
message = "Failed to open {}".format(uri)
sublime.status_message(message)
15 changes: 15 additions & 0 deletions plugin/core/windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
from .logging import exception_log
from .message_request_handler import MessageRequestHandler
from .panels import log_server_message
from .promise import Promise
from .protocol import Diagnostic
from .protocol import Error
from .protocol import Location
from .sessions import get_plugin
from .sessions import Logger
from .sessions import Manager
Expand Down Expand Up @@ -189,6 +191,19 @@ def enable_config_async(self, config_name: str) -> None:
def disable_config_async(self, config_name: str) -> None:
self._configs.disable_config(config_name)

def open_location_async(
self,
location: Location,
session_name: Optional[str],
view: sublime.View,
flags: int = 0,
group: int = -1
) -> Promise[bool]:
for session in self.sessions(view):
if session_name is None or session_name == session.config.name:
return session.open_location_async(location, flags, group)
return Promise.resolve(False)

def register_listener_async(self, listener: AbstractViewListener) -> None:
set_diagnostics_count(listener.view, self.total_error_count, self.total_warning_count)
# Update workspace folders in case the user have changed those since window was created.
Expand Down