diff --git a/.config/kak/autoload/lsp.kak b/.config/kak/autoload/lsp.kak index 5e389c57..a9ca4889 100644 --- a/.config/kak/autoload/lsp.kak +++ b/.config/kak/autoload/lsp.kak @@ -237,6 +237,13 @@ define-command -params 2 lsp-diag-query %{ } } +hook global KakEnd .* %{ + nop %sh{ + printf 'exit\n' >"$kak_opt_diagpipe_in" + read result < "$kak_opt_diagpipe_out" + } +} + define-command lsp-diag-hover-enable %{ hook window User lsp-diag-hover-false %{ try inlay-diagnostics-off @@ -252,13 +259,6 @@ define-command lsp-diag-hover-enable %{ hook window WinSetOption lsp_inline_diagnostics=.* %{ lsp-diag-set } - hook global KakEnd .* %{ - nop %sh{ - printf 'exit\n' >"$kak_opt_diagpipe_in" - read result < "$kak_opt_diagpipe_out" - } - } - } hook global User lsp-enabled %{ diff --git a/.config/kak/scripts/lsp-diags.py b/.config/kak/scripts/lsp-diags.py index 2bd6a30a..e9b30345 100755 --- a/.config/kak/scripts/lsp-diags.py +++ b/.config/kak/scripts/lsp-diags.py @@ -9,6 +9,7 @@ import os import tempfile import signal import types +import selectors Position = tuple[int, int] SpecList = list[tuple[Position, Position]] @@ -104,12 +105,21 @@ def main(): sys.stdout.flush() daemonize(in_path, out_path, fifo_dir) - with open(in_path, "r") as infile, open(out_path, "w") as outfile: - diagnostics: SpecList = [] - while True: - line = infile.readline() + sel = selectors.DefaultSelector() + infile = open(in_path, "r", buffering=1) + outfile = open(out_path, "w", buffering=1) + sel.register(infile.fileno(), selectors.EVENT_READ, data=infile) + + # with open(in_path, "r") as infile, open(out_path, "w") as outfile: + diagnostics: SpecList = [] + while True: + for key, _ in sel.select(timeout=None): + infile_obj = key.data + line = infile_obj.readline() + # line = infile.readline() if not line: continue + line = line.strip() assert isinstance(line, str) # # subprocess.run(["notify-send", f"Received command: {line}"]) if line.startswith("set "):