zig-lsp icon indicating copy to clipboard operation
zig-lsp copied to clipboard

Responding to a request with slices

Open tadeokondrak opened this issue 2 years ago • 1 comments

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?

tadeokondrak avatar Jul 12 '23 02:07 tadeokondrak

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

dstrachan avatar Feb 15 '24 00:02 dstrachan