From d0893f3708a62c572064e5191e86d84722f8ad9a Mon Sep 17 00:00:00 2001 From: Daniel Fichtinger Date: Mon, 9 Jun 2025 19:11:37 -0400 Subject: [PATCH] AutoYADM commit: 2025-06-09 19:11:37 --- .config/kak/scripts/lsp-diags.py | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/.config/kak/scripts/lsp-diags.py b/.config/kak/scripts/lsp-diags.py index bf9ee83b..0b0a1e38 100755 --- a/.config/kak/scripts/lsp-diags.py +++ b/.config/kak/scripts/lsp-diags.py @@ -1,5 +1,7 @@ #!/usr/bin/env python +# pyright: strict, reportUnusedCallResult=false + import sys import os import tempfile @@ -64,6 +66,27 @@ 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}" +def daemonize(): + # exit parent + if os.fork() > 0: + sys.exit(0) + # new session + os.setsid() + 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: + os.dup2(dn.fileno(), sys.stdin.fileno()) + with open("/dev/null", "ab", 0) as dn: + os.dup2(dn.fileno(), sys.stdout.fileno()) + os.dup2(dn.fileno(), sys.stderr.fileno()) + + def main(): # create unique directory and names fifo_dir = tempfile.mkdtemp(prefix="diagpipe-") @@ -76,8 +99,10 @@ def main(): _ = atexit.register(lambda: cleanup(in_path, out_path, fifo_dir)) - print(in_path, flush=True) - print(out_path, flush=True) + output = gen_kakoune_output(in_path, out_path) + print(output) + sys.stdout.flush() + daemonize() with open(in_path, "r") as infile, open(out_path, "w") as outfile: diagnostics = []