From c08de64ce17bec1369b9d7dd4a9e67006a3665f3 Mon Sep 17 00:00:00 2001 From: lopy <70210066+lopi-py@users.noreply.github.com> Date: Sun, 10 Nov 2024 18:24:23 -0500 Subject: [PATCH] feat: add `sourcemap.sourcemap_file` option --- CHANGELOG.md | 8 ++++++++ README.md | 3 ++- lua/luau-lsp/bytecode.lua | 8 ++++---- lua/luau-lsp/config.lua | 1 + lua/luau-lsp/health.lua | 2 +- lua/luau-lsp/roblox/sourcemap.lua | 6 +++--- lua/luau-lsp/server.lua | 1 + spec/server_spec.lua | 14 +------------- 8 files changed, 21 insertions(+), 22 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e8aa869..8196944 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,14 @@ ## [Unreleased] +### Added + +- Option `sourcemap.sourcemap_file` to specify a different name to use for the sourcemap + +### Changed + +- Upgraded the required version of `luau-lsp` to `1.35.0` + ### Removed - Deprecated option `types.roblox` diff --git a/README.md b/README.md index 61acf8e..e944791 100644 --- a/README.md +++ b/README.md @@ -99,6 +99,7 @@ require("luau-lsp").setup { enabled = true, autogenerate = true, -- automatic generation when the server is attached rojo_project_file = "default.project.json", + sourcemap_file = "sourcemap.json", }, } ``` @@ -164,7 +165,6 @@ require("luau-lsp").setup { settings = { ["luau-lsp"] = { require = { - mode = "relativeToFile", directoryAliases = require("luau-lsp").aliases(), }, }, @@ -226,6 +226,7 @@ local defaults = { rojo_path = "rojo", rojo_project_file = "default.project.json", include_non_scripts = true, + sourcemap_file = "sourcemap.json", }, types = { ---@type string[] diff --git a/lua/luau-lsp/bytecode.lua b/lua/luau-lsp/bytecode.lua index b7a5d04..4679298 100644 --- a/lua/luau-lsp/bytecode.lua +++ b/lua/luau-lsp/bytecode.lua @@ -37,7 +37,7 @@ end local function create_view() vim.cmd "belowright vsplit +enew" - local augroup = vim.api.nvim_create_augroup("luau-lsp/bytecode", {}) + local group = vim.api.nvim_create_augroup("luau-lsp/bytecode", {}) bytecode_bufnr = vim.api.nvim_get_current_buf() bytecode_winnr = vim.api.nvim_get_current_win() @@ -59,17 +59,17 @@ local function create_view() }) vim.api.nvim_create_autocmd(UPDATE_EVENTS, { - group = augroup, + group = group, callback = function(event) M.update_buffer(event.buf) end, }) vim.api.nvim_create_autocmd("BufUnload", { - group = augroup, + group = group, buffer = bytecode_bufnr, callback = function() - vim.api.nvim_del_augroup_by_id(augroup) + vim.api.nvim_del_augroup_by_id(group) end, }) diff --git a/lua/luau-lsp/config.lua b/lua/luau-lsp/config.lua index 746d069..9dd10e6 100644 --- a/lua/luau-lsp/config.lua +++ b/lua/luau-lsp/config.lua @@ -20,6 +20,7 @@ local defaults = { rojo_path = "rojo", rojo_project_file = "default.project.json", include_non_scripts = true, + sourcemap_file = "sourcemap.json", }, types = { ---@type string[] diff --git a/lua/luau-lsp/health.lua b/lua/luau-lsp/health.lua index 385802d..639b901 100644 --- a/lua/luau-lsp/health.lua +++ b/lua/luau-lsp/health.lua @@ -34,7 +34,7 @@ function M.check() check_executable { name = "luau-lsp", cmd = { vim.fn.exepath(config.get().server.cmd[1]), "--version" }, - version = "1.34.0", + version = "1.35.0", } local ok, autocmds = pcall(vim.api.nvim_get_autocmds, { diff --git a/lua/luau-lsp/roblox/sourcemap.lua b/lua/luau-lsp/roblox/sourcemap.lua index a6b64f2..c471bf7 100644 --- a/lua/luau-lsp/roblox/sourcemap.lua +++ b/lua/luau-lsp/roblox/sourcemap.lua @@ -55,14 +55,14 @@ local function start_sourcemap_generation(project_file) "--watch", project_file, "--output", - "sourcemap.json", + config.get().sourcemap.sourcemap_file, } if config.get().sourcemap.include_non_scripts then table.insert(cmd, "--include-non-scripts") end - local augroup = vim.api.nvim_create_augroup("luau-lsp/sourcemap", {}) + local group = vim.api.nvim_create_augroup("luau-lsp/sourcemap", {}) local ok, job = pcall(vim.system, cmd, { text = true, }, function(result) @@ -80,7 +80,7 @@ local function start_sourcemap_generation(project_file) pid = job.pid vim.api.nvim_create_autocmd("VimLeavePre", { - group = augroup, + group = group, callback = stop_sourcemap_generation, }) end diff --git a/lua/luau-lsp/server.lua b/lua/luau-lsp/server.lua index 62026ca..a8c9df2 100644 --- a/lua/luau-lsp/server.lua +++ b/lua/luau-lsp/server.lua @@ -95,6 +95,7 @@ local function get_settings() }, sourcemap = { enabled = config.get().sourcemap.enabled, + sourcemapFile = config.get().sourcemap.sourcemap_file, }, }, } diff --git a/spec/server_spec.lua b/spec/server_spec.lua index e4f7544..2885132 100644 --- a/spec/server_spec.lua +++ b/spec/server_spec.lua @@ -114,18 +114,6 @@ describe("luau-lsp server", function() create_luau_buffer() local client = wait_for_client() - assert.same({ - ["luau-lsp"] = { - platform = { - type = "roblox", - }, - sourcemap = { - enabled = true, - }, - testSetting = { - testField = "testing", - }, - }, - }, client.settings) + assert.same("testing", vim.tbl_get(client.settings, "luau-lsp", "testSetting", "testField")) end) end)