Adds function for running different projects

This commit is contained in:
Dennis Schoepf 2025-03-07 13:10:25 +01:00
parent 73e528266c
commit e538146c81
3 changed files with 12 additions and 16 deletions

6
flake.lock generated
View file

@ -44,11 +44,11 @@
},
"nixpkgs": {
"locked": {
"lastModified": 1740339700,
"narHash": "sha256-cbrw7EgQhcdFnu6iS3vane53bEagZQy/xyIkDWpCgVE=",
"lastModified": 1740865531,
"narHash": "sha256-h00vGIh/jxcGl8aWdfnVRD74KuLpyY3mZgMFMy7iKIc=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "04ef94c4c1582fd485bbfdb8c4a8ba250e359195",
"rev": "5ef6c425980847c78a80d759abc476e941a9bf42",
"type": "github"
},
"original": {

View file

@ -1,17 +1,12 @@
-- Map of file markers to their compile commands
local project_types = {
["main.odin"] = "odin build . -file",
["package.json"] = "npm run build",
["go.mod"] = "go build ./...",
["Cargo.toml"] = "cargo build",
["CMakeLists.txt"] = "cmake --build build",
["main.odin"] = "odin run .",
["package.json"] = "pnpm run dev",
["Makefile"] = "make",
}
local function find_project_type()
-- Search for known project markers in the current directory
for marker, _ in pairs(project_types) do
-- Use vim.fn.glob() to check if file exists in current directory
if vim.fn.glob(marker) ~= "" then
return marker
end
@ -19,7 +14,7 @@ local function find_project_type()
return nil
end
local function compile()
local function run()
local marker = find_project_type()
if not marker then
@ -40,5 +35,5 @@ local function compile()
end
return {
compile,
run,
}

View file

@ -48,7 +48,8 @@ return {
desc = "Delete all buffers",
mode = "n",
},
{ "<leader>c", group = "code", mode = "n" },
{ "<leader>c", group = "code/compile", mode = "n" },
{ "<leader>cr", "<cmd>lua require('dnsc.compile').run()<cr>", desc = "Run current project", mode = "n" },
{ "<leader>ca", "<cmd>FzfLua lsp_code_actions<cr>", desc = "Code actions", mode = "n" },
{ "<leader>cd", "<cmd>FzfLua diagnostics_document<cr>", desc = "Show diagnostics", mode = "n" },
{