Skip to content

Commit

Permalink
bug fix: some config won't have effect
Browse files Browse the repository at this point in the history
  • Loading branch information
Civitasv committed Nov 2, 2022
1 parent 90a84f7 commit 14603f0
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 14 deletions.
5 changes: 2 additions & 3 deletions lua/cmake-tools/config.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
local Path = require("plenary.path")
local scandir = require("plenary.scandir")
local const = require("cmake-tools.const")
local Result = require("cmake-tools.result")
local utils = require("cmake-tools.utils")
local Types = require("cmake-tools.types")
Expand All @@ -16,7 +15,7 @@ local Config = {
launch_target = nil,
}

function Config:new()
function Config:new(const)
local obj = {}
setmetatable(obj, self)
self.__index = self
Expand Down Expand Up @@ -168,7 +167,7 @@ function Config:validate_for_debugging()
if build_type ~= "Debug" and build_type ~= "RelWithDebInfo" then
utils.error(
"For debugging you need to use Debug or RelWithDebInfo, but currently your build type is "
.. build_type
.. build_type
)
return Result:new(Types.CANNOT_DEBUG_LAUNCH_TARGET, false, "cannot debug it")
end
Expand Down
21 changes: 17 additions & 4 deletions lua/cmake-tools/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ local const = require("cmake-tools.const")
local Config = require("cmake-tools.config")
local variants = require("cmake-tools.variants")

local config = Config:new()
local config

local cmake = {}

--- Setup cmake-tools
function cmake.setup(values)
const = vim.tbl_deep_extend("force", const, values)
config = Config:new(const)
end

--- Generate build system for this project.
Expand Down Expand Up @@ -52,6 +53,8 @@ function cmake.generate(opt, callback)
callback()
end
end,
cmake_show_console = const.cmake_show_console,
cmake_console_size = const.cmake_console_size
})
end

Expand All @@ -74,6 +77,8 @@ function cmake.clean(callback)
callback()
end
end,
cmake_show_console = const.cmake_show_console,
cmake_console_size = const.cmake_console_size
})
end

Expand All @@ -88,7 +93,6 @@ function cmake.build(opt, callback)
if result.code ~= Types.SUCCESS then
return utils.error(result.message)
end
-- print("BUILD")

local fargs = opt.fargs or {}

Expand Down Expand Up @@ -135,6 +139,8 @@ function cmake.build(opt, callback)
callback()
end
end,
cmake_show_console = const.cmake_show_console,
cmake_console_size = const.cmake_console_size
})
end

Expand Down Expand Up @@ -170,7 +176,10 @@ function cmake.install(opt)
local fargs = opt.fargs

vim.list_extend(fargs, { "--install", config.build_directory.filename })
return utils.run(const.cmake_command, fargs)
return utils.run(const.cmake_command, fargs, {
cmake_show_console = const.cmake_show_console,
cmake_console_size = const.cmake_console_size
})
end

--- CMake close cmake console
Expand Down Expand Up @@ -217,7 +226,11 @@ function cmake.run(opt, callback)
local target_path = result.data
-- print("TARGET", target_path)

return utils.execute(target_path, { bufname = vim.fn.expand("%:t:r") })
return utils.execute(target_path, {
bufname = vim.fn.expand("%:t:r"),
cmake_console_position = const.cmake_console_position,
cmake_console_size = const.cmake_console_size
})
end)
end)
end
Expand Down
13 changes: 6 additions & 7 deletions lua/cmake-tools/utils.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
local Job = require("plenary.job")
local Path = require("plenary.path")
local const = require("cmake-tools.const")
local Result = require("cmake-tools.result")
local Types = require("cmake-tools.types")

Expand Down Expand Up @@ -36,8 +35,8 @@ function utils.dump(o)
end
end

function utils.show_cmake_console()
vim.api.nvim_command("copen " .. const.cmake_console_size)
function utils.show_cmake_console(cmake_console_size)
vim.api.nvim_command("copen " .. cmake_console_size)
vim.api.nvim_command("wincmd j")
end

Expand All @@ -57,7 +56,7 @@ end
function utils.execute(executable, opts)
-- print("EXECUTABLE", executable)
local set_bufname = "file " .. opts.bufname
local prefix = string.format("%s %d new", const.cmake_console_position, const.cmake_console_size)
local prefix = string.format("%s %d new", opts.cmake_console_position, opts.cmake_console_size)

vim.api.nvim_command("cclose")
vim.cmd(prefix .. " | term " .. executable)
Expand Down Expand Up @@ -92,9 +91,9 @@ end
-- Execute CMake command using job api
function utils.run(cmd, args, opts)
vim.fn.setqflist({}, " ", { title = cmd .. " " .. table.concat(args, " ") })
opts.cmake_show_console = const.cmake_show_console == "always"
opts.cmake_show_console = opts.cmake_show_console == "always"
if opts.cmake_show_console then
utils.show_cmake_console()
utils.show_cmake_console(opts.cmake_console_size)
end

utils.job = Job:new({
Expand All @@ -110,7 +109,7 @@ function utils.run(cmd, args, opts)
opts.on_success()
end
elseif opts.cmake_show_console == "only_on_error" then
utils.show_cmake_console()
utils.show_cmake_console(opts.cmake_console_size)
vim.api.nvim_command("cbottom")
end
end),
Expand Down

0 comments on commit 14603f0

Please sign in to comment.