Skip to content

Commit 35822de

Browse files
committed
fix): fix nvim-treesitter compilation by standardizing separators
Overrode vim.fn.stdpath with a normalized _G.join_path implementation to prevent CMD.exe from misinterpreting forward slashes as command switches.
1 parent 8137ee5 commit 35822de

4 files changed

Lines changed: 31 additions & 18 deletions

File tree

init.lua

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,43 @@
11
vim.g.mapleader = " "
22
vim.g.maplocalleader = " "
3-
vim.g.is_wsl = vim.fn.isdirectory("/mnt/c")
4-
vim.g.is_win = vim.fn.has("win32")
5-
vim.g.is_tmux = vim.fn.exists("$TMUX")
3+
vim.g.is_wsl = vim.fn.isdirectory("/mnt/c") == 1
4+
vim.g.is_win = vim.fn.has("win32") == 1
5+
vim.g.is_tmux = vim.fn.exists("$TMUX") == 1
6+
7+
print(vim.g.is_win2)
8+
function _G.join_path(...)
9+
local sep = vim.g.is_win and "\\" or "/"
10+
-- 1. Concatenate all arguments using the system separator
11+
local path = table.concat({ ... }, sep)
12+
if vim.g.is_win then
13+
-- Convert all forward slashes to backslashes
14+
path = path:gsub("/", "\\")
15+
path = path:gsub("\\\\+", "\\")
16+
else
17+
path = path:gsub("//+", "/")
18+
end
19+
return path
20+
end
621

722
-- set dir path {{{
823
vim.g.config_dir = vim.fn.fnamemodify(vim.fn.resolve(vim.fn.expand("<sfile>:p")), ":h")
924
vim.opt.rtp:prepend(vim.g.config_dir)
1025
vim.g.runtime_dir = vim.fs.joinpath(vim.g.config_dir, ".run")
1126

12-
local env_separator = vim.g.is_win == 1 and ";" or ":"
27+
local env_separator = vim.g.is_win and ";" or ":"
1328
vim.env.PATH = vim.fs.joinpath(vim.g.config_dir, "vendor") .. env_separator .. vim.env.PATH
1429

1530
local original_stdpath = vim.fn.stdpath
1631
---@diagnostic disable-next-line: duplicate-set-field
1732
vim.fn.stdpath = function(what)
1833
local path_map = {
19-
config = vim.fs.joinpath(vim.g.runtime_dir, "config"),
20-
state = vim.fs.joinpath(vim.g.runtime_dir, "state"),
21-
cache = vim.fs.joinpath(vim.g.runtime_dir, "cache"),
22-
log = vim.fs.joinpath(vim.g.runtime_dir, "log"),
23-
run = vim.fs.joinpath(vim.g.runtime_dir, "run"),
34+
config = join_path(vim.g.runtime_dir, "config"),
35+
data = join_path(vim.g.runtime_dir, "data"),
36+
state = join_path(vim.g.runtime_dir, "state"),
37+
cache = join_path(vim.g.runtime_dir, "cache"),
38+
log = join_path(vim.g.runtime_dir, "log"),
39+
run = join_path(vim.g.runtime_dir, "run"),
2440
}
25-
if vim.g.is_win == 0 then
26-
path_map.data = vim.fs.joinpath(vim.g.runtime_dir, "data")
27-
end
2841

2942
if path_map[what] then
3043
return path_map[what]
@@ -36,7 +49,7 @@ vim.fn.stdpath = function(what)
3649
return { path_map.data }
3750
end
3851

39-
-- print(what)
52+
print(what)
4053
return original_stdpath(what)
4154
end
4255
vim.o.shadafile = vim.fs.joinpath(vim.fn.stdpath("state"), "shadafile")

lua/config/option.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ g.has_go = fn.executable("go")
77

88
vim.api.nvim_create_augroup("myau", { clear = true })
99

10-
if g.is_win == 1 then
10+
if g.is_win then
1111
g.make = "mingw32-make"
1212
else
1313
g.make = "make"
@@ -96,7 +96,7 @@ opt.wrap = true
9696
opt.whichwrap = opt.whichwrap + "<,>,[,],h,l"
9797

9898
-- terminal {{{
99-
if g.is_win == 0 then
99+
if not g.is_win then
100100
vim.o.shellcmdflag = "-ic"
101101
end
102102

@@ -170,7 +170,7 @@ vim.api.nvim_create_autocmd("VimLeave", {
170170
})
171171

172172
-- osc52 clip {{{
173-
if g.is_tmux == 1 then
173+
if g.is_tmux then
174174
vim.g.clipboard = {
175175
name = "tmux",
176176
copy = {

lua/plugins/ZFVimIM.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ return {
1212

1313
local db_file = "vim_wubi.txt"
1414
local repo_path
15-
if vim.g.is_win == 1 then
15+
if vim.g.is_win then
1616
repo_path = "d:/sync/tool/rime"
1717
else
1818
repo_path = vim.fn.expand("~/sync/tool/rime")

lua/plugins/luasnip.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ end
99
return {
1010
"L3MON4D3/LuaSnip",
1111
version = "v2.*",
12-
build = (vim.g.is_win == 0) and vim.g.make .. " install_jsregexp" or nil,
12+
build = vim.g.is_win and nil or vim.g.make .. " install_jsregexp",
1313
config = luasnip_opts,
1414
dependencies = { "rafamadriz/friendly-snippets" }
1515
}

0 commit comments

Comments
 (0)