diff options
author | Yegappan Lakshmanan <yegappan@yahoo.com> | 2022-03-30 10:16:05 +0100 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2022-03-30 10:16:05 +0100 |
commit | 9247a221ce7800c0ae1b3487112d314b8ab79f53 (patch) | |
tree | 9a8b926843777e9c2af9c420ff098155b2ee113b /src/json.c | |
parent | 2bdad6126778f907c0b98002bfebf0e611a3f5db (diff) | |
download | vim-git-9247a221ce7800c0ae1b3487112d314b8ab79f53.tar.gz |
patch 8.2.4648: handling LSP messages is a bit slowv8.2.4648
Problem: Handling LSP messages is a bit slow.
Solution: Included support for LSP messages. (Yegappan Lakshmanan,
closes #10025)
Diffstat (limited to 'src/json.c')
-rw-r--r-- | src/json.c | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/json.c b/src/json.c index 942d131e3..b23bfa089 100644 --- a/src/json.c +++ b/src/json.c @@ -86,6 +86,32 @@ json_encode_nr_expr(int nr, typval_T *val, int options) ga_append(&ga, NUL); return ga.ga_data; } + +/* + * Encode "val" into a JSON format string prefixed by the LSP HTTP header. + * Returns NULL when out of memory. + */ + char_u * +json_encode_lsp_msg(typval_T *val) +{ + garray_T ga; + garray_T lspga; + + ga_init2(&ga, 1, 4000); + if (json_encode_gap(&ga, val, 0) == FAIL) + return NULL; + ga_append(&ga, NUL); + + ga_init2(&lspga, 1, 4000); + vim_snprintf((char *)IObuff, IOSIZE, + "Content-Length: %u\r\n" + "Content-Type: application/vim-jsonrpc; charset=utf-8\r\n\r\n", + ga.ga_len - 1); + ga_concat(&lspga, IObuff); + ga_concat_len(&lspga, ga.ga_data, ga.ga_len); + ga_clear(&ga); + return lspga.ga_data; +} #endif static void |