ziglibs / zig-lsp

Microsoft's Language Server Protocol implemented in Zig for use in zls and beyond! <3
MIT License
44 stars 2 forks source link

Responding to a request with slices #5

Open tadeokondrak opened 1 year ago

tadeokondrak commented 1 year ago

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?

dstrachan commented 8 months ago

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