Skip to content

Commit

Permalink
Fix cpp build in neovim
Browse files Browse the repository at this point in the history
  • Loading branch information
JafarAbdi committed Jan 20, 2025
1 parent 22a2561 commit 6d18138
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 36 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ mynotes
scripts/.local/bin/rgr
scripts/.local/bin/pixi
scripts/.local/bin/stylua
neovim/.config/nvim/spell/
73 changes: 38 additions & 35 deletions neovim/.config/nvim/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -307,44 +307,47 @@ local runners = {
end,
c = function(file_path, root_dir, _)
local vscode_root_dir = vim.fs.root(file_path, { ".vscode" })
local cmake_settings_filename = vim.fs.joinpath(vscode_root_dir, ".vscode", "settings.json")
if vim.uv.fs_stat(cmake_settings_filename) then
local settings = vim.fn.json_decode(vim.fn.readfile(cmake_settings_filename))
local build_directory = settings["cmake.buildDirectory"]
local reply_directory = vim.fs.joinpath(build_directory, ".cmake", "api", "v1", "reply")
local indices = vim.fs.find(function(name, _)
return name:match("^index%-.*%.json$")
end, { path = reply_directory, limit = math.huge })
if #indices == 0 then
vim.notify("No index files found in " .. reply_directory, vim.log.levels.WARN)
return
end
assert(#indices == 1, "Expected exactly one index file")
local index = vim.fn.json_decode(vim.fn.readfile(indices[1]))
local response = index["reply"]["codemodel-v2"]
local codemodel =
vim.fn.json_decode(vim.fn.readfile(vim.fs.joinpath(reply_directory, response["jsonFile"])))
local targets = {}
for _, target_config in ipairs(codemodel["configurations"][1]["targets"]) do
local target = vim.fn.json_decode(
vim.fn.readfile(vim.fs.joinpath(reply_directory, target_config["jsonFile"]))
if vscode_root_dir then
local cmake_settings_filename = vim.fs.joinpath(vscode_root_dir, ".vscode", "settings.json")
if vim.uv.fs_stat(cmake_settings_filename) then
local settings = vim.fn.json_decode(vim.fn.readfile(cmake_settings_filename))
local build_directory = settings["cmake.buildDirectory"]
local reply_directory = vim.fs.joinpath(build_directory, ".cmake", "api", "v1", "reply")
local indices = vim.fs.find(function(name, _)
return name:match("^index%-.*%.json$")
end, { path = reply_directory, limit = math.huge })
if #indices == 0 then
vim.notify("No index files found in " .. reply_directory, vim.log.levels.WARN)
return
end
assert(#indices == 1, "Expected exactly one index file")
local index = vim.fn.json_decode(vim.fn.readfile(indices[1]))
local response = index["reply"]["codemodel-v2"]
local codemodel = vim.fn.json_decode(
vim.fn.readfile(vim.fs.joinpath(reply_directory, response["jsonFile"]))
)
if target["type"] == "EXECUTABLE" then
targets[vim.fs.joinpath(vscode_root_dir, target["sources"][1]["path"])] = {
name = target["name"],
path = vim.fs.joinpath(build_directory, target["artifacts"][1]["path"]),
}
local targets = {}
for _, target_config in ipairs(codemodel["configurations"][1]["targets"]) do
local target = vim.fn.json_decode(
vim.fn.readfile(vim.fs.joinpath(reply_directory, target_config["jsonFile"]))
)
if target["type"] == "EXECUTABLE" then
targets[vim.fs.joinpath(vscode_root_dir, target["sources"][1]["path"])] = {
name = target["name"],
path = vim.fs.joinpath(build_directory, target["artifacts"][1]["path"]),
}
end
end
return {
"cmake",
"--build",
build_directory,
"--target",
targets[file_path].name,
"&&",
targets[file_path].path,
}
end
return {
"cmake",
"--build",
build_directory,
"--target",
targets[file_path].name,
"&&",
targets[file_path].path,
}
end
local output = vim.fn.tempname()

Expand Down
2 changes: 1 addition & 1 deletion wezterm/.config/wezterm/wezterm.lua
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ wezterm.on("bell", function(window, pane)
if window:is_focused() and window:active_pane():pane_id() == pane:pane_id() then
return
end
window:toast_notification("wezterm", "Bell in pane '" .. pane:get_title() .. "'", nil, 5000)
window:toast_notification("wezterm", "Bell in pane '" .. pane:get_title() .. "'", nil, 2500)
end)

return config

0 comments on commit 6d18138

Please sign in to comment.