Skip to content

Commit f3e1a7f

Browse files
authored
fix: invalid data dir name generated on windows (#66)
1 parent 44272f8 commit f3e1a7f

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

lua/java-core/ls/servers/jdtls/utils.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ local M = {}
77
---Returns the workspace directory path based on the current dir
88
---@return string
99
function M.get_workspace_path()
10-
local project_path =
11-
string.gsub(vim.fn.fnamemodify(vim.fn.getcwd(), ':p:h'), '/', '_')
10+
local project_path = vim.fn.fnamemodify(vim.fn.getcwd(), ':p:h')
11+
local project_path_hash = string.gsub(project_path, '[/\\:+-]', '_')
1212

1313
local nvim_cache_path = vim.fn.stdpath('cache')
14-
return join(nvim_cache_path, 'jdtls', 'workspaces', project_path)
14+
return join(nvim_cache_path, 'jdtls', 'workspaces', project_path_hash)
1515
end
1616

1717
---Returns the jdtls config cache directory

lua/java-core/utils/path.lua

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
local M = {}
22

3+
if vim.fn.has('win32') == 1 or vim.fn.has('win32unix') == 1 then
4+
M.path_separator = '\\'
5+
else
6+
M.path_separator = '/'
7+
end
8+
39
---Join a given list of paths to one path
410
---@param ... string paths to join
511
---@return string # joined path
612
function M.join(...)
7-
return table.concat({ ... }, '/')
13+
return table.concat({ ... }, M.path_separator)
814
end
915

1016
return M

0 commit comments

Comments
 (0)