Compare commits

..

No commits in common. "bb8bd19f64e894c2bb533bb86cf2233ce719c031" and "91236b728be66405d2987e1c5b7165acc2c43b60" have entirely different histories.

2 changed files with 25 additions and 34 deletions

View File

@ -8,7 +8,7 @@ from .lsp import LspServer, command, get_data_home
FILE_URI = "file://"
VERSION = "1.1.1"
VERSION = "0.64.0"
DOWNLOADS_URI = "http://download.eclipse.org/jdtls/milestones/{version}/{file}"
LATEST = "latest.txt"

View File

@ -10,40 +10,34 @@ from xdg import xdg_data_home
CONTENT_LENGTH = "Content-Length: "
def log (message, *args, **kwargs):
print(message.format(*args, **kwargs), file=sys.stderr)
def process_messages (label, source, sink, handlers):
log(f"[{label}] start process_messages")
def process_messages (source, sink, handlers, log):
print("start message handler", file=log)
while True:
line = source.readline()
if not line:
break
try:
line = line.decode()
if line.startswith(CONTENT_LENGTH):
content_length = int(line[len(CONTENT_LENGTH):].strip())
log(f">> [{label}] ce: [{content_length}]")
source.readline()
payload = source.read(content_length).decode()
log(">> [{label}] payload: [{payload}]", label=label, payload=payload)
if handlers:
payload_parsed = json.loads(payload)
for handler in handlers:
try:
handler(payload_parsed)
except Exception as e:
log(f"Error from handler: {e}")
transmit_payload(payload, sink)
except Exception as e:
log(f"[{label}] Error decoding input: {e}")
line = line.decode()
if line.startswith(CONTENT_LENGTH):
content_length = int(line[len(CONTENT_LENGTH):].strip())
print(f">> ce: [{content_length}]", file=log)
source.readline()
payload = source.read(content_length).decode()
print(f">> payload: [{payload}]", file=log)
if handlers:
payload_parsed = json.loads(payload)
for handler in handlers:
try:
handler(payload_parsed)
except Exception as e:
print(f"Error from handler: {e}", file=log)
transmit_payload(payload, sink)
log(f"[{label}] exit process_messages")
print("stop message handler", file=log)
def transmit_payload (payload, sink):
if isinstance(payload, dict):
@ -97,16 +91,13 @@ class LspServer:
def start (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:
self.process = process
self.process_reader = Thread(target=process_messages, args=["process.stdout reader", process.stdout, sys.stdout.buffer, handlers])
self.process_reader = Thread(target=process_messages, args=[process.stdout, sys.stdout.buffer, handlers, sys.stderr])
self.process_reader.start()
process_messages("process.stdin reader", sys.stdin.buffer, process.stdin, handlers)
log("lsp process ended")
process_messages(sys.stdin.buffer, process.stdin, handlers, sys.stderr)
def start2 (self):
run(self.command)