AutoYADM commit: 2025-06-09 23:39:01

This commit is contained in:
Daniel Fichtinger 2025-06-09 23:39:01 -04:00
parent ac51e3f41e
commit ad6b9f48b1
2 changed files with 19 additions and 10 deletions

View file

@ -214,6 +214,8 @@ define-command lsp-check-inline-diagnostic %{
# we write a python script for this
}
evaluate-commands %sh{ ${kak_config}/scripts/lsp-diags.py }
define-command lsp-diag-set %{
evaluate-commands %sh{
printf 'set %s\n' "$kak_opt_lsp_inline_diagnostics" >"$kak_opt_diagpipe_in"

View file

@ -2,11 +2,13 @@
# pyright: strict, reportUnusedCallResult=false
import atexit
import subprocess
import sys
import os
import tempfile
import atexit
import signal
from typing import Any
Position = tuple[int, int]
SpecList = list[tuple[Position, Position]]
@ -55,6 +57,7 @@ def test():
def cleanup(inp: str, outp: str, dir: str):
subprocess.run(["notify-send", "cleanup runs"])
try:
os.remove(inp)
os.remove(outp)
@ -64,10 +67,10 @@ def cleanup(inp: str, outp: str, dir: str):
def gen_kakoune_output(inp: str, outp: str) -> str:
return f"declare_option -hidden str diagpipe_in {inp}\ndeclare_option -hidden str diagpipe_out {outp}"
return f"declare-option -hidden str diagpipe_in {inp}\ndeclare-option -hidden str diagpipe_out {outp}"
def daemonize():
def daemonize(inp: str, outp: str, dir: str):
# fork and exit parent
if os.fork() > 0:
sys.exit(0)
@ -76,9 +79,6 @@ def daemonize():
if os.fork() > 0:
# exit first child
sys.exit(0)
_ = sys.stdin.close()
_ = sys.stdout.flush()
_ = sys.stderr.flush()
# redirect IO to /dev/null
with open("/dev/null", "rb", 0) as dn:
@ -86,9 +86,18 @@ def daemonize():
with open("/dev/null", "ab", 0) as dn:
os.dup2(dn.fileno(), sys.stdout.fileno())
os.dup2(dn.fileno(), sys.stderr.fileno())
_ = atexit.register(lambda: cleanup(inp, outp, dir))
def on_exit(signum: Any, frame: Any):
cleanup(inp, outp, dir)
sys.exit(0)
signal.signal(signal.SIGTERM, on_exit)
signal.signal(signal.SIGINT, on_exit)
def main():
subprocess.run(["notify-send", "begin loop"])
# create unique directory and names
fifo_dir = tempfile.mkdtemp(prefix="diagpipe-")
in_path = os.path.join(fifo_dir, "in")
@ -98,12 +107,10 @@ def main():
os.mkfifo(in_path)
os.mkfifo(out_path)
_ = atexit.register(lambda: cleanup(in_path, out_path, fifo_dir))
output = gen_kakoune_output(in_path, out_path)
print(output)
sys.stdout.flush()
daemonize()
daemonize(in_path, out_path, fifo_dir)
with open(in_path, "r") as infile, open(out_path, "w") as outfile:
diagnostics = []