chore: fixed create_file to take filetype over asking for language each
time as 97% of the time people (I) will want to make the same filetype instead
This commit is contained in:
@@ -1,5 +1,8 @@
|
|||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
|
---TODO
|
||||||
|
---Split filetype only and just change a filetype variable and vairables both share and then run the duplicate code
|
||||||
|
|
||||||
local utils = require("vern-nvim.utils")
|
local utils = require("vern-nvim.utils")
|
||||||
local templates = require("vern-nvim.templates")
|
local templates = require("vern-nvim.templates")
|
||||||
|
|
||||||
@@ -84,22 +87,18 @@ end
|
|||||||
|
|
||||||
M.create_file = function(opts)
|
M.create_file = function(opts)
|
||||||
opts = opts or {}
|
opts = opts or {}
|
||||||
vim.ui.input({
|
local filetype = vim.bo.filetype
|
||||||
prompt = "File language (e.g. python): ",
|
|
||||||
completion = "filetype",
|
local function continue_filetype(ft)
|
||||||
}, function(ft)
|
filetype = ft
|
||||||
ft = ft and vim.trim(ft)
|
local ok, actions = pcall(require, "vern-nvim.actions." .. filetype)
|
||||||
if not ft or vim.trim(ft) == "" then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
local ok, actions = pcall(require, "vern-nvim.actions." .. ft)
|
|
||||||
if not ok then
|
if not ok then
|
||||||
vim.notify("Unknown Filetype: " .. ft, vim.log.levels.WARN, {
|
vim.notify("Unknown Filetype: " .. filetype, vim.log.levels.WARN, {
|
||||||
title = "Vern File",
|
title = "Vern File",
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local configs = require("vern-nvim.configs." .. ft)
|
local configs = require("vern-nvim.configs." .. filetype)
|
||||||
local args = vim.tbl_deep_extend("force", {}, configs, opts or {})
|
local args = vim.tbl_deep_extend("force", {}, configs, opts or {})
|
||||||
|
|
||||||
vim.ui.input({ prompt = "Enter file name: " }, function(fname)
|
vim.ui.input({ prompt = "Enter file name: " }, function(fname)
|
||||||
@@ -110,7 +109,9 @@ M.create_file = function(opts)
|
|||||||
|
|
||||||
local mod
|
local mod
|
||||||
if ok and actions and type(actions.create_file) == "function" then
|
if ok and actions and type(actions.create_file) == "function" then
|
||||||
mod = actions.create_file(args[ft]) or args[ft].templates.file.source or {}
|
mod = actions.create_file(args[filetype])
|
||||||
|
or args[filetype].templates.file.source
|
||||||
|
or {}
|
||||||
end
|
end
|
||||||
local raw_path = vim.fs.joinpath(mod.path, mod.name)
|
local raw_path = vim.fs.joinpath(mod.path, mod.name)
|
||||||
local context = {
|
local context = {
|
||||||
@@ -118,7 +119,7 @@ M.create_file = function(opts)
|
|||||||
company_name = opts.env.author,
|
company_name = opts.env.author,
|
||||||
file_name = fname,
|
file_name = fname,
|
||||||
}
|
}
|
||||||
local path = utils.resolve_path(raw_path, args[ft].dirs or {}, context)
|
local path = utils.resolve_path(raw_path, args[filetype].dirs or {}, context)
|
||||||
local root = utils.proj_root()
|
local root = utils.proj_root()
|
||||||
utils.dump(
|
utils.dump(
|
||||||
vim.fs.joinpath(root, path),
|
vim.fs.joinpath(root, path),
|
||||||
@@ -127,7 +128,23 @@ M.create_file = function(opts)
|
|||||||
vim.cmd.edit(vim.fn.fnameescape(path))
|
vim.cmd.edit(vim.fn.fnameescape(path))
|
||||||
vim.notify(fname .. " has been created!", vim.log.levels.INFO, { title = "Vern File" })
|
vim.notify(fname .. " has been created!", vim.log.levels.INFO, { title = "Vern File" })
|
||||||
end)
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
local ft_ok, ft_config = pcall(require, "vern-nvim.configs." .. filetype)
|
||||||
|
if not filetype or filetype == "" or not ft_ok or type(ft_config) ~= "table" then
|
||||||
|
vim.ui.input({
|
||||||
|
prompt = "File language (e.g. python): ",
|
||||||
|
completion = "filetype",
|
||||||
|
}, function(ft)
|
||||||
|
ft = ft and vim.trim(ft)
|
||||||
|
if not ft or vim.trim(ft) == "" then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
continue_filetype(ft)
|
||||||
end)
|
end)
|
||||||
|
else
|
||||||
|
continue_filetype(filetype)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|||||||
Reference in New Issue
Block a user