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/dap.lua b/lua/csharp/modules/dap.lua index fc96f23..5345626 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,12 @@ 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") + + -- Netcoredbg puts the executable in a different spot + if vim.loop.os_uname().sysname == "Windows_NT" then + path = utils.join_paths(path, "netcoredbg.exe") + end dap.adapters.coreclr = { type = "executable", 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) 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)