Skip to content

Make LspTextCommand inherit from sublime_aio.ViewCommand - #3004

Draft
rwols wants to merge 1 commit into
feat/asynciofrom
feat/sublime-aio-view-command
Draft

Make LspTextCommand inherit from sublime_aio.ViewCommand#3004
rwols wants to merge 1 commit into
feat/asynciofrom
feat/sublime-aio-view-command

Conversation

@rwols

@rwols rwols commented Aug 2, 2026

Copy link
Copy Markdown
Member

This PR makes LspTextCommand inherit from sublime_aio.ViewCommand. The benefit is that this ViewCommand has special handling for async def run() methods. So, you can write directly such a method, without having to use the somewhat cumbersome pattern of defining an async def _run() method and invoking that one, via run_coroutine, in the regular run() method. So:

# OLD
FooBarCommand(LspTextcommand):
    def run(self, edit: sublime.Edit, foo: str, bar: str) -> None:
        run_coroutine(self._run(foo, bar))

    async def _run(self, foo: str, bar: str) -> None:
        ...
# NEW
FooBarCommand(LspTextCommand):
    async def run(self, foo: str, bar: str) -> None:
        ...

However, I see TypeErrors being thrown for old LspTextCommand-derived classes that don't have an async run() method. This PR is blocked on that: packagecontrol/sublime_aio#34

@jwortmann

jwortmann commented Aug 2, 2026

Copy link
Copy Markdown
Member

I was thinking about whether we could make a command wrapper that would allow to report back a result when (asynchronically) running a command. Then we could use that in a way like

result = await run_command(view, 'lsp_some_command', {})

instead of the regular ST API call (which always returns None)

view.run_command('lsp_some_command', {})

This could be useful for example when applying TextEdits or a WorkspaceEdit (e.g. LspApplyWorkspaceEditCommand), where it would be nice to know whether an operation failed, or to get back the number of applied edits and edited files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants