Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lua/csharp/features/user-secrets/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion lua/csharp/modules/dap.lua
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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",
Expand Down
3 changes: 2 additions & 1 deletion lua/csharp/modules/launch-settings.lua
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion lua/csharp/modules/lsp/omnisharp.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
local M = {}
local config_store = require("csharp.config")
local utils = require("csharp.utils")

--- @return string
--- @param buffer number
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions lua/csharp/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
21 changes: 21 additions & 0 deletions tests/utils_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)