Compare commits
5 Commits
91236b728b
...
master
Author | SHA1 | Date | |
---|---|---|---|
198f28d994 | |||
905e034137 | |||
8792bd45fc | |||
bb8bd19f64 | |||
9af1594e32 |
@@ -8,7 +8,7 @@ from .lsp import LspServer, command, get_data_home
|
|||||||
|
|
||||||
FILE_URI = "file://"
|
FILE_URI = "file://"
|
||||||
|
|
||||||
VERSION = "0.64.0"
|
VERSION = "1.3.0"
|
||||||
DOWNLOADS_URI = "http://download.eclipse.org/jdtls/milestones/{version}/{file}"
|
DOWNLOADS_URI = "http://download.eclipse.org/jdtls/milestones/{version}/{file}"
|
||||||
LATEST = "latest.txt"
|
LATEST = "latest.txt"
|
||||||
|
|
||||||
@@ -28,7 +28,7 @@ def locate_launcher_configuration (jdt_ls_path):
|
|||||||
def log (message, *args, **kwargs):
|
def log (message, *args, **kwargs):
|
||||||
print(message.format(*args, **kwargs), file=sys.stderr)
|
print(message.format(*args, **kwargs), file=sys.stderr)
|
||||||
|
|
||||||
def download_jdt_ls (destination):
|
def download_jdt_ls (version, destination):
|
||||||
if not os.path.isdir(destination):
|
if not os.path.isdir(destination):
|
||||||
os.makedirs(destination)
|
os.makedirs(destination)
|
||||||
|
|
||||||
@@ -40,12 +40,12 @@ def download_jdt_ls (destination):
|
|||||||
log("Currently downloaded version is {version}:", version=current_version)
|
log("Currently downloaded version is {version}:", version=current_version)
|
||||||
|
|
||||||
latest_version = None
|
latest_version = None
|
||||||
with request.urlopen(DOWNLOADS_URI.format(version=VERSION, file=LATEST)) as f:
|
with request.urlopen(DOWNLOADS_URI.format(version=version, file=LATEST)) as f:
|
||||||
latest_version = f.read().decode().strip()
|
latest_version = f.read().decode().strip()
|
||||||
log("Latest available version is {version}:", version=latest_version)
|
log("Latest available version is {version}:", version=latest_version)
|
||||||
|
|
||||||
if not latest_version == current_version:
|
if not latest_version == current_version:
|
||||||
latest_uri = DOWNLOADS_URI.format(version=VERSION, file=latest_version)
|
latest_uri = DOWNLOADS_URI.format(version=version, file=latest_version)
|
||||||
log("Downloading latest version from: {uri}:", uri=latest_uri)
|
log("Downloading latest version from: {uri}:", uri=latest_uri)
|
||||||
with request.urlopen(latest_uri) as f:
|
with request.urlopen(latest_uri) as f:
|
||||||
with tarfile.open(fileobj=f, mode="r|gz") as tar:
|
with tarfile.open(fileobj=f, mode="r|gz") as tar:
|
||||||
@@ -61,12 +61,25 @@ def download_jdt_ls (destination):
|
|||||||
def locate_lombok ():
|
def locate_lombok ():
|
||||||
return os.path.join(os.environ['HOME'], ".m2/repository/org/projectlombok/lombok/1.18.16/lombok-1.18.16.jar")
|
return os.path.join(os.environ['HOME'], ".m2/repository/org/projectlombok/lombok/1.18.16/lombok-1.18.16.jar")
|
||||||
|
|
||||||
|
def get_argument (arguments, arg_name):
|
||||||
|
if not arg_name in args:
|
||||||
|
return
|
||||||
|
|
||||||
|
value = arguments.pop(arguments.index(arg_name) + 1)
|
||||||
|
arguments.remove(arg_name)
|
||||||
|
return value
|
||||||
|
|
||||||
class Java(LspServer):
|
class Java(LspServer):
|
||||||
def __init__ (self, arguments):
|
def __init__ (self, arguments):
|
||||||
self.path = arguments[0] if arguments else None
|
self.path = arguments[0] if arguments else None
|
||||||
|
|
||||||
if self.path is None or not os.path.exists(self.path):
|
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"))
|
version = VERSION
|
||||||
|
|
||||||
|
if "--version" in arguments:
|
||||||
|
version = get_argument(arguments, "--version")
|
||||||
|
|
||||||
|
self.path = download_jdt_ls(version, os.path.join(get_data_home(), "java", "jdt.ls", version))
|
||||||
else:
|
else:
|
||||||
self.path = locate_product_directory(self.path)
|
self.path = locate_product_directory(self.path)
|
||||||
|
|
||||||
@@ -77,8 +90,7 @@ class Java(LspServer):
|
|||||||
|
|
||||||
data_directory = None
|
data_directory = None
|
||||||
if "--data" in arguments:
|
if "--data" in arguments:
|
||||||
data_directory = arguments.pop(arguments.index("--data") + 1)
|
data_directory = get_argument(arguments, "--data")
|
||||||
arguments.remove("--data")
|
|
||||||
else:
|
else:
|
||||||
data_directory = os.path.join(get_data_home(), "java", "data")
|
data_directory = os.path.join(get_data_home(), "java", "data")
|
||||||
|
|
||||||
|
@@ -10,34 +10,40 @@ from xdg import xdg_data_home
|
|||||||
|
|
||||||
CONTENT_LENGTH = "Content-Length: "
|
CONTENT_LENGTH = "Content-Length: "
|
||||||
|
|
||||||
def process_messages (source, sink, handlers, log):
|
def log (message, *args, **kwargs):
|
||||||
print("start message handler", file=log)
|
print(message.format(*args, **kwargs), file=sys.stderr)
|
||||||
|
|
||||||
|
def process_messages (label, source, sink, handlers):
|
||||||
|
log(f"[{label}] start process_messages")
|
||||||
while True:
|
while True:
|
||||||
line = source.readline()
|
line = source.readline()
|
||||||
if not line:
|
if not line:
|
||||||
break
|
break
|
||||||
|
|
||||||
line = line.decode()
|
try:
|
||||||
if line.startswith(CONTENT_LENGTH):
|
line = line.decode()
|
||||||
content_length = int(line[len(CONTENT_LENGTH):].strip())
|
if line.startswith(CONTENT_LENGTH):
|
||||||
print(f">> ce: [{content_length}]", file=log)
|
content_length = int(line[len(CONTENT_LENGTH):].strip())
|
||||||
|
log(f">> [{label}] ce: [{content_length}]")
|
||||||
|
|
||||||
source.readline()
|
source.readline()
|
||||||
|
|
||||||
payload = source.read(content_length).decode()
|
payload = source.read(content_length).decode()
|
||||||
print(f">> payload: [{payload}]", file=log)
|
log(">> [{label}] payload: [{payload}]", label=label, payload=payload)
|
||||||
|
|
||||||
if handlers:
|
if handlers:
|
||||||
payload_parsed = json.loads(payload)
|
payload_parsed = json.loads(payload)
|
||||||
for handler in handlers:
|
for handler in handlers:
|
||||||
try:
|
try:
|
||||||
handler(payload_parsed)
|
handler(payload_parsed)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Error from handler: {e}", file=log)
|
log(f"Error from handler: {e}")
|
||||||
|
|
||||||
transmit_payload(payload, sink)
|
transmit_payload(payload, sink)
|
||||||
|
except Exception as e:
|
||||||
|
log(f"[{label}] Error decoding input: {e}")
|
||||||
|
|
||||||
print("stop message handler", file=log)
|
log(f"[{label}] exit process_messages")
|
||||||
|
|
||||||
def transmit_payload (payload, sink):
|
def transmit_payload (payload, sink):
|
||||||
if isinstance(payload, dict):
|
if isinstance(payload, dict):
|
||||||
@@ -91,13 +97,16 @@ class LspServer:
|
|||||||
def start (self):
|
def start (self):
|
||||||
handlers = self.handlers + handler.get_handlers(self)
|
handlers = self.handlers + handler.get_handlers(self)
|
||||||
|
|
||||||
|
log("starting lsp process: {}", " ".join(self.command))
|
||||||
with Popen(self.command, stdin=PIPE, stdout=PIPE) as process:
|
with Popen(self.command, stdin=PIPE, stdout=PIPE) as process:
|
||||||
self.process = process
|
self.process = process
|
||||||
|
|
||||||
self.process_reader = Thread(target=process_messages, args=[process.stdout, sys.stdout.buffer, handlers, sys.stderr])
|
self.process_reader = Thread(target=process_messages, args=["process.stdout -> sys.stdout reader", process.stdout, sys.stdout.buffer, handlers])
|
||||||
self.process_reader.start()
|
self.process_reader.start()
|
||||||
|
|
||||||
process_messages(sys.stdin.buffer, process.stdin, handlers, sys.stderr)
|
process_messages("sys.stdin -> process.stdin", sys.stdin.buffer, process.stdin, handlers)
|
||||||
|
|
||||||
|
log("lsp process ended")
|
||||||
|
|
||||||
def start2 (self):
|
def start2 (self):
|
||||||
run(self.command)
|
run(self.command)
|
||||||
|
Reference in New Issue
Block a user