-
Notifications
You must be signed in to change notification settings - Fork 44
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
Java adapter #106
Changes from 4 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
75472ef
Initial java configuration
daveleroy ca1cad6
Implement java adapter
LDAP 5c15016
Merge branch 'master' into Implement-java-adapter
LDAP 2775766
Remove debug output
LDAP d131bf1
Fix Exception on jdtls server
LDAP 99d72ec
Resolve classPaths and mainClass
LDAP b126fc4
Show errors
LDAP c482ce7
Fix modulePaths and incompatible class version
LDAP a0fc030
Allow failure when resolving mainClass/classPaths if set in configura…
LDAP 4805618
Fix for debug-java out-of-specification response
LDAP a0d9d2c
Merge branch 'master' into java-adapter
LDAP 846c839
Update Java adapter to new API
LDAP 43f91c2
Merge branch 'master' into java-adapter
LDAP 27cdc87
Merge branch 'master' into java-adapter
LDAP dbe7182
Update Java adapter to new API
LDAP ef9bbec
Java: Move LSP config logic into debugger
LDAP aac31cb
Java: Move source navigation special case to adapter
LDAP 71fabb5
Update README
LDAP 83650c2
Java: Format
LDAP 85f3cfd
Merge branch 'master' into java-adapter
LDAP fe97c7e
Java: Adapt to new installer interface
LDAP 43c28ba
Java: Add jdtls connection timeout
LDAP File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
|
||
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) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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... ;)