sublimehq / sublime_text

Issue tracker for Sublime Text
https://www.sublimetext.com
801 stars 36 forks source link

[ST4] Opening URIs #3989

Open rwols opened 3 years ago

rwols commented 3 years ago

Problem description

Development is moving more and more towards web-based tooling. Sublime is lacking in this area.

Preferred solution

A new async method for the sublime.Window class:


async def open_uri(
    uri: str,
    flags: int = 0,
    group: int = -1
) -> Optional[View]
    ...

It should have the following behavior:

The return type should be an Optional[View] if the URI can be represented as a single file. It may be None because it might have been closed/cancelled by the user while opening it.

Alternatives

N/A

Additional Information (optional)

https://github.com/sublimelsp/LSP/issues/1605

The Deno language server has the "goto definition" capability. When the user wants to jump to the definition of a module that is not in the workspace, it will report back a resource on the web. The editor is expected to open that web resource.

EDIT: Contrary to what you might expect, Deno doesn't use http:// schemes but rather deno:// schemes (see below).

rwols commented 3 years ago

Preferred solution continued

If the scheme of the URI is not file, res, http, https or buffer, then ST should look for a "view provider", much like how it searches for a "key binding handler" with on_query_context. There should be a new async callback that can signal to ST that it can "handle" a certain scheme. So maybe a new callback for sublime_plugin.EventListener:

async def on_query_uri(
    self,
    window: sublime.Window,
    uri: str
) -> Optional[Tuple[str, str, Optional[str]]]:
    ...

If you define this method in a plugin, then you must return a tuple of three elements:

  1. The first element is the content of the new view
  2. The second element is the syntax to apply to the new view
  3. The third optional element is a file-system backed file, in case the user wants to save it, and for interoperability with view.file_name(), although I guess this should be None.

If you don't know how to handle the provided URI then you must return None.

This would allow plugins to extend the behavior of opening URIs for custom schemes.

For instance, the Deno language server uses a deno scheme. This scheme requires custom handling to fetch the remote content (and again, it must all be asynchronous).

rwols commented 3 years ago

Of course I didn't think of this myself. VSCode already has this mechanism.

rwols commented 3 years ago

I'm learning this idea has consequences for various other features:

Nevertheless I still think this would be a nice feature to have as a basis for, for instance, remote SSH file viewing, or translating paths for inspecting files in a docker container.

rwols commented 3 years ago

Another use case is resolving URIs with a jdt scheme for Debugger + Eclipse language server integration: https://github.com/daveleroy/sublime_debugger/pull/106#issuecomment-795747917