FIX: fixed lua to not use global function but local to stop nil error
This commit is contained in:
@@ -6,12 +6,13 @@ M.opts = nil
|
|||||||
|
|
||||||
function M.setup(opts)
|
function M.setup(opts)
|
||||||
M.opts = vim.tbl_deep_extend("force", {}, require("Polydev.configs").get("cpp"), opts or {})
|
M.opts = vim.tbl_deep_extend("force", {}, require("Polydev.configs").get("cpp"), opts or {})
|
||||||
|
vim.api.nvim_create_user_command("NewCppHeaderFile", M.create_new_header_file, {})
|
||||||
|
vim.api.nvim_create_user_command("CppRun", M.run, {})
|
||||||
|
|
||||||
for key, command in pairs(M.opts.keybinds) do
|
for key, command in pairs(M.opts.keybinds) do
|
||||||
M.keybinds[command] = key
|
M.keybinds[command] = key
|
||||||
end
|
end
|
||||||
|
|
||||||
vim.api.nvim_create_user_command("NewCppHeaderFile", M.create_new_header_file, {})
|
|
||||||
vim.api.nvim_create_user_command("CppRun", M.run, {})
|
|
||||||
|
|
||||||
if M.keybinds.CppRun then
|
if M.keybinds.CppRun then
|
||||||
vim.keymap.set("n", M.keybinds.CppRun, ":CppRun<CR>", { silent = true })
|
vim.keymap.set("n", M.keybinds.CppRun, ":CppRun<CR>", { silent = true })
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ function M.run()
|
|||||||
|
|
||||||
---@return string
|
---@return string
|
||||||
local function get_project_name()
|
local function get_project_name()
|
||||||
return vim.fn.glob((M.get_project_root() or "") .. "/*.polydev"):match("([^/]+)%.polydev$")
|
return vim.fn.glob((get_project_root() or "") .. "/*.polydev"):match("([^/]+)%.polydev$")
|
||||||
end
|
end
|
||||||
|
|
||||||
---@return string
|
---@return string
|
||||||
|
|||||||
@@ -1,26 +1,18 @@
|
|||||||
---@module "Polydev.presets"
|
|
||||||
local presets = require("Polydev.presets")
|
local presets = require("Polydev.presets")
|
||||||
|
|
||||||
---@type table
|
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
---@type table
|
|
||||||
M.opts = {}
|
M.opts = {}
|
||||||
|
|
||||||
---@param opts table
|
|
||||||
function M.setup(opts)
|
function M.setup(opts)
|
||||||
M.opts = vim.tbl_deep_extend("force", {}, require("Polydev.configs").get("terminal"), opts or {})
|
M.opts = vim.tbl_deep_extend("force", {}, require("Polydev.configs").get("terminal"), opts or {})
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param path string
|
|
||||||
---@return boolean
|
|
||||||
function M.is_dir(path)
|
function M.is_dir(path)
|
||||||
local stat = vim.loop.fs_stat(path)
|
local stat = vim.loop.fs_stat(path)
|
||||||
return stat and stat.type == "directory"
|
return stat and stat.type == "directory"
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param path string
|
|
||||||
---@param content string
|
|
||||||
function M.write_file(path, content)
|
function M.write_file(path, content)
|
||||||
local file = assert(io.open(path, "w"), "Error creating file: " .. path)
|
local file = assert(io.open(path, "w"), "Error creating file: " .. path)
|
||||||
file:write(content)
|
file:write(content)
|
||||||
@@ -28,8 +20,6 @@ function M.write_file(path, content)
|
|||||||
vim.cmd("edit " .. path)
|
vim.cmd("edit " .. path)
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param cmd string
|
|
||||||
---@return boolean?, table?, nil?
|
|
||||||
function M.open_float_terminal(cmd)
|
function M.open_float_terminal(cmd)
|
||||||
local presets_opts = {}
|
local presets_opts = {}
|
||||||
if presets.getPresets(M.opts.presets) == nil then return nil end
|
if presets.getPresets(M.opts.presets) == nil then return nil end
|
||||||
|
|||||||
Reference in New Issue
Block a user