dotfiles/nvim/lua/helper/init.lua

39 lines
817 B
Lua
Raw Normal View History

local M = {}
function M.get_cmake_project_file()
return vim.fn.findfile('CMakeLists.txt', '.;')
end
function M.in_cmake_project()
return M.get_cmake_project_file() ~= ''
end
function M.get_cargo_project_file()
return vim.fn.findfile('Cargo.toml', '.;')
end
function M.in_cargo_project()
return M.get_cargo_project_file() ~= ''
end
2024-10-06 21:50:07 -04:00
function M.in_git_project()
return vim.fn.finddir('.git', '.;') ~= ''
end
2024-10-20 20:55:35 -04:00
-- TODO: is there some better way to do this?
-- TODO: also add `in_golang_project()` function to detect based on presence of go.mod file?
function M.is_golang_filetype()
return M.contains({ 'go', 'gomod', 'gosum', 'gotmpl' }, vim.bo.filetype)
end
2024-10-06 21:50:07 -04:00
function M.contains(tbl, v)
for i, value in ipairs(tbl) do
if value == v then
return true
end
end
return false
end
return M