From 9c302e35065a3a79a576c00733fc4ce963f24ed0 Mon Sep 17 00:00:00 2001 From: kalmenn Date: Thu, 12 Sep 2024 22:12:32 +0200 Subject: [PATCH] feat(languages): Add support for idris2 --- lazy-lock.json | 46 +++++------ lua/filetypes.lua | 1 + lua/plugins/languages/idris2.lua | 126 +++++++++++++++++++++++++++++++ 3 files changed, 151 insertions(+), 22 deletions(-) create mode 100644 lua/plugins/languages/idris2.lua diff --git a/lazy-lock.json b/lazy-lock.json index 4a8ede4..5914d10 100644 --- a/lazy-lock.json +++ b/lazy-lock.json @@ -2,32 +2,34 @@ "LuaSnip": { "branch": "master", "commit": "03c8e67eb7293c404845b3982db895d59c0d1538" }, "cmp-buffer": { "branch": "main", "commit": "3022dbc9166796b644a841a02de8dd1cc1d311fa" }, "cmp-cmdline": { "branch": "main", "commit": "d250c63aa13ead745e3a40f61fdd3470efde3923" }, - "cmp-nvim-lsp": { "branch": "main", "commit": "5af77f54de1b16c34b23cba810150689a3a90312" }, + "cmp-nvim-lsp": { "branch": "main", "commit": "39e2eda76828d88b773cc27a3f61d2ad782c922d" }, "cmp-path": { "branch": "main", "commit": "91ff86cd9c29299a64f968ebb45846c485725f23" }, "cmp_luasnip": { "branch": "master", "commit": "05a9ab28b53f71d1aece421ef32fee2cb857a843" }, - "crates.nvim": { "branch": "main", "commit": "8437522d12a8c523da2aee9db2979d070b2ecc33" }, - "fd": { "branch": "master", "commit": "bc6782624ef8d886c267c0f698e3895d9657df0e" }, - "feline.nvim": { "branch": "main", "commit": "2aa8b757313cc01f7779865bef7c7cc391753bd8" }, - "gitsigns.nvim": { "branch": "main", "commit": "035da036e68e509ed158414416c827d022d914bd" }, - "lazy.nvim": { "branch": "main", "commit": "3f13f080434ac942b150679223d54f5ca91e0d52" }, - "mason-lspconfig.nvim": { "branch": "main", "commit": "f3658bfc667df6a0340194a015ac2f31c1e675e0" }, + "crates.nvim": { "branch": "main", "commit": "1c924d5a9ea3496c4e1a02d0d51388ba809f8468" }, + "fd": { "branch": "master", "commit": "8e0bd33af7c31ce30d5f03b608bfb65f82a95b2b" }, + "feline.nvim": { "branch": "main", "commit": "c97c17dc56ca3cf2b9b9192c3447fc59347e8c0d" }, + "gitsigns.nvim": { "branch": "main", "commit": "1ef74b546732f185d0f806860fa5404df7614f28" }, + "idris2-nvim": { "branch": "main", "commit": "8bff02984a33264437e70fd9fff4359679d910da" }, + "lazy.nvim": { "branch": "main", "commit": "48b52b5cfcf8f88ed0aff8fde573a5cc20b1306d" }, + "mason-lspconfig.nvim": { "branch": "main", "commit": "25c11854aa25558ee6c03432edfa0df0217324be" }, "mason-null-ls.nvim": { "branch": "main", "commit": "de19726de7260c68d94691afb057fa73d3cc53e7" }, - "mason.nvim": { "branch": "main", "commit": "751b1fcbf3d3b783fcf8d48865264a9bcd8f9b10" }, + "mason.nvim": { "branch": "main", "commit": "e2f7f9044ec30067bc11800a9e266664b88cda22" }, "neo-tree-diagnostics.nvim": { "branch": "main", "commit": "e00434c3cf8637bcaf70f65c2b9d82b0cc9bd7dc" }, - "neo-tree.nvim": { "branch": "v3.x", "commit": "7aad1bf3f6b849cbf108e02c55ad4d701cb4d33a" }, - "neodev.nvim": { "branch": "main", "commit": "ce9a2e8eaba5649b553529c5498acb43a6c317cd" }, - "none-ls.nvim": { "branch": "main", "commit": "88821b67e6007041f43b802f58e3d9fa9bfce684" }, - "nui.nvim": { "branch": "main", "commit": "cbd2668414331c10039278f558630ed19b93e69b" }, - "nvim": { "branch": "main", "commit": "a1439ad7c584efb3d0ce14ccb835967f030450fe" }, - "nvim-cmp": { "branch": "main", "commit": "ce16de5665c766f39c271705b17fff06f7bcb84f" }, - "nvim-lspconfig": { "branch": "master", "commit": "ed8b8a15acc441aec669f97d75f2c1f2ac8c8aa5" }, - "nvim-metals": { "branch": "main", "commit": "4f9bf0c821092f20dd34c1a4ea5b07b0500ff089" }, - "nvim-treesitter": { "branch": "master", "commit": "c1d1b4084ef5239e2671f64d35962d184251aea4" }, - "nvim-web-devicons": { "branch": "master", "commit": "beb6367ab8496c9e43f22e0252735fdadae1872d" }, - "plenary.nvim": { "branch": "master", "commit": "5129a3693c482fcbc5ab99a7706ffc4360b995a0" }, - "ripgrep": { "branch": "master", "commit": "d922b7ac114c24d6800ae5f79d2967481f380c83" }, + "neo-tree.nvim": { "branch": "v3.x", "commit": "29f7c215332ba95e470811c380ddbce2cebe2af4" }, + "neodev.nvim": { "branch": "main", "commit": "46aa467dca16cf3dfe27098042402066d2ae242d" }, + "none-ls.nvim": { "branch": "main", "commit": "9b98991e15dce8fc502993e23caac2528b8b667f" }, + "nui.nvim": { "branch": "main", "commit": "61574ce6e60c815b0a0c4b5655b8486ba58089a1" }, + "nvim": { "branch": "main", "commit": "4fd72a9ab64b393c2c22b168508fd244877fec96" }, + "nvim-cmp": { "branch": "main", "commit": "ae644feb7b67bf1ce4260c231d1d4300b19c6f30" }, + "nvim-lspconfig": { "branch": "master", "commit": "bb682c167a0878338b4313b55538953d1c039085" }, + "nvim-metals": { "branch": "main", "commit": "1b87e6bfa4174b5fbaee9ca7ec79d8eae8df7f18" }, + "nvim-treesitter": { "branch": "master", "commit": "4af16a10b7f1e79275f712a1c6dcf725d301a303" }, + "nvim-web-devicons": { "branch": "master", "commit": "9154484705968658e9aab2b894d1b2a64bf9f83d" }, + "overseer.nvim": { "branch": "master", "commit": "236e60cdac6410dd95ea5cecafdb801a304d6a41" }, + "plenary.nvim": { "branch": "master", "commit": "ec289423a1693aeae6cd0d503bac2856af74edaa" }, + "ripgrep": { "branch": "master", "commit": "8bd595029656370927f846406ca4ce4ffe0b3e91" }, "rust-tools.nvim": { "branch": "master", "commit": "676187908a1ce35ffcd727c654ed68d851299d3e" }, - "telescope.nvim": { "branch": "0.1.x", "commit": "6312868392331c9c0f22725041f1ec2bef57c751" }, + "telescope.nvim": { "branch": "0.1.x", "commit": "a0bbec21143c7bc5f8bb02e0005fa0b982edc026" }, "undotree": { "branch": "master", "commit": "56c684a805fe948936cda0d1b19505b84ad7e065" }, - "vim-fugitive": { "branch": "master", "commit": "dac8e5c2d85926df92672bf2afb4fc48656d96c7" } + "vim-fugitive": { "branch": "master", "commit": "d4877e54cef67f5af4f950935b1ade19ed6b7370" } } \ No newline at end of file diff --git a/lua/filetypes.lua b/lua/filetypes.lua index d86482e..e3a98cb 100644 --- a/lua/filetypes.lua +++ b/lua/filetypes.lua @@ -9,5 +9,6 @@ vim.filetype.add({ vim.bo[bufnr].tabstop = 2 return "typst" end, + idr = "idris2", }, }) diff --git a/lua/plugins/languages/idris2.lua b/lua/plugins/languages/idris2.lua new file mode 100644 index 0000000..c179690 --- /dev/null +++ b/lua/plugins/languages/idris2.lua @@ -0,0 +1,126 @@ +local function get_ipkg_executable(ipkg_path) + local file = io.open(ipkg_path) + + if file == nil then + return nil + end + + for line in file:lines() do + local _, start = line:find("executable%s*=%s*\"") + + if start ~= nil then + file:close() + return line:sub(start + 1, #line - 1) + end + end + + file:close() + return nil +end + +local function setup_tasks() + local overseer = require("overseer") + + local generic_build_tmpl = { + name = "Idris2 Generic Build", + params = { + ipkg_path = { type = "string", optional = false, default = "./main.ipkg" }, + }, + builder = function(params) + return { + name = "Idris2: Build " .. params.ipkg_path, + cmd = { 'idris2', '--build', params.ipkg_path }, + components = { + { "on_exit_set_status", success_codes = { 0 } }, + }, + } + end, + } + + overseer.register_template(generic_build_tmpl) + + local generic_run_tmpl = { + name = "Idris2 Generic Run", + params = { + ipkg_path = { type = "string", optional = false, default = "./main.ipkg" }, + }, + builder = function(params) + local executable_name = get_ipkg_executable(params.ipkg_path) + + if params.ipkg_path == nil then + return nil + end + + return { + name = "Idris2: Run " .. params.ipkg_path, + cmd = { './build/exec/' .. executable_name }, + components = { + { + "dependencies", + task_names = { + { "Idris2 Generic Build", ipkg_path = params.ipkg_path }, + }, + sequential = true, + }, + { "on_exit_set_status", success_codes = { 0 } }, + }, + } + end, + } + + overseer.register_template(generic_run_tmpl) + + overseer.register_template { + name = "Idris2 compilation", + generator = function(_, cb) + local ipkg_paths = require('plenary.scandir').scan_dir( + '.', { search_pattern = '.+[.]ipkg$', } + ) + + local templates = {} + + for _, ipkg_path in pairs(ipkg_paths) do + templates:insert( + overseer.wrap_template( + generic_build_tmpl, + { name = "Build " .. ipkg_path}, + { ipkg_path = ipkg_path } + ) + ) + + templates:insert( + overseer.wrap_template( + generic_run_tmpl, + { name = "Run " .. ipkg_path }, + { ipkg_path = ipkg_path } + ) + ) + end + + cb(templates) + end, + } +end + +return { + "ShinKage/idris2-nvim", + requires = { + 'neovim/nvim-lspconfig', + 'MunifTanjim/nui.nvim', + 'stevearc/overseer.nvim', + 'nvim-lua/plenary.nvim', + }, + ft = { 'idris2', 'ipkg' }, + cond = function() + return vim.fn.executable("idris2") ~= 0 + and vim.fn.executable("idris2-lsp") ~= 0 + end, + opts = { + autostart_semantic = true, + }, + config = function(_, opts) + setup_tasks() + + require("idris2").setup(opts) + end, +}