From 1ccb8718d18fdcf25a60ea55bd8cc70f4f278176 Mon Sep 17 00:00:00 2001 From: Raoul Wols Date: Sun, 4 Jul 2021 11:27:40 +0200 Subject: [PATCH] Handle jdt URIs with java/classFileContents request --- plugin.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/plugin.py b/plugin.py index 28f9d84..656c625 100644 --- a/plugin.py +++ b/plugin.py @@ -4,8 +4,7 @@ from LSP.plugin import unregister_plugin from LSP.plugin import Request 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,6 +17,10 @@ # 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.protocol import DocumentUri +from LSP.plugin.core.protocol import ExecuteCommandParams +from LSP.plugin.core.protocol import Notification +from LSP.plugin.core.registry import LspTextCommand from LSP.plugin.core.views import location_to_encoded_filename, text_document_identifier @@ -156,6 +159,20 @@ 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 + view = session.window.active_view() + session.send_request_async( + Request("java/classFileContents", text_document_identifier(uri), view, 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: