From b24c79ffc2fd20964b2713f2f93a3a7c23faa235 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Martins?= Date: Fri, 21 Mar 2025 00:00:54 -0300 Subject: [PATCH 1/7] =?UTF-8?q?=F0=9F=90=9B=20Fix=20path=20combine=20in=20?= =?UTF-8?q?debug=20adapter=20module=20for=20any=20OS?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lua/csharp/modules/dap.lua | 3 ++- lua/csharp/utils.lua | 8 ++++++++ tests/utils_spec.lua | 21 +++++++++++++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/lua/csharp/modules/dap.lua b/lua/csharp/modules/dap.lua index fc96f23..bb5145c 100644 --- a/lua/csharp/modules/dap.lua +++ b/lua/csharp/modules/dap.lua @@ -1,6 +1,7 @@ local M = {} local config_store = require("csharp.config") local dap = require("dap") +local utils = require("csharp.utils") function M.get_debug_adapter() local config = config_store.get_config().dap @@ -22,7 +23,7 @@ function M.get_debug_adapter() package:install() end - local path = package:get_install_path() .. "/netcoredbg" + local path = utils.join_paths(package:get_install_path(), "netcoredbg") dap.adapters.coreclr = { type = "executable", diff --git a/lua/csharp/utils.lua b/lua/csharp/utils.lua index 3850955..09529ff 100644 --- a/lua/csharp/utils.lua +++ b/lua/csharp/utils.lua @@ -48,4 +48,12 @@ function M.run_async(fn) end end +--- @param paths to join +--- @return string with combined paths +function M.join_paths(...) + local separator = package.config:sub(1, 1) + local paths = {...} + return table.concat(paths, separator) +end + return M diff --git a/tests/utils_spec.lua b/tests/utils_spec.lua index cb395fe..17edd4c 100644 --- a/tests/utils_spec.lua +++ b/tests/utils_spec.lua @@ -101,3 +101,24 @@ describe("omnisharp_text_changes_to_text_edits", function() assert.are.same(expected, result) end) end) + +describe("join_paths", function() + local test_cases = { + { sep = "/", input = {"home", "user", "docs"}, expected = "home/user/docs", desc = "Linux-style" }, + { sep = "\\", input = {"C:", "Users", "User"}, expected = "C:\\Users\\User", desc = "Windows-style" }, + { sep = "/", input = {"var", "log", "app"}, expected = "var/log/app", desc = "Another Linux" } + } + + for _, case in ipairs(test_cases) do + it("should join the paths in: " .. case.desc, function() + local original_config = package.config + package.config = case.sep .. "\n" + + local result = utils.join_paths(table.unpack(case.input)) + + assert.are.equal(case.expected, result) + + package.config = original_config + end) + end +end) From 33cc4ca719f2cb89730fd685887269b514eb0802 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Martins?= Date: Mon, 31 Mar 2025 21:28:22 -0300 Subject: [PATCH 2/7] =?UTF-8?q?=F0=9F=90=9B=20Fix=20join=20paths=20based?= =?UTF-8?q?=20on=20OS?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lua/csharp/features/user-secrets/init.lua | 2 +- lua/csharp/modules/launch-settings.lua | 3 ++- lua/csharp/modules/lsp/omnisharp.lua | 3 ++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lua/csharp/features/user-secrets/init.lua b/lua/csharp/features/user-secrets/init.lua index 5b3cf92..180eae4 100644 --- a/lua/csharp/features/user-secrets/init.lua +++ b/lua/csharp/features/user-secrets/init.lua @@ -8,7 +8,7 @@ local _lua_pattern_guid = "%w+-%w+-%w+-%w+-%w+" -- Creates the user secret file if the same -- doesn't exists local function _ensure_secret_exists(user_secret_folder_path) - local full_file_path = user_secret_folder_path .. "/secrets.json" + local full_file_path = utils.join_paths(user_secret_folder_path, "secrets.json") local file, _ = io.open(full_file_path, "r+") if not file then diff --git a/lua/csharp/modules/launch-settings.lua b/lua/csharp/modules/launch-settings.lua index 414083d..9cea012 100644 --- a/lua/csharp/modules/launch-settings.lua +++ b/lua/csharp/modules/launch-settings.lua @@ -1,6 +1,7 @@ local M = {} local logger = require("csharp.log") local ui = require("csharp.ui") +local utils = require("csharp.utils") --- @class DotNetLaunchProfile --- @field name string @@ -32,7 +33,7 @@ end --- @param project_folder string --- @return DotNetLaunchProfile[] local function get_launch_profiles(project_folder) - local file_name = project_folder .. "/Properties/launchSettings.json" + local file_name = utils.join_paths(project_folder, "Properties", "launchSettings.json") local launch_settings = readFileWithoutBom(file_name) if launch_settings == nil then diff --git a/lua/csharp/modules/lsp/omnisharp.lua b/lua/csharp/modules/lsp/omnisharp.lua index 053d946..9eafc7c 100644 --- a/lua/csharp/modules/lsp/omnisharp.lua +++ b/lua/csharp/modules/lsp/omnisharp.lua @@ -1,5 +1,6 @@ local M = {} local config_store = require("csharp.config") +local utils = require("csharp.utils") --- @return string --- @param buffer number @@ -34,7 +35,7 @@ local function get_omnisharp_cmd() package:install() end - return package:get_install_path() .. "/omnisharp" + return utils.join_paths(package:get_install_path(), "omnisharp") end local function start_omnisharp(buffer) From 120940d83ff449c5d2b0af79802008edcfa7af85 Mon Sep 17 00:00:00 2001 From: Yarik Popov <89220488+Yarik-Popov@users.noreply.github.com> Date: Mon, 14 Apr 2025 17:27:24 -0400 Subject: [PATCH 3/7] fix windows file executable difference --- lua/csharp/modules/dap.lua | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lua/csharp/modules/dap.lua b/lua/csharp/modules/dap.lua index bb5145c..156834d 100644 --- a/lua/csharp/modules/dap.lua +++ b/lua/csharp/modules/dap.lua @@ -23,6 +23,12 @@ function M.get_debug_adapter() package:install() end + -- Netcoredbg puts the executable in a different spot + local exec_path = {"netcoredbg"} + if vim.loop.os_uname().sysname == "Windows_NT" then + exec_path[#exec_path+1] = "netcoredbg.exe" + end + local path = utils.join_paths(package:get_install_path(), "netcoredbg") dap.adapters.coreclr = { From 1815d9b763e40c47ec459f890469cd498d68c713 Mon Sep 17 00:00:00 2001 From: Yarik Popov <89220488+Yarik-Popov@users.noreply.github.com> Date: Mon, 14 Apr 2025 17:32:03 -0400 Subject: [PATCH 4/7] actually use the exec_path --- lua/csharp/modules/dap.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/csharp/modules/dap.lua b/lua/csharp/modules/dap.lua index 156834d..d26374f 100644 --- a/lua/csharp/modules/dap.lua +++ b/lua/csharp/modules/dap.lua @@ -29,7 +29,7 @@ function M.get_debug_adapter() exec_path[#exec_path+1] = "netcoredbg.exe" end - local path = utils.join_paths(package:get_install_path(), "netcoredbg") + local path = utils.join_paths(package:get_install_path(), exec_path) dap.adapters.coreclr = { type = "executable", From 530401b4dbeafdfedb0b29bdb48b1d06aceb26b3 Mon Sep 17 00:00:00 2001 From: Yarik Popov <89220488+Yarik-Popov@users.noreply.github.com> Date: Wed, 16 Apr 2025 14:19:12 -0400 Subject: [PATCH 5/7] temp fix --- lua/csharp/utils.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/csharp/utils.lua b/lua/csharp/utils.lua index 09529ff..ec1238f 100644 --- a/lua/csharp/utils.lua +++ b/lua/csharp/utils.lua @@ -51,7 +51,7 @@ end --- @param paths to join --- @return string with combined paths function M.join_paths(...) - local separator = package.config:sub(1, 1) + local separator = "/" local paths = {...} return table.concat(paths, separator) end From 2d99f9ce1844cf823fc31040a4272d230c573a97 Mon Sep 17 00:00:00 2001 From: Yarik Popov <89220488+Yarik-Popov@users.noreply.github.com> Date: Wed, 16 Apr 2025 14:31:27 -0400 Subject: [PATCH 6/7] fix: argument of type table to utils.join_paths --- lua/csharp/modules/dap.lua | 6 +++--- lua/csharp/utils.lua | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lua/csharp/modules/dap.lua b/lua/csharp/modules/dap.lua index d26374f..c2f9968 100644 --- a/lua/csharp/modules/dap.lua +++ b/lua/csharp/modules/dap.lua @@ -23,13 +23,13 @@ function M.get_debug_adapter() package:install() end + local exec_path = {package:get_install_path(), "netcoredbg"} -- Netcoredbg puts the executable in a different spot - local exec_path = {"netcoredbg"} if vim.loop.os_uname().sysname == "Windows_NT" then exec_path[#exec_path+1] = "netcoredbg.exe" end - - local path = utils.join_paths(package:get_install_path(), exec_path) + + local path = utils.join_paths(table.unpack(exec_path)) dap.adapters.coreclr = { type = "executable", diff --git a/lua/csharp/utils.lua b/lua/csharp/utils.lua index ec1238f..09529ff 100644 --- a/lua/csharp/utils.lua +++ b/lua/csharp/utils.lua @@ -51,7 +51,7 @@ end --- @param paths to join --- @return string with combined paths function M.join_paths(...) - local separator = "/" + local separator = package.config:sub(1, 1) local paths = {...} return table.concat(paths, separator) end From 53d140ae633e291429cf4c1b51a606a29bc0379d Mon Sep 17 00:00:00 2001 From: Yarik Popov <89220488+Yarik-Popov@users.noreply.github.com> Date: Wed, 16 Apr 2025 14:35:52 -0400 Subject: [PATCH 7/7] fix: undefined table.unpack --- lua/csharp/modules/dap.lua | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lua/csharp/modules/dap.lua b/lua/csharp/modules/dap.lua index c2f9968..5345626 100644 --- a/lua/csharp/modules/dap.lua +++ b/lua/csharp/modules/dap.lua @@ -23,14 +23,13 @@ function M.get_debug_adapter() package:install() end - local exec_path = {package:get_install_path(), "netcoredbg"} + local path = utils.join_paths(package:get_install_path(), "netcoredbg") + -- Netcoredbg puts the executable in a different spot if vim.loop.os_uname().sysname == "Windows_NT" then - exec_path[#exec_path+1] = "netcoredbg.exe" + path = utils.join_paths(path, "netcoredbg.exe") end - local path = utils.join_paths(table.unpack(exec_path)) - dap.adapters.coreclr = { type = "executable", command = path,