From b9ea15454ca828f63ba0c1dcebb3307575c72406 Mon Sep 17 00:00:00 2001 From: lopy <70210066+lopi-py@users.noreply.github.com> Date: Thu, 29 Aug 2024 21:28:36 -0500 Subject: [PATCH] fix: kill rojo sourcemap process on exit --- CHANGELOG.md | 4 ++++ lua/luau-lsp/roblox/sourcemap.lua | 17 +++++++++++------ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 040acd4..98510b1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ - Support for Neovim 0.9 +### Fixed + +- Kill rojo sourcemap process on exit + ## [1.6.0] - 2024-08-29 ### Added diff --git a/lua/luau-lsp/roblox/sourcemap.lua b/lua/luau-lsp/roblox/sourcemap.lua index 9adb8bc..a6b64f2 100644 --- a/lua/luau-lsp/roblox/sourcemap.lua +++ b/lua/luau-lsp/roblox/sourcemap.lua @@ -37,6 +37,12 @@ local function get_rojo_project_file(callback) end end +local function stop_sourcemap_generation() + if pid then + vim.uv.kill(pid) + end +end + ---@param project_file? string local function start_sourcemap_generation(project_file) if not project_file then @@ -56,13 +62,13 @@ local function start_sourcemap_generation(project_file) table.insert(cmd, "--include-non-scripts") end + local augroup = vim.api.nvim_create_augroup("luau-lsp/sourcemap", {}) local ok, job = pcall(vim.system, cmd, { text = true, }, function(result) if result.stderr and result.stderr ~= "" then log.error("Failed to update sourcemap for '%s': %s", project_file, result.stderr) end - pid = nil end) if not ok then @@ -72,12 +78,11 @@ local function start_sourcemap_generation(project_file) log.info("Starting sourcemap generation for '%s'", project_file) pid = job.pid -end -local function stop_sourcemap_generation() - if pid then - vim.uv.kill(pid) - end + vim.api.nvim_create_autocmd("VimLeavePre", { + group = augroup, + callback = stop_sourcemap_generation, + }) end ---@param project_file? string