add xdg module and implement xdg data storage, default java data directory to ours, begin implementing auto-download

This commit is contained in:
Adrian Kuschelyagi Malacoda 2020-11-11 16:23:58 -06:00
parent 7a346a9185
commit f144963c32
3 changed files with 29 additions and 7 deletions

View File

@ -1,7 +1,7 @@
import os import os
import sys import sys
from .lsp import LspServer, command from .lsp import LspServer, command, get_data_home
FILE_URI = "file://" FILE_URI = "file://"
@ -9,12 +9,14 @@ def locate_product_directory (jdt_ls_path):
return os.path.join(jdt_ls_path, "org.eclipse.jdt.ls.product/target/repository") return os.path.join(jdt_ls_path, "org.eclipse.jdt.ls.product/target/repository")
def locate_launcher_jar (jdt_ls_path): def locate_launcher_jar (jdt_ls_path):
jdt_ls_product_directory = locate_product_directory(jdt_ls_path) plugins_directory = os.path.join(jdt_ls_path, "plugins")
plugins_directory = os.path.join(jdt_ls_product_directory, "plugins")
return os.path.join(plugins_directory, [jar for jar in os.listdir(plugins_directory) if jar.startswith("org.eclipse.equinox.launcher_")][0]) return os.path.join(plugins_directory, [jar for jar in os.listdir(plugins_directory) if jar.startswith("org.eclipse.equinox.launcher_")][0])
def locate_launcher_configuration (jdt_ls_path): def locate_launcher_configuration (jdt_ls_path):
return os.path.join(locate_product_directory(jdt_ls_path), "config_linux") return os.path.join(jdt_ls_path, "config_linux")
def download_jdt_ls (destination):
raise Exception("download_jdt_ls not implemented")
# TODO # TODO
def locate_lombok (): def locate_lombok ():
@ -22,13 +24,25 @@ def locate_lombok ():
class Java(LspServer): class Java(LspServer):
def __init__ (self, arguments): def __init__ (self, arguments):
self.path = arguments[0] self.path = arguments[0] if arguments else None
if self.path is None or not os.path.exists(self.path):
self.path = download_jdt_ls(os.path.join(get_data_home(), "java", "jdt.ls"))
else:
self.path = locate_product_directory(self.path)
command = ["java"] command = ["java"]
if "--enable-lombok" in arguments: if "--enable-lombok" in arguments:
arguments.remove("--enable-lombok") arguments.remove("--enable-lombok")
command.append(f"-javaagent:{locate_lombok()}") command.append(f"-javaagent:{locate_lombok()}")
data_directory = None
if "--data" in arguments:
data_directory = arguments.pop(arguments.index("--data") + 1)
arguments.remove("--data")
else:
data_directory = os.path.join(get_data_home(), "java", "data")
command = command + [ command = command + [
"-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=1044", "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=1044",
"-Declipse.application=org.eclipse.jdt.ls.core.id1", "-Declipse.application=org.eclipse.jdt.ls.core.id1",
@ -38,7 +52,7 @@ class Java(LspServer):
"-Xmx1G", "-Xmx1G",
"-jar", locate_launcher_jar(self.path), "-jar", locate_launcher_jar(self.path),
"-configuration", locate_launcher_configuration(self.path), "-configuration", locate_launcher_configuration(self.path),
"-data", os.path.join(self.path, "data"), "-data", data_directory,
"--add-modules=ALL-SYSTEM", "--add-modules=ALL-SYSTEM",
"--add-opens", "java.base/java.util=ALL-UNNAMED", "--add-opens", "java.base/java.util=ALL-UNNAMED",
"--add-opens", "java.base/java.lang=ALL-UNNAMED" "--add-opens", "java.base/java.lang=ALL-UNNAMED"

View File

@ -6,6 +6,8 @@ import json
from subprocess import run, Popen, PIPE from subprocess import run, Popen, PIPE
from threading import Thread from threading import Thread
from xdg import xdg_data_home
CONTENT_LENGTH = "Content-Length: " CONTENT_LENGTH = "Content-Length: "
def process_messages (source, sink, handlers, log): def process_messages (source, sink, handlers, log):
@ -75,6 +77,12 @@ def command (name):
return method("workspace/executeCommand")(handle_command) return method("workspace/executeCommand")(handle_command)
return command_handler return command_handler
def get_data_home ():
data_directory = os.path.join(xdg_data_home(), "lsp-proxy")
if not os.path.exists(data_directory):
os.makedirs(data_directory)
return data_directory
class LspServer: class LspServer:
def __init__ (self, command): def __init__ (self, command):
self.command = command self.command = command

View File

@ -8,7 +8,7 @@ setup(
description='lsp-proxy is a proxy for language servers.', description='lsp-proxy is a proxy for language servers.',
author='Adrian Malacoda', author='Adrian Malacoda',
packages=['lsp_proxy'], packages=['lsp_proxy'],
install_requires=[], install_requires=['xdg'],
entry_points={ entry_points={
'console_scripts': [ 'console_scripts': [
'lsp-proxy = lsp_proxy:main' 'lsp-proxy = lsp_proxy:main'