Skip to content
Draft
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
11 changes: 2 additions & 9 deletions plugin/code_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,19 +353,15 @@ def is_visible(
return self.is_enabled(event, point)
return True

def run(
async def run(
self,
edit: sublime.Edit,
event: dict | None = None,
only_kinds: list[str | CodeActionKind] | None = None,
code_actions_by_config: list[CodeActionsByConfigName] | None = None
) -> None:
if code_actions_by_config:
self._handle_code_actions(code_actions_by_config, run_first=True)
return
run_coroutine(self._run(only_kinds))

async def _run(self, only_kinds: list[str | CodeActionKind] | None = None) -> None:
view = self.view
region = first_selection_region(view)
if region is None:
Expand Down Expand Up @@ -465,10 +461,7 @@ def description(self, index: int, event: dict | None = None) -> str | None:
def want_event(self) -> bool:
return True

def run(self, index: int, event: dict | None = None) -> None:
run_coroutine(self._run(index, event))

async def _run(self, index: int, event: dict | None) -> None:
async def run(self, index: int, event: dict | None = None) -> None:
if self._is_cache_valid(event):
config_name, action = self.actions_cache[index]
if session := self.session_by_name(config_name):
Expand Down
6 changes: 1 addition & 5 deletions plugin/code_lens.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from __future__ import annotations

from .core.aio import run_coroutine
from .core.constants import CODE_LENS_ENABLED_KEY
from .core.protocol import Error
from .core.protocol import Request
Expand Down Expand Up @@ -128,12 +127,9 @@ def are_enabled(cls, window: sublime.Window | None) -> bool:
def is_checked(self) -> bool:
return self.are_enabled(self.window)

def run(self) -> None:
async def run(self) -> None:
enable = not self.is_checked()
self.window.settings().set(CODE_LENS_ENABLED_KEY, enable)
run_coroutine(self._update_views(enable))

async def _update_views(self, enable: bool) -> None:
window_manager = windows.lookup(self.window)
if not window_manager:
return
Expand Down
5 changes: 1 addition & 4 deletions plugin/completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,10 +267,7 @@ def _get_userpref_flags(self) -> sublime.AutoCompleteFlags:

class LspResolveDocsCommand(LspTextCommand):

def run(self, edit: sublime.Edit, index: int, session_name: str, event: dict | None = None) -> None:
run_coroutine(self._run(index, session_name, event))

async def _run(self, index: int, session_name: str, event: dict | None = None) -> None:
async def run(self, index: int, session_name: str, event: dict | None = None) -> None:
items, item_defaults = LspSelectCompletionCommand.completions[session_name]
item = completion_with_defaults(items[index], item_defaults)
language_map: MarkdownLangMap | None = None
Expand Down
26 changes: 9 additions & 17 deletions plugin/core/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from typing import TYPE_CHECKING
import operator
import sublime
import sublime_plugin
import sublime_aio

if TYPE_CHECKING:
from ...protocol import Diagnostic
Expand Down Expand Up @@ -52,7 +52,7 @@ def get_position(view: sublime.View, event: dict | None = None, point: int | Non
return None


class LspWindowCommand(sublime_plugin.WindowCommand):
class LspWindowCommand(sublime_aio.WindowCommand):
"""
Inherit from this class to define requests which are not bound to a particular view. This allows to run requests
for example from links in HtmlSheets or when an unrelated file has focus.
Expand Down Expand Up @@ -115,7 +115,7 @@ def manager(self) -> WindowManager | None:
return windows.lookup(self.window)


class LspTextCommand(sublime_plugin.TextCommand):
class LspTextCommand(sublime_aio.ViewCommand):
"""
Inherit from this class to define your requests that should be triggered via the command palette and/or a
keybinding.
Expand Down Expand Up @@ -188,7 +188,7 @@ def sessions(self, capability_path: str | None = None) -> Generator[Session, Non
class LspOpenLocationCommand(LspWindowCommand):
"""A command to be used by third-party ST packages that need to open an URI with some abstract scheme."""

def run(
async def run(
self,
location: Location | LocationLink,
session_name: str | None = None,
Expand All @@ -202,20 +202,15 @@ def run(
flags |= sublime.NewFileFlags.ADD_TO_SELECTION | sublime.NewFileFlags.SEMI_TRANSIENT | sublime.NewFileFlags.CLEAR_TO_RIGHT # noqa: E501
elif 'shift' in modifier_keys:
flags |= sublime.NewFileFlags.ADD_TO_SELECTION | sublime.NewFileFlags.SEMI_TRANSIENT
run_coroutine(self._run(location, session_name, flags, group))

def want_event(self) -> bool:
return True

async def _run(
self, location: Location | LocationLink, session_name: str | None, flags: sublime.NewFileFlags, group: int
) -> None:
if session := self.session_by_name(session_name) if session_name else self.session():
if not await session.open_location(location, flags, group):
uri, _ = get_uri_and_position_from_location(location)
message = f"Failed to open {uri}"
sublime.status_message(message)

def want_event(self) -> bool:
return True


class LspRestartServerCommand(LspTextCommand):

Expand All @@ -241,12 +236,9 @@ def restart_server(self, wm: WindowManager, index: int) -> None:
run_coroutine(wm.restart_sessions([self._config_names[index]]))


class LspCheckApplicableCommand(sublime_plugin.TextCommand):

def run(self, edit: sublime.Edit, session_name: str) -> None:
run_coroutine(self._run(session_name))
class LspCheckApplicableCommand(sublime_aio.ViewCommand):

async def _run(self, session_name: str) -> None:
async def run(self, session_name: str) -> None:
if wm := windows.lookup(self.view.window()):
await wm.recheck_is_applicable(self.view, session_name)

Expand Down
7 changes: 1 addition & 6 deletions plugin/document_link.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from __future__ import annotations

from .core.aio import run_coroutine
from .core.logging import exception_log
from .core.open import open_file_uri
from .core.open import open_in_browser
Expand All @@ -17,7 +16,6 @@
if TYPE_CHECKING:
from ..protocol import URI
from .core.sessions import Session
import sublime


class LspOpenLinkCommand(LspTextCommand):
Expand All @@ -35,10 +33,7 @@ def is_enabled(self, event: dict | None = None, point: int | None = None) -> boo
return False
return True

def run(self, edit: sublime.Edit, event: dict | None = None, point: int | None = None) -> None:
run_coroutine(self._run(event, point))

async def _run(self, event: dict | None, point: int | None) -> None:
async def run(self, event: dict | None = None, point: int | None = None) -> None:
if (position := get_position(self.view, event, point)) is not None:
if session := self.best_session(self.capability, position):
response = await session.request(
Expand Down
8 changes: 1 addition & 7 deletions plugin/edit.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from __future__ import annotations

from .core.aio import run_coroutine
from .core.constants import ChangeEventAction
from .core.edit import is_snippet_text_edit
from .core.edit import parse_lsp_position
Expand Down Expand Up @@ -93,12 +92,7 @@ def temporary_setting(settings: sublime.Settings, key: str, val: Any) -> Generat

class LspApplyWorkspaceEditCommand(LspWindowCommand):

def run(
self, session_name: str, edit: WorkspaceEdit, label: str | None = None, is_refactoring: bool = False
) -> None:
run_coroutine(self._run(session_name, edit, label, is_refactoring))

async def _run(
async def run(
self, session_name: str, edit: WorkspaceEdit, label: str | None = None, is_refactoring: bool = False
) -> None:
if session := self.session_by_name(session_name):
Expand Down
19 changes: 6 additions & 13 deletions plugin/execute_command.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
from __future__ import annotations

from .core.aio import run_coroutine
from .core.logging import debug
from .core.protocol import Error
from .core.protocol import LSPAny
from .core.registry import LspTextCommand
from .core.views import first_selection_region
from .core.views import offset_to_point
Expand All @@ -18,14 +16,12 @@

if TYPE_CHECKING:
from ..protocol import ExecuteCommandParams
from .core.sessions import Session


class LspExecuteCommand(LspTextCommand):
"""Helper command for triggering workspace/executeCommand requests."""

def run(self,
edit: sublime.Edit,
async def run(self,
command_name: str | None = None,
command_args: list[Any] | None = None,
session_name: str | None = None,
Expand All @@ -35,14 +31,11 @@ def run(self,
params: ExecuteCommandParams = {"command": command_name}
if command_args:
params["arguments"] = self._expand_variables(command_args)
run_coroutine(self._run(session, command_name, params))

async def _run(self, session: Session, command_name: str, params: ExecuteCommandParams) -> None:
result: LSPAny | Error = await session.run_command(params, progress=True, view=self.view)
if isinstance(result, Error):
self.handle_error_async(result, command_name)
else:
self.handle_success_async(result, command_name)
result = await session.run_command(params, progress=True, view=self.view)
if isinstance(result, Error):
self.handle_error_async(result, command_name)
else:
self.handle_success_async(result, command_name)

def handle_success_async(self, result: Any, command_name: str) -> None:
"""
Expand Down
5 changes: 1 addition & 4 deletions plugin/formatting.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,10 +241,7 @@ def is_enabled(self, event: dict | None = None, point: int | None = None) -> boo
return True
return False

def run(self, edit: sublime.Edit, event: dict | None = None) -> None:
run_coroutine(self._run())

async def _run(self) -> None:
async def run(self, event: dict | None = None) -> None:
if (potential_error := await format_selection(self.get_listener())) and isinstance(potential_error, Error):
sublime.status_message(f'Formatting error: {potential_error}')

Expand Down
20 changes: 9 additions & 11 deletions plugin/inlay_hint.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from __future__ import annotations

from .core.aio import run_coroutine
from .core.constants import RequestFlags
from .core.constants import ST_VERSION
from .core.css import css
Expand Down Expand Up @@ -42,10 +41,7 @@ def _get_default_value() -> bool:
return sublime.load_settings('LSP.sublime-settings').get('show_inlay_hints')
return False

def run(self, enable: bool | None = None) -> None:
run_coroutine(self._run(enable))

async def _run(self, enable: bool | None) -> None:
async def run(self, enable: bool | None = None) -> None:
window_settings = self.window.settings()
if not isinstance(enable, bool):
enable = not bool(window_settings.get('lsp_show_inlay_hints'))
Expand All @@ -68,12 +64,14 @@ def is_checked(self) -> bool:
class LspInlayHintClickCommand(LspTextCommand):
capability = 'inlayHintProvider'

def run(self, _edit: sublime.Edit, session_name: str, inlay_hint: InlayHint, phantom_uuid: str,
event: dict | None = None, label_part: InlayHintLabelPart | None = None) -> None:
run_coroutine(self._run(session_name, inlay_hint, phantom_uuid, label_part))

async def _run(self, session_name: str, inlay_hint: InlayHint, phantom_uuid: str,
label_part: InlayHintLabelPart | None = None) -> None:
async def run(
self,
session_name: str,
inlay_hint: InlayHint,
phantom_uuid: str,
event: dict | None = None,
label_part: InlayHintLabelPart | None = None,
) -> None:
# Insert textEdits for the given inlay hint.
# If a InlayHintLabelPart was clicked, label_part will be passed as an argument to the LspInlayHintClickCommand
# and InlayHintLabelPart.command will be executed.
Expand Down
6 changes: 1 addition & 5 deletions plugin/lsp_task.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from __future__ import annotations

from .core.aio import run_coroutine
from .core.logging import exception_log
from .core.registry import LspTextCommand
from .core.settings import userprefs
Expand Down Expand Up @@ -57,10 +56,7 @@ async def on_tasks_completed(self, **kwargs: dict[str, Any]) -> None:
"""Override this to execute code when all tasks are completed."""

@override
def run(self, edit: sublime.Edit, **kwargs: dict[str, Any]) -> None:
run_coroutine(self._run(**kwargs))

async def _run(self, **kwargs: dict[str, Any]) -> None:
async def run(self, **kwargs: dict[str, Any]) -> None:
if self._tasks_runner:
# Request to cancel the task.
if self._tasks_runner.cancel():
Expand Down
6 changes: 1 addition & 5 deletions plugin/symbols.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from ..protocol import SymbolKind
from ..protocol import SymbolTag
from ..protocol import WorkspaceSymbol
from .core.aio import run_coroutine
from .core.constants import SYMBOL_KINDS
from .core.input_handlers import DynamicListInputHandler
from .core.input_handlers import PreselectedListInputHandler
Expand Down Expand Up @@ -328,10 +327,7 @@ class LspWorkspaceSymbolsCommand(LspWindowCommand):

capability = 'workspaceSymbolProvider'

def run(self, symbol: WorkspaceSymbolValue) -> None:
run_coroutine(self._run(symbol))

async def _run(self, symbol: WorkspaceSymbolValue) -> None:
async def run(self, symbol: WorkspaceSymbolValue) -> None:
session_name = symbol['session']
if session := self.session_by_name(session_name):
if location := symbol.get('location'):
Expand Down
Loading