From bf74a0983c2d534e217e7312ab559ca8929ff8a2 Mon Sep 17 00:00:00 2001 From: umarcor Date: Sun, 27 Dec 2020 22:10:38 +0100 Subject: rework 'python', rename to 'pyGHDL' * Rename 'python' to 'pyGHDL'. * Let 'thin' be 'libghdl'. * Move move 'pyutils.py' from 'python/libghdl/vhdl' to a separate package ('pyGHDL/libghdl/utils/'). * Update 'vhdl_langserver' accordingly. * Rename 'vhdl_langserver' to 'lsp'. * Move 'ghdl-ls' to 'pyGHDL/cli'. --- pyGHDL/lsp/lsptools.py | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 pyGHDL/lsp/lsptools.py (limited to 'pyGHDL/lsp/lsptools.py') diff --git a/pyGHDL/lsp/lsptools.py b/pyGHDL/lsp/lsptools.py new file mode 100644 index 000000000..648f0a8c0 --- /dev/null +++ b/pyGHDL/lsp/lsptools.py @@ -0,0 +1,41 @@ +import sys +import argparse +import json +from . import lsp + + +def lsp2json(): + "Utility that transforms lsp log file to a JSON list" + conn = lsp.LSPConn(sys.stdin.buffer, sys.stdout.buffer) + ls = lsp.LanguageProtocolServer(None, conn) + res = [] + while True: + req = ls.read_request() + if req is None: + break + res.append(json.loads(req)) + print(json.dumps(res, indent=2)) + + +def json2lsp(): + "Utility that transform a JSON list to an lsp file" + res = json.load(sys.stdin) + conn = lsp.LSPConn(sys.stdin.buffer, sys.stdout.buffer) + ls = lsp.LanguageProtocolServer(None, conn) + for req in res: + ls.write_output(req) + + +def main(): + parser = argparse.ArgumentParser() + subparsers = parser.add_subparsers(help="sub-command help") + parser_l2j = subparsers.add_parser("lsp2json", help="convert lsp dump to JSON") + parser_l2j.set_defaults(func=lsp2json) + parser_j2l = subparsers.add_parser("json2lsp", help="convert JSON to lsp dump") + parser_j2l.set_defaults(func=json2lsp) + args = parser.parse_args() + args.func() + + +if __name__ == "__main__": + main() -- cgit v1.2.3