diff --git a/LSP-jdtls.sublime-settings b/LSP-jdtls.sublime-settings index 805e883..ef78f3e 100644 --- a/LSP-jdtls.sublime-settings +++ b/LSP-jdtls.sublime-settings @@ -1,6 +1,13 @@ { // We start this language server when we open java files. "selector": "source.java", + // Declares what URI schemes this server attaches to. + "schemes": [ + // regular files on disk + "file", + // opened by a DAP-compatible debugger + "jdt" + ], // The startup command. "command": [ "${java_executable}", diff --git a/plugin.py b/plugin.py index 28f9d84..77951c9 100644 --- a/plugin.py +++ b/plugin.py @@ -3,9 +3,9 @@ from LSP.plugin import Session from LSP.plugin import unregister_plugin from LSP.plugin import Request +from LSP.plugin import Notification from LSP.plugin.core.typing import Optional, Any, List, Dict, Mapping, Callable -from LSP.plugin.core.registry import LspTextCommand -from LSP.plugin.core.protocol import ExecuteCommandParams, Notification + import os import sublime from urllib.request import urlopen @@ -18,7 +18,11 @@ # TODO: Not part of the public API :( from LSP.plugin.core.edit import apply_workspace_edit from LSP.plugin.core.edit import parse_workspace_edit -from LSP.plugin.core.views import location_to_encoded_filename, text_document_identifier +from LSP.plugin.core.protocol import DocumentUri +from LSP.plugin.core.protocol import ExecuteCommandParams +from LSP.plugin.core.registry import LspTextCommand +from LSP.plugin.core.views import location_to_encoded_filename +from LSP.plugin.core.views import text_document_identifier DOWNLOAD_URL = "http://download.eclipse.org/jdtls/snapshots" @@ -156,6 +160,22 @@ def install_or_update(cls) -> None: if os.path.isdir(absdir): shutil.move(absdir, serverdir(cls.storage_subpath())) + def on_open_uri_async(self, uri: DocumentUri, callback: Callable[[str, str, str], None]) -> bool: + if not uri.startswith("jdt:"): + return False + session = self.weaksession() + if not session: + return False + # https://github.com/redhat-developer/vscode-java/blob/9f32875a67352487f5c414bb7fef04c9b00af89d/src/protocol.ts#L105-L107 + # https://github.com/redhat-developer/vscode-java/blob/9f32875a67352487f5c414bb7fef04c9b00af89d/src/providerDispatcher.ts#L61-L76 + # https://github.com/redhat-developer/vscode-java/blob/9f32875a67352487f5c414bb7fef04c9b00af89d/src/providerDispatcher.ts#L27-L28 + session.send_request_async( + Request("java/classFileContents", text_document_identifier(uri), progress=True), + lambda resp: callback(uri, resp, "Packages/Java/Java.sublime-syntax"), + lambda err: callback("ERROR", str(err), "Packages/Text/Plain text.tmLanguage") + ) + return True + def on_pre_server_command(self, command: Mapping[str, Any], done: Callable[[], None]) -> bool: session = self.weaksession() if not session: