Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Java adapter #106

Merged
merged 22 commits into from
Sep 18, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions modules/adapters/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from .go import Go
from .php import PHP
from .python import Python
from .java import Java
from .ruby import Ruby

from .node import Node
Expand Down
108 changes: 108 additions & 0 deletions modules/adapters/java.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
# Basic idea here is...
# When installing the adapter it would add the com.microsoft.java.debug.plugin-0.30.0.jar as a plugin to lsp-jdts
# When starting the adapter it will ask lsp-jdts to start the adapter by calling the command lsp_jdts_start_debugging exposed by lsp-jdts
# lsp-jdts will then call debugger_lsp_jdts_start_debugging_response after it has started the adapter
# Debugger will then connect to the given port and start debugging

# see https://github.com/Microsoft/java-debug for how the lsp side needs to be setup it looks something like....
# add the jar to the init options
# "initializationOptions": {
# "bundles": [
# "path/to/microsoft/java-debug/com.microsoft.java.debug.plugin/target/com.microsoft.java.debug.plugin-<version>.jar"
# ]
# }
# command to start the debug session
# {
# "command": "vscode.java.startDebugSession"
# }

from ..typecheck import *
from .. import core
from .import adapter

import sublime
import sublime_plugin
import os

# window.run_command('debugger_lsp_jdtls_start_debugging_response', {'id': 1, 'port': 12345, 'error': None})
class DebuggerLspJdtlsStartDebuggingResponseCommand(sublime_plugin.WindowCommand):
def run(self, id: int, port: Optional[int], error: Optional[str]):
future_port = Java.pending_adapters.get(id)
if not future_port:
print("Hmm... unable to find a future port for this id")
return

if error:
future_port.set_exception(core.Error(error))
return

if not port:
future_port.set_exception(core.Error('Expected port or error from lsp-jdts'))
return

future_port.set_result(port)


class Java(adapter.AdapterConfiguration):
pending_adapters: Dict[int, core.future] = {}
pending_adapters_current_id = 0

@property
def type(self): return 'java'

async def start(self, log, configuration):
# probably need to add some sort of timeout
# probably need to ensure lsp_jdts is installed
# probably need to ensure lsp_jdts has the plugin jar patched in
future_port = core.create_future()

id = Java.pending_adapters_current_id
Java.pending_adapters_current_id += 1
Java.pending_adapters[id] = future_port

# ask lsp_jdts to start the debug adapter
# lsp_jdts will call debugger_lsp_jdts_start_debugging_response with the id it was given and a port to connect to the adapter with or an error
# note: the active window might not match the debugger window but generally will... probably need a way to get the actual window.
sublime.active_window().run_command('lsp_jdtls_start_debug_session', {
'id': id
})

port = await future_port
return adapter.SocketTransport(log, 'localhost', port)

async def install(self, log):
url = 'https://marketplace.visualstudio.com/_apis/public/gallery/publishers/vscjava/vsextensions/vscode-java-debug/latest/vspackage'
await adapter.vscode.install(self.type, url, log)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@daveleroy I'm fairly certain this isn't allowed, unfortunately...

https://cdn.vsassets.io/v/M146_20190123.39/_content/Microsoft-Visual-Studio-Marketplace-Terms-of-Use.pdf

Offerings are intended for use only with Visual Studio Products and Services and you may only install and use Marketplace Offerings with Visual Studio Products and Services.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case its actually possible to compile the jar and ship it with Debugger (or download it elsewhere.) The plugin itself is under Eclipse Public License - v 1.0. See https://github.com/microsoft/java-debug/blob/master/LICENSE.txt

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You cannot download or in any way install software provided through the “marketplace” if it’s not a “visual studio product”. The license you link to does allow one to compile/use the software. But obtaining that software cannot be done through the marketplace (or, risk a cease and desist I guess).

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If that debugger jar is somewhere else on the internet available for download and the terms and conditions of that source allow it, then we can use that.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you think VSCodium has its own marketplace?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We would want the full extension https://github.com/Microsoft/vscode-java-debug which includes all the snippets and a schema for the configurations.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Incidentally, open-vsx.org is hosted by the eclipse foundation https://www.eclipse.org/community/eclipse_newsletter/2020/march/1.php

Copy link

@rwols rwols Mar 8, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, I think you can also just fetch the .vsix file from https://github.com/microsoft/vscode-java-debug/releases/ and extract it as a zip.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like you can in this case. Other adapters do not add the vscode package to their releases so those will probably need to be changed.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. What a coincidence that the assets are not in a GitHub release... ;)


install_path = adapter.vscode.install_path(self.type)

# probably need to just look through this folder? this has a version #
plugin_jar_path = os.path.join(f'{install_path}/extension/server', os.listdir(f'{install_path}/extension/server')[0])

settings = sublime.load_settings("LSP-jdtls.sublime-settings")
init_options = settings.get("initializationOptions", {})
bundles = init_options.get("bundles", [])

if plugin_jar_path not in bundles:
# Cleanup
for jar in bundles:
if "com.microsoft.java.debug.plugin" in jar:
bundles.remove(jar)
break
bundles += [plugin_jar_path]
init_options["bundles"] = bundles
settings.set("initializationOptions", init_options)
sublime.save_settings("LSP-jdtls.sublime-settings")

@property
def installed_version(self) -> Optional[str]:
return adapter.vscode.installed_version(self.type)

@property
def configuration_snippets(self) -> Optional[list]:
return adapter.vscode.configuration_snippets(self.type)

@property
def configuration_schema(self) -> Optional[dict]:
return adapter.vscode.configuration_schema(self.type)

1 change: 1 addition & 0 deletions start.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

# import all the commands so that sublime sees them
from .modules.commands import DebuggerCommand, DebuggerExecCommand
from .modules.adapters.java import DebuggerLspJdtlsStartDebuggingResponseCommand

from .modules.ui.input import DebuggerInputCommand
from .modules.core.sublime import DebuggerAsyncTextCommand, DebuggerEventsListener
Expand Down