Update rust.lua
This commit is contained in:
+17
-20
@@ -1,18 +1,16 @@
|
|||||||
local M = {}
|
local M = {}
|
||||||
M.close_key = nil
|
M.close_key = nil
|
||||||
M.c_build = nil
|
M.rust_build = nil
|
||||||
M.c_run = nil
|
M.rust_run = nil
|
||||||
M.new_c_file = nil
|
M.new_rust_file = nil
|
||||||
M.new_c_header_file = nil
|
|
||||||
|
|
||||||
M.config = {
|
M.config = {
|
||||||
project_root = "~/Projects/C",
|
project_root = "~/Projects/Rust",
|
||||||
keybinds = {
|
keybinds = {
|
||||||
["<Esc>"] = "CloseTerminal",
|
["<Esc>"] = "CloseTerminal",
|
||||||
["<leader>pb"] = "CBuild",
|
["<leader>pb"] = "RustBuild",
|
||||||
["<leader>pr"] = "CRun",
|
["<leader>pr"] = "RustRun",
|
||||||
["<leader>nf"] = "NewCFile",
|
["<leader>nf"] = "NewRustFile",
|
||||||
["<leader>nh"] = "NewCHeaderFile",
|
|
||||||
},
|
},
|
||||||
terminal = {
|
terminal = {
|
||||||
right_padding = 0,
|
right_padding = 0,
|
||||||
@@ -30,21 +28,19 @@ function M.setup(opts)
|
|||||||
M.config = vim.tbl_deep_extend("force", M.config, opts or {})
|
M.config = vim.tbl_deep_extend("force", M.config, opts or {})
|
||||||
for key, command in pairs(M.config.keybinds) do
|
for key, command in pairs(M.config.keybinds) do
|
||||||
if command == "CloseTerminal" then M.close_key = key end
|
if command == "CloseTerminal" then M.close_key = key end
|
||||||
if command == "CBuild" then M.c_build = key end
|
if command == "RustBuild" then M.rust_build = key end
|
||||||
if command == "CRun" then M.c_run = key end
|
if command == "RustRun" then M.rust_run = key end
|
||||||
if command == "NewCFile" then M.new_c_file = key end
|
if command == "NewRustFile" then M.new_rust_file = key end
|
||||||
if command == "NewCHeaderFile" then M.new_c_header_file = key end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
vim.api.nvim_create_user_command("NewCHeaderFile", M.create_new_header_file, {})
|
vim.api.nvim_create_user_command("NewCHeaderFile", M.create_new_header_file, {})
|
||||||
vim.api.nvim_create_user_command("NewCFile", M.create_new_file, {})
|
vim.api.nvim_create_user_command("NewRustFile", M.create_new_file, {})
|
||||||
vim.api.nvim_create_user_command("CBuild", M.build, {})
|
vim.api.nvim_create_user_command("RustBuild", M.build, {})
|
||||||
vim.api.nvim_create_user_command("CRun", M.run, {})
|
vim.api.nvim_create_user_command("RustRun", M.run, {})
|
||||||
|
|
||||||
vim.keymap.set("n", M.c_build, ":CBuild<CR>", { silent = true })
|
vim.keymap.set("n", M.rust_build, ":RustBuild<CR>", { silent = true })
|
||||||
vim.keymap.set("n", M.c_run, ":CRun<CR>", { silent = true })
|
vim.keymap.set("n", M.rust_run, ":RustRun<CR>", { silent = true })
|
||||||
vim.keymap.set("n", M.new_c_file, ":NewCFile<CR>", { silent = true })
|
vim.keymap.set("n", M.new_rust_file, ":NewRustFile<CR>", { silent = true })
|
||||||
vim.keymap.set("n", M.new_c_header_file, ":NewCHeaderFile<CR>", { silent = true })
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.open_float_terminal(cmd)
|
function M.open_float_terminal(cmd)
|
||||||
@@ -97,6 +93,7 @@ function M.create_project()
|
|||||||
vim.ui.input({ prompt = "Enter project name: " }, function(project_name)
|
vim.ui.input({ prompt = "Enter project name: " }, function(project_name)
|
||||||
if not project_name or project_name == "" then return print("Project creation canceled.") end
|
if not project_name or project_name == "" then return print("Project creation canceled.") end
|
||||||
local project_root = vim.fn.expand(M.config.project_root) .. "/" .. project_name
|
local project_root = vim.fn.expand(M.config.project_root) .. "/" .. project_name
|
||||||
|
vim.fn.system("cargo new " .. project_root)
|
||||||
vim.cmd("edit " .. project_root .. "/src/main.rs")
|
vim.cmd("edit " .. project_root .. "/src/main.rs")
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user