lsp tool: offer to install a missing language server
ci / check (pull_request) Canceled after 0s
ci / check (push) Canceled after 0s

This commit is contained in:
hermes committed 2026-09-30 21:10:13 +00:00
1 parent ee167ce6ed
commit ee0714d271
10 files changed
+378 -5

No files matched your search

+1
View File
@@ -17,3 +17,4 @@ sh tests/lens_e2e.sh
sh tests/m4_e2e.sh
sh tests/m5_e2e.sh
sh tests/m6_e2e.sh
python3 tests/tui_lspinstall.py | grep -q FAIL && { echo "tui lsp install FAIL"; exit 1; } || echo "tui lsp install ok"
+38
View File
@@ -0,0 +1,38 @@
"""Fake model: turn 1 calls lsp symbols on a.zz; turn 2 finishes echoing the tool result."""
import http.server, json, sys
N = [0]
def sse(ev, d):
return f"event: {ev}\ndata: {json.dumps(d)}\n\n".encode()
class H(http.server.BaseHTTPRequestHandler):
def log_message(self, *a):
pass
def do_POST(self):
body = json.loads(self.rfile.read(int(self.headers["content-length"])))
N[0] += 1
last = body["messages"][-1]["content"]
res = "".join(b.get("content", "") if isinstance(b.get("content"), str) else "" for b in last if b.get("type") == "tool_result")
self.send_response(200)
self.send_header("content-type", "text/event-stream")
self.end_headers()
w = self.wfile.write
w(sse("message_start", {"message": {"usage": {"input_tokens": 1, "output_tokens": 1}}}))
if N[0] == 1:
w(sse("content_block_start", {"index": 0, "content_block": {"type": "tool_use", "id": "t1", "name": "lsp", "input": {}}}))
w(sse("content_block_delta", {"index": 0, "delta": {"type": "input_json_delta", "partial_json": json.dumps({"action": "symbols", "path": "a.zz"})}}))
stop = "tool_use"
else:
w(sse("content_block_start", {"index": 0, "content_block": {"type": "text", "text": ""}}))
w(sse("content_block_delta", {"index": 0, "delta": {"type": "text_delta", "text": "RESULT " + res[:60]}}))
stop = "end_turn"
w(sse("content_block_stop", {"index": 0}))
w(sse("message_delta", {"delta": {"stop_reason": stop}, "usage": {"output_tokens": 1}}))
w(sse("message_stop", {}))
http.server.ThreadingHTTPServer(("127.0.0.1", int(sys.argv[1])), H).serve_forever()
+72
View File
@@ -0,0 +1,72 @@
"""lsp install prompt in the TUI: missing server -> [y/n] -> y runs the installer."""
import os, pty, sys, time, subprocess, select, re, json, tempfile, signal
root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
port = 20000 + os.getpid() % 20000
srv = subprocess.Popen([sys.executable, f"{root}/tests/fake_lspinstall.py", str(port)])
tmp = tempfile.mkdtemp()
os.makedirs(f"{tmp}/home/.hx"); os.makedirs(f"{tmp}/repo")
open(f"{tmp}/home/.hx/auth.json", "w").write(json.dumps({"claude": {"access": "fake-token", "refresh": "r", "expires": 99999999999999}}))
open(f"{tmp}/repo/a.zz", "w").write("")
binp = f"{tmp}/bin/fake-ls"
open(f"{tmp}/home/.hx/config.toml", "w").write(f"""[lsp]
tests = "off"
[[lsp.servers]]
id = "fakels"
language = "zz"
extensions = ["zz"]
command = ["{binp}"]
roots = []
install = ["sh", "-c", "mkdir -p {tmp}/bin && touch {binp} && chmod +x {binp}"]
""")
time.sleep(0.5)
pid, fd = pty.fork()
if pid == 0:
os.chdir(f"{tmp}/repo")
os.environ.update(HOME=f"{tmp}/home", HX_BASE_URL=f"http://127.0.0.1:{port}", TERM="xterm-256color", COLUMNS="100", LINES="30")
os.execv(f"{root}/target/debug/hx", ["hx"])
import fcntl, termios, struct
fcntl.ioctl(fd, termios.TIOCSWINSZ, struct.pack("HHHH", 30, 100, 0, 0))
buf = b""
def pump(t):
global buf
end = time.time() + t
while time.time() < end:
r, _, _ = select.select([fd], [], [], 0.05)
if r:
try:
buf += os.read(fd, 65536)
except OSError:
return
def plain():
s = buf.decode(errors="replace")
s = re.sub(r"\x1b\[[0-9;?]*[A-Za-z]", " ", s)
return re.sub(r"\x1b[()][A-Z0-9]|\x1b[=>]", "", s)
def send(b, t=0.6):
os.write(fd, b); pump(t)
ok = True
def check(label, needle):
global ok
hit = needle in plain()
ok &= hit
print(f"{'PASS' if hit else 'FAIL'} {label}: {needle!r}")
pump(1.5)
send(b"go\r", 3)
check("question in footer", "[y/n] fakels is not")
check("installer shown", "Run `sh -c mkdir")
send(b"y", 3)
check("answer logged", " yes")
check("installed", "") if os.path.exists(binp) else (print("FAIL installer did not run"), globals().update(ok=False))
send(b"\x03", 1) # ctrl-c on empty -> quit
try:
_, st = os.waitpid(pid, 0)
print("exit status", st)
except ChildProcessError:
pass
check("exit summary", "session")
srv.kill()
sys.exit(0 if ok else 1)