Compare commits
No commits in common. "bb8bd19f64e894c2bb533bb86cf2233ce719c031" and "91236b728be66405d2987e1c5b7165acc2c43b60" have entirely different histories.
bb8bd19f64
...
91236b728b
@ -8,7 +8,7 @@ from .lsp import LspServer, command, get_data_home
|
|||||||
|
|
||||||
FILE_URI = "file://"
|
FILE_URI = "file://"
|
||||||
|
|
||||||
VERSION = "1.1.1"
|
VERSION = "0.64.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"
|
||||||
|
|
||||||
|
@ -10,40 +10,34 @@ from xdg import xdg_data_home
|
|||||||
|
|
||||||
CONTENT_LENGTH = "Content-Length: "
|
CONTENT_LENGTH = "Content-Length: "
|
||||||
|
|
||||||
def log (message, *args, **kwargs):
|
def process_messages (source, sink, handlers, log):
|
||||||
print(message.format(*args, **kwargs), file=sys.stderr)
|
print("start message handler", file=log)
|
||||||
|
|
||||||
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
|
||||||
|
|
||||||
try:
|
line = line.decode()
|
||||||
line = line.decode()
|
if line.startswith(CONTENT_LENGTH):
|
||||||
if line.startswith(CONTENT_LENGTH):
|
content_length = int(line[len(CONTENT_LENGTH):].strip())
|
||||||
content_length = int(line[len(CONTENT_LENGTH):].strip())
|
print(f">> ce: [{content_length}]", file=log)
|
||||||
log(f">> [{label}] ce: [{content_length}]")
|
|
||||||
|
|
||||||
source.readline()
|
source.readline()
|
||||||
|
|
||||||
payload = source.read(content_length).decode()
|
payload = source.read(content_length).decode()
|
||||||
log(">> [{label}] payload: [{payload}]", label=label, payload=payload)
|
print(f">> payload: [{payload}]", file=log)
|
||||||
|
|
||||||
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:
|
||||||
log(f"Error from handler: {e}")
|
print(f"Error from handler: {e}", file=log)
|
||||||
|
|
||||||
transmit_payload(payload, sink)
|
transmit_payload(payload, sink)
|
||||||
except Exception as e:
|
|
||||||
log(f"[{label}] Error decoding input: {e}")
|
|
||||||
|
|
||||||
log(f"[{label}] exit process_messages")
|
print("stop message handler", file=log)
|
||||||
|
|
||||||
def transmit_payload (payload, sink):
|
def transmit_payload (payload, sink):
|
||||||
if isinstance(payload, dict):
|
if isinstance(payload, dict):
|
||||||
@ -97,16 +91,13 @@ 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 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()
|
self.process_reader.start()
|
||||||
|
|
||||||
process_messages("process.stdin reader", sys.stdin.buffer, process.stdin, handlers)
|
process_messages(sys.stdin.buffer, process.stdin, handlers, sys.stderr)
|
||||||
|
|
||||||
log("lsp process ended")
|
|
||||||
|
|
||||||
def start2 (self):
|
def start2 (self):
|
||||||
run(self.command)
|
run(self.command)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user