Skip to content

Commit

Permalink
Handle jdt URIs with java/classFileContents request
Browse files Browse the repository at this point in the history
  • Loading branch information
rwols committed Jul 4, 2021
1 parent 85d3c30 commit 1ccb871
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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


Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 1ccb871

Please sign in to comment.