zig-lsp
zig-lsp copied to clipboard
Responding to a request with slices
Some request results have slices, like textDocument/hover's MarkupContent.
When using lsp.Connection, the signature is
pub fn @"textDocument/hover"(conn: *Connection, id: lsp.types.RequestId, params: lsp.types.HoverParams) !lsp.types.Hover
If I set up an arena allocator inside the implementation, the memory returned becomes invalid. Is there a simple way to do this without leaking memory?
You should take a look at implementing lspRecvPre and lspRecvPost hooks which will be called before and after your textDocument/hover request.
https://github.com/ziglibs/zig-lsp/blob/d89ebda52af2db181bfcdb3fba17f7e3e8208984/src/zig_lsp.zig#L314-L320