Skip to content
This repository has been archived by the owner on Feb 27, 2024. It is now read-only.

Responding to a request with slices #5

Open
tadeokondrak opened this issue Jul 12, 2023 · 1 comment
Open

Responding to a request with slices #5

tadeokondrak opened this issue Jul 12, 2023 · 1 comment

Comments

@tadeokondrak
Copy link

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
Copy link

You should take a look at implementing lspRecvPre and lspRecvPost hooks which will be called before and after your textDocument/hover request.

zig-lsp/src/zig_lsp.zig

Lines 314 to 320 in d89ebda

if (@hasDecl(ContextType, "lspRecvPre")) try ContextType.lspRecvPre(conn, req.method, .request, id, value);
try conn.respond(req.method, id, @field(ContextType, req.method)(conn, id, value) catch |err| {
try conn.respondError(arena, id, err, @errorReturnTrace());
if (@hasDecl(ContextType, "lspRecvPost")) try ContextType.lspRecvPost(conn, req.method, .request, id, value);
return;
});
if (@hasDecl(ContextType, "lspRecvPost")) try ContextType.lspRecvPost(conn, req.method, .request, id, value);

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants