From 23fefb6b7c36cdf19f6c97367973e6a34989157f Mon Sep 17 00:00:00 2001 From: Armand Touminet Date: Sun, 7 May 2023 03:05:42 +0200 Subject: [PATCH 1/4] remove REPL history clear when starting a new session --- lua/dap/session.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/lua/dap/session.lua b/lua/dap/session.lua index 8dc4a6ee..f205367f 100644 --- a/lua/dap/session.lua +++ b/lua/dap/session.lua @@ -1623,7 +1623,6 @@ end --- Initialize the debug session ---@param config Configuration function Session:initialize(config) - vim.schedule(repl.clear) local adapter_responded = false self.config = config self:request('initialize', { From 83729f206102a7bb0b789044dae24b8a08a9dff0 Mon Sep 17 00:00:00 2001 From: Armand Touminet Date: Mon, 8 May 2023 18:55:48 +0200 Subject: [PATCH 2/4] clear REPL output on session startup, set maximum REPL history size --- lua/dap/repl.lua | 14 +++++++------- lua/dap/session.lua | 1 + 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/lua/dap/repl.lua b/lua/dap/repl.lua index de4c8cce..7efe2e8b 100644 --- a/lua/dap/repl.lua +++ b/lua/dap/repl.lua @@ -6,7 +6,8 @@ local M = {} local history = { last = nil, entries = {}, - idx = 1 + idx = 1, + max_size = 5000, } local autoscroll = vim.fn.has('nvim-0.7') == 1 @@ -226,6 +227,9 @@ function execute(text) end else history.last = text + if #history.entries == history.max_size then + table.remove(history.entries, 1) + end table.insert(history.entries, text) history.idx = #history.entries + 1 end @@ -245,8 +249,7 @@ function execute(text) return elseif vim.tbl_contains(M.commands.clear, text) then if repl.buf and api.nvim_buf_is_loaded(repl.buf) then - local layer = ui.layer(repl.buf) - layer.render({}, tostring, {}, 0, - 1) + M.clear_output() end return end @@ -383,10 +386,7 @@ function M.append(line, lnum, opts) end -function M.clear() - history.last = nil - history.entries = {} - history.idx = 1 +function M.clear_output() if repl.buf and api.nvim_buf_is_loaded(repl.buf) then local layer = ui.layer(repl.buf) layer.render({}, tostring, {}, 0, - 1) diff --git a/lua/dap/session.lua b/lua/dap/session.lua index f205367f..71a2f72a 100644 --- a/lua/dap/session.lua +++ b/lua/dap/session.lua @@ -1623,6 +1623,7 @@ end --- Initialize the debug session ---@param config Configuration function Session:initialize(config) + vim.schedule(repl.clear_output) local adapter_responded = false self.config = config self:request('initialize', { From dffdd74459146f656f1a5eb8903fb381eca8db35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mathias=20Fu=C3=9Fenegger?= Date: Wed, 17 May 2023 20:52:14 +0200 Subject: [PATCH 3/4] Apply suggestions from code review --- lua/dap/repl.lua | 4 ++-- lua/dap/session.lua | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lua/dap/repl.lua b/lua/dap/repl.lua index 7efe2e8b..1efbd202 100644 --- a/lua/dap/repl.lua +++ b/lua/dap/repl.lua @@ -249,7 +249,7 @@ function execute(text) return elseif vim.tbl_contains(M.commands.clear, text) then if repl.buf and api.nvim_buf_is_loaded(repl.buf) then - M.clear_output() + M.clear() end return end @@ -386,7 +386,7 @@ function M.append(line, lnum, opts) end -function M.clear_output() +function M.clear() if repl.buf and api.nvim_buf_is_loaded(repl.buf) then local layer = ui.layer(repl.buf) layer.render({}, tostring, {}, 0, - 1) diff --git a/lua/dap/session.lua b/lua/dap/session.lua index 71a2f72a..8dc4a6ee 100644 --- a/lua/dap/session.lua +++ b/lua/dap/session.lua @@ -1623,7 +1623,7 @@ end --- Initialize the debug session ---@param config Configuration function Session:initialize(config) - vim.schedule(repl.clear_output) + vim.schedule(repl.clear) local adapter_responded = false self.config = config self:request('initialize', { From 3b806b0f382da8ea1635c2a3772e7a89734ab6ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mathias=20Fu=C3=9Fenegger?= Date: Wed, 17 May 2023 20:52:42 +0200 Subject: [PATCH 4/4] Update lua/dap/repl.lua --- lua/dap/repl.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/dap/repl.lua b/lua/dap/repl.lua index 1efbd202..20522444 100644 --- a/lua/dap/repl.lua +++ b/lua/dap/repl.lua @@ -7,7 +7,7 @@ local history = { last = nil, entries = {}, idx = 1, - max_size = 5000, + max_size = 100, } local autoscroll = vim.fn.has('nvim-0.7') == 1