From c1bcc569f1eb5df51ade0579d2cfd5dfb7f2ff11 Mon Sep 17 00:00:00 2001 From: Marc Jakobi Date: Mon, 23 Oct 2023 01:27:34 +0200 Subject: [PATCH] feat(lsp): support `rust-analyzer/viewRecursiveMemoryLayout` --- lua/rustaceanvim/commands/init.lua | 3 ++ lua/rustaceanvim/commands/memory_layout.lua | 31 +++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 lua/rustaceanvim/commands/memory_layout.lua diff --git a/lua/rustaceanvim/commands/init.lua b/lua/rustaceanvim/commands/init.lua index 528c2db2..99726c87 100644 --- a/lua/rustaceanvim/commands/init.lua +++ b/lua/rustaceanvim/commands/init.lua @@ -56,6 +56,9 @@ local command_tbl = { joinLines = function(_) require('rustaceanvim.commands.join_lines')() end, + memoryLayout = function(_) + require('rustaceanvim.commands.memory_layout')() + end, moveItem = function(args) if #args == 0 then vim.notify("moveItem: called without 'up' or 'down'", vim.log.levels.ERROR) diff --git a/lua/rustaceanvim/commands/memory_layout.lua b/lua/rustaceanvim/commands/memory_layout.lua new file mode 100644 index 00000000..fb68a253 --- /dev/null +++ b/lua/rustaceanvim/commands/memory_layout.lua @@ -0,0 +1,31 @@ +local ui = require('rustaceanvim.ui') + +local M = {} + +---@return lsp_range_params + +---@type integer | nil +local latest_buf_id = nil + +local function parse(_) + local ret = {} + -- TODO: + error('not implemented') + return ret +end + +local function handler(_, result) + ui.delete_buf(latest_buf_id) + latest_buf_id = vim.api.nvim_create_buf(false, true) + ui.split(true, latest_buf_id) + vim.api.nvim_buf_set_name(latest_buf_id, 'memory.layout.rust') + vim.api.nvim_buf_set_text(latest_buf_id, 0, 0, 0, 0, parse(result)) + ui.resize(true, '-25') +end + +local rl = require('rustaceanvim.rust_analyzer') +function M.memory_layout() + rl.buf_request(0, 'rust-analyzer/viewRecursiveMemoryLayout', vim.lsp.util.make_position_params(), handler) +end + +return M.memory_layout