diff --git a/home/private_dot_config/nvim/lua/config/autocmds.lua b/home/private_dot_config/nvim/lua/config/autocmds.lua index 220bfb2..053f67c 100644 --- a/home/private_dot_config/nvim/lua/config/autocmds.lua +++ b/home/private_dot_config/nvim/lua/config/autocmds.lua @@ -16,3 +16,27 @@ vim.api.nvim_create_autocmd({ "BufEnter", "BufWinEnter" }, { pattern = { "*.roc" }, command = "set filetype=roc", }) + +-- if cspell config found then disable buitlin spell check +vim.api.nvim_create_autocmd({"BufRead", "BufNewFile"}, { + pattern = "*", + callback = function() + -- this isn't exhuastive and won't work if config is contained in a package.json + local cspell_files = { + "cspell.json", + ".cspell.json", + "cSpell.json", + ".cSpell.json", + ".cspell.config.json", + "cpsell.config.yaml", + ".cpsell.config.yaml" + } + + for _, file in ipairs(cspell_files) do + if vim.fn.findfile(file, ".;") ~= "" then + vim.opt_local.spell = false + break + end + end + end +}) diff --git a/home/private_dot_config/nvim/lua/config/lazy.lua b/home/private_dot_config/nvim/lua/config/lazy.lua index a3e308b..7ebc458 100644 --- a/home/private_dot_config/nvim/lua/config/lazy.lua +++ b/home/private_dot_config/nvim/lua/config/lazy.lua @@ -1,3 +1,4 @@ +local import_if_exe = require("util").import_if_exe local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim" if not (vim.uv or vim.loop).fs_stat(lazypath) then local lazyrepo = "https://github.com/folke/lazy.nvim.git" @@ -25,22 +26,22 @@ require("lazy").setup({ { import = "plugins.disabled" }, { import = "plugins.host" }, { import = "plugins.ui" }, - -- { import = "plugins.language" }, - { import = "plugins.language.go" }, + + { import = "plugins.language.misc" }, { import = "plugins.language.lua" }, { import = "plugins.language.markdown" }, - { import = "plugins.language.misc" }, - { import = "plugins.language.nim" }, - { import = "plugins.language.nix" }, - require("util").if_exe("nu", { { import = "plugins.language.nu" } }), - { import = "plugins.language.python" }, - - -- { import = "plugins.language.roc" }, - { import = "plugins.language.rust" }, { import = "plugins.language.shell" }, + { import = "plugins.language.python" }, { import = "plugins.language.tex" }, - { import = "plugins.language.typst" }, - -- { import = "plugins.language.zig" }, + + import_if_exe("go", "plugins.language.go" ), + import_if_exe("nim", "plugins.language.nim"), + import_if_exe("nix" , "plugins.language.nix" ), + import_if_exe("nu", "plugins.language.nu" ), + import_if_exe("rust", "plugins.language.rust" ), + import_if_exe("typst", "plugins.language.typst" ), + -- import_if_exe("zig", "plugins.language.zig" ), + -- import_if_exe("roc", "plugins.language.roc" ), -- }, rocks = { diff --git a/home/private_dot_config/nvim/lua/plugins/builtins.lua b/home/private_dot_config/nvim/lua/plugins/builtins.lua index c2ebeba..ee6fba1 100644 --- a/home/private_dot_config/nvim/lua/plugins/builtins.lua +++ b/home/private_dot_config/nvim/lua/plugins/builtins.lua @@ -35,4 +35,34 @@ return { keymap = { preset = "default" }, }, }, + { + "mfussenegger/nvim-lint", + opts = { + -- cspell probably isn't installed globally? though could be with pnpm... + -- linters_by_ft = { + -- markdown = { "cspell" }, + -- }, + + -- LazyVim extension to easily override linter options + -- or add custom linters. + ---@type table + linters = { + -- -- Example of using selene only when a selene.toml file is present + -- selene = { + -- -- `condition` is another LazyVim extension that allows you to + -- -- dynamically enable/disable linters based on the context. + -- condition = function(ctx) + -- return vim.fs.find({ "selene.toml" }, { path = ctx.filename, upward = true })[1] + -- end, + -- }, + cspell = { + -- only works for one file type? + -- see lua/config/autocmds for a possible solution that includes more files + condition = function(ctx) + return vim.fs.find({".cspell.config.yaml"}, {path = ctx.filename, upward = true})[1] + end + } + }, + }, + }, } diff --git a/home/private_dot_config/nvim/lua/plugins/disabled.lua b/home/private_dot_config/nvim/lua/plugins/disabled.lua index ad40dd0..eab46d8 100644 --- a/home/private_dot_config/nvim/lua/plugins/disabled.lua +++ b/home/private_dot_config/nvim/lua/plugins/disabled.lua @@ -7,7 +7,7 @@ local function disable(plugins) end return disable({ - "mfussenegger/nvim-lint", + -- "mfussenegger/nvim-lint", "folke/tokyonight.nvim", -- snippets are wildly really annoying "L3MON4D3/LuaSnip", diff --git a/home/private_dot_config/nvim/lua/plugins/language/go.lua b/home/private_dot_config/nvim/lua/plugins/language/go.lua index 2fad189..8614f29 100644 --- a/home/private_dot_config/nvim/lua/plugins/language/go.lua +++ b/home/private_dot_config/nvim/lua/plugins/language/go.lua @@ -1,5 +1,5 @@ -- adapted from https://www.lazyvim.org/extras/lang/go -return require("util").if_exe("go", { +return { { "nvim-treesitter/nvim-treesitter", opts = function(_, opts) @@ -97,4 +97,4 @@ return require("util").if_exe("go", { }, }, }, -}) +} diff --git a/home/private_dot_config/nvim/lua/plugins/language/janet.lua b/home/private_dot_config/nvim/lua/plugins/language/janet.lua new file mode 100644 index 0000000..5df59a0 --- /dev/null +++ b/home/private_dot_config/nvim/lua/plugins/language/janet.lua @@ -0,0 +1,3 @@ +return { + require("util").setup_lang({ treesitter = { "janet_simple" } }), +} diff --git a/home/private_dot_config/nvim/lua/plugins/language/nim.lua b/home/private_dot_config/nvim/lua/plugins/language/nim.lua index 49d0f3b..a248b49 100644 --- a/home/private_dot_config/nvim/lua/plugins/language/nim.lua +++ b/home/private_dot_config/nvim/lua/plugins/language/nim.lua @@ -1,16 +1,14 @@ -local util = require("util") - -return util.if_exe("nim", { - util.setup_lang({ treesitter = { "nim", "nim_format_string" } }), +return { + require("util").setup_lang({ treesitter = { "nim", "nim_format_string" }, lsp = { "nim_langserver" } }), { "alaviss/nim.nvim" }, - { - "neovim/nvim-lspconfig", - opts = { - servers = { - nim_langserver = { - mason = false, - }, - }, - }, - }, -}) + -- { + -- "neovim/nvim-lspconfig", + -- opts = { + -- servers = { + -- nim_langserver = { + -- mason = false, + -- }, + -- }, + -- }, + -- }, +} diff --git a/home/private_dot_config/nvim/lua/plugins/language/nix.lua b/home/private_dot_config/nvim/lua/plugins/language/nix.lua index 92bf259..1a2f52c 100644 --- a/home/private_dot_config/nvim/lua/plugins/language/nix.lua +++ b/home/private_dot_config/nvim/lua/plugins/language/nix.lua @@ -1,6 +1,5 @@ -local util = require("util") -return util.if_exe("nix", { - util.setup_lang({ treesitter = { "nix" } }), +return { + require("util").setup_lang({ treesitter = { "nix" } }), { "neovim/nvim-lspconfig", opts = { @@ -14,4 +13,4 @@ return util.if_exe("nix", { }, }, }, -}) +} diff --git a/home/private_dot_config/nvim/lua/plugins/language/roc.lua b/home/private_dot_config/nvim/lua/plugins/language/roc.lua index fc69fe7..57f8c6d 100644 --- a/home/private_dot_config/nvim/lua/plugins/language/roc.lua +++ b/home/private_dot_config/nvim/lua/plugins/language/roc.lua @@ -1,4 +1,4 @@ -return require("util").if_exe("roc", { +return { { "nvim-treesitter/nvim-treesitter", opts = { ensure_installed = { "roc" } } }, { "neovim/nvim-lspconfig", @@ -10,4 +10,4 @@ return require("util").if_exe("roc", { }, }, }, -}) +} diff --git a/home/private_dot_config/nvim/lua/plugins/language/rust.lua b/home/private_dot_config/nvim/lua/plugins/language/rust.lua index de9893f..6c22d9d 100644 --- a/home/private_dot_config/nvim/lua/plugins/language/rust.lua +++ b/home/private_dot_config/nvim/lua/plugins/language/rust.lua @@ -1,5 +1,5 @@ -- adapted from https://www.lazyvim.org/extras/lang/rust -return require("util").if_exe("rust", { +return { { "hrsh7th/nvim-cmp", opts = function(_, opts) @@ -96,4 +96,4 @@ return require("util").if_exe("rust", { }, }, }, -}) +} diff --git a/home/private_dot_config/nvim/lua/plugins/language/typst.lua b/home/private_dot_config/nvim/lua/plugins/language/typst.lua index 0f1cf37..7ecbf6f 100644 --- a/home/private_dot_config/nvim/lua/plugins/language/typst.lua +++ b/home/private_dot_config/nvim/lua/plugins/language/typst.lua @@ -1,16 +1,15 @@ -return require("util").if_exe("typst", { - { - "neovim/nvim-lspconfig", - opts = { - servers = { - typst_lsp = { - mason = false, - settings = { - exportPdf = "never", -- Choose onType, onSave or never. - -- serverPath = "" -- Normally, there is no need to uncomment it. - }, - }, - }, - }, - }, -}) +-- todo: treesitter? +-- return { +-- { +-- "neovim/nvim-lspconfig", +-- opts = { +-- servers = { +-- tinymist = { +-- mason = false +-- } +-- }, +-- }, +-- }, +-- } +-- +return require("util").setup_lang({lsp = {"tinymist"}}) diff --git a/home/private_dot_config/nvim/lua/plugins/language/zig.lua b/home/private_dot_config/nvim/lua/plugins/language/zig.lua index 20a5ddb..c10d9d7 100644 --- a/home/private_dot_config/nvim/lua/plugins/language/zig.lua +++ b/home/private_dot_config/nvim/lua/plugins/language/zig.lua @@ -1,5 +1,5 @@ -- adapted from https://www.lazyvim.org/extras/lang/rust -return require("util").if_exe("zig", { +return { { "nvim-treesitter/nvim-treesitter", opts = function(_, opts) @@ -17,4 +17,4 @@ return require("util").if_exe("zig", { }, }, }, -}) +} diff --git a/home/private_dot_config/nvim/lua/util/init.lua b/home/private_dot_config/nvim/lua/util/init.lua index 128aa1f..4ded852 100644 --- a/home/private_dot_config/nvim/lua/util/init.lua +++ b/home/private_dot_config/nvim/lua/util/init.lua @@ -7,24 +7,89 @@ local function setDefault(t, d) setmetatable(t, mt) end +-- local function setup_lsp(name) +-- return { +-- "neovim/nvim-lspconfig", +-- opts = { +-- servers = { +-- [name] = { mason = false }, +-- }, +-- }, +-- } +-- end + + +-- local function setup_lang(defs) +-- setDefault(defs, {}) +-- return { +-- { +-- "nvim-treesitter/nvim-treesitter", +-- opts = function(_, opts) +-- opts.ensure_installed = vim.list_extend(opts.ensure_installed or {}, defs.treesitter) +-- end, +-- }, +-- { +-- "williamboman/mason.nvim", +-- opts = function(_, opts) +-- opts.ensure_installed = vim.list_extend(opts.ensure_installed or {}, defs.mason) +-- end, +-- }, +-- } +-- end + + +local function lsp_no_mason(server_name) + return { + [server_name] = { + mason = false, + }, + } +end + +--- generated with the help of claude local function setup_lang(defs) setDefault(defs, {}) - return { + + local result = { { "nvim-treesitter/nvim-treesitter", opts = function(_, opts) - opts.ensure_installed = vim.list_extend(opts.ensure_installed or {}, defs.treesitter) + opts.ensure_installed = vim.list_extend(opts.ensure_installed or {}, defs.treesitter or {}) end, }, { "williamboman/mason.nvim", opts = function(_, opts) - opts.ensure_installed = vim.list_extend(opts.ensure_installed or {}, defs.mason) + opts.ensure_installed = vim.list_extend(opts.ensure_installed or {}, defs.mason or {}) end, }, } + + -- Handle LSP configuration + if defs.lsp then + table.insert(result, { + "neovim/nvim-lspconfig", + opts = { + servers = {}, + }, + }) + + -- i think the result[#result] syntax is taking the "last" index of result + for _, lsp in ipairs(defs.lsp) do + if type(lsp) == "string" then + -- Regular LSP server + result[#result].opts.servers[lsp] = {mason = false} + elseif type(lsp) == "table" and lsp[1] then + -- LSP server with no Mason + result[#result].opts.servers = vim.tbl_deep_extend("force", result[#result].opts.servers, lsp_no_mason(lsp[1])) + end + end + end + + return result end + local function if_exe(exe, deps) if vim.fn.executable(exe) == 0 then return {} @@ -32,7 +97,12 @@ local function if_exe(exe, deps) return deps end +local function import_if_exe(exe, mod) + return if_exe(exe, { { import = mod } }) +end + return { setup_lang = setup_lang, if_exe = if_exe, + import_if_exe = import_if_exe, }