From 4ae4f3bb2b9c16d3a35f68bc829a4d7334273c5d Mon Sep 17 00:00:00 2001 From: imxyy_soope_ Date: Sat, 22 Nov 2025 22:03:21 +0800 Subject: [PATCH] feat(nvim): typst; tidy language specific configurations --- .lazy.lua | 17 +++++++ .../editor/neovim/nvim/lua/langs/go.lua | 3 -- .../neovim/nvim/lua/langs/langs-setup.lua | 4 -- .../editor/neovim/nvim/lua/langs/lualang.lua | 34 -------------- .../editor/neovim/nvim/lua/langs/markdown.lua | 34 -------------- .../editor/neovim/nvim/lua/langs/nix.lua | 34 -------------- .../editor/neovim/nvim/lua/langs/rust.lua | 10 ----- .../neovim/nvim/lua/plugins/lsp/lspconfig.lua | 44 +++++++------------ .../neovim/nvim/lua/plugins/plugins-setup.lua | 6 +++ modules/coding/langs/all.nix | 1 + modules/coding/langs/typst.nix | 21 +++++++++ modules/nix.nix | 5 ++- 12 files changed, 66 insertions(+), 147 deletions(-) delete mode 100644 modules/coding/editor/neovim/nvim/lua/langs/lualang.lua delete mode 100644 modules/coding/editor/neovim/nvim/lua/langs/markdown.lua delete mode 100644 modules/coding/editor/neovim/nvim/lua/langs/nix.lua delete mode 100644 modules/coding/editor/neovim/nvim/lua/langs/rust.lua create mode 100644 modules/coding/langs/typst.nix diff --git a/.lazy.lua b/.lazy.lua index b7583e0..be7b8d2 100644 --- a/.lazy.lua +++ b/.lazy.lua @@ -1,3 +1,20 @@ +vim.lsp.config("nixd", { + settings = { + nixd = { + nixpkgs = { + expr = "import { }", + }, + options = { + nixos = { + expr = '(builtins.getFlake ("git+file://" + toString ./.)).nixosConfigurations.' + .. vim.uv.os_gethostname() + .. ".options", + }, + }, + }, + }, +}) + return { { "folke/lazydev.nvim", diff --git a/modules/coding/editor/neovim/nvim/lua/langs/go.lua b/modules/coding/editor/neovim/nvim/lua/langs/go.lua index c19138c..04c2a27 100644 --- a/modules/coding/editor/neovim/nvim/lua/langs/go.lua +++ b/modules/coding/editor/neovim/nvim/lua/langs/go.lua @@ -4,9 +4,6 @@ vim.api.nvim_create_autocmd("BufWritePre", { desc = "auto format Go files", callback = function() vim.lsp.buf.format() - -- vim.fn.system("go fmt " .. vim.fn.expand("%:p")) - -- vim.fn.system("goimports -w " .. vim.fn.expand("%:p")) - -- vim.cmd("edit") end, group = "Go", }) diff --git a/modules/coding/editor/neovim/nvim/lua/langs/langs-setup.lua b/modules/coding/editor/neovim/nvim/lua/langs/langs-setup.lua index 0ccecf8..d2b702a 100644 --- a/modules/coding/editor/neovim/nvim/lua/langs/langs-setup.lua +++ b/modules/coding/editor/neovim/nvim/lua/langs/langs-setup.lua @@ -1,5 +1 @@ require("langs.go") --- require("langs.rust") -require("langs.lualang") -require("langs.nix") -require("langs.markdown") diff --git a/modules/coding/editor/neovim/nvim/lua/langs/lualang.lua b/modules/coding/editor/neovim/nvim/lua/langs/lualang.lua deleted file mode 100644 index eac4d3c..0000000 --- a/modules/coding/editor/neovim/nvim/lua/langs/lualang.lua +++ /dev/null @@ -1,34 +0,0 @@ -vim.api.nvim_create_augroup("Lua", {}) - -local old = {} -vim.api.nvim_create_autocmd("BufEnter", { - pattern = { "*.lua" }, - desc = "auto lua file indent", - callback = function() - local opt = vim.opt - -- Tab width setting - old.tabstop = opt.tabstop - old.shiftwidth = opt.shiftwidth - old.softtabstop = opt.softtabstop - old.expandtab = opt.expandtab - opt.tabstop = 2 - opt.shiftwidth = 2 - opt.softtabstop = 2 - opt.expandtab = true - opt.autoindent = true - end, - group = "Lua", -}) -vim.api.nvim_create_autocmd("BufLeave", { - pattern = { "*.lua" }, - desc = "auto lua file indent", - callback = function() - local opt = vim.opt - -- Tab width setting - opt.tabstop = old.tabstop - opt.shiftwidth = old.shiftwidth - opt.softtabstop = old.softtabstop - opt.expandtab = old.expandtab - end, - group = "Lua", -}) diff --git a/modules/coding/editor/neovim/nvim/lua/langs/markdown.lua b/modules/coding/editor/neovim/nvim/lua/langs/markdown.lua deleted file mode 100644 index 5004675..0000000 --- a/modules/coding/editor/neovim/nvim/lua/langs/markdown.lua +++ /dev/null @@ -1,34 +0,0 @@ -vim.api.nvim_create_augroup("Markdown", {}) - -local old = {} -vim.api.nvim_create_autocmd("BufEnter", { - pattern = { "*.md" }, - desc = "auto md file indent", - callback = function() - local opt = vim.opt - -- Tab width setting - old.tabstop = opt.tabstop - old.shiftwidth = opt.shiftwidth - old.softtabstop = opt.softtabstop - old.expandtab = opt.expandtab - opt.tabstop = 2 - opt.shiftwidth = 2 - opt.softtabstop = 2 - opt.expandtab = true - opt.autoindent = true - end, - group = "Markdown", -}) -vim.api.nvim_create_autocmd("BufLeave", { - pattern = { "*.md" }, - desc = "auto markdown file indent", - callback = function() - local opt = vim.opt - -- Tab width setting - opt.tabstop = old.tabstop - opt.shiftwidth = old.shiftwidth - opt.softtabstop = old.softtabstop - opt.expandtab = old.expandtab - end, - group = "Markdown", -}) diff --git a/modules/coding/editor/neovim/nvim/lua/langs/nix.lua b/modules/coding/editor/neovim/nvim/lua/langs/nix.lua deleted file mode 100644 index 8d3037f..0000000 --- a/modules/coding/editor/neovim/nvim/lua/langs/nix.lua +++ /dev/null @@ -1,34 +0,0 @@ -vim.api.nvim_create_augroup("Nix", {}) - -local old = {} -vim.api.nvim_create_autocmd("BufEnter", { - pattern = { "*.nix" }, - desc = "auto nix file indent", - callback = function() - local opt = vim.opt - -- Tab width setting - old.tabstop = opt.tabstop - old.shiftwidth = opt.shiftwidth - old.softtabstop = opt.softtabstop - old.expandtab = opt.expandtab - opt.tabstop = 2 - opt.shiftwidth = 2 - opt.softtabstop = 2 - opt.expandtab = true - opt.autoindent = true - end, - group = "Nix", -}) -vim.api.nvim_create_autocmd("BufLeave", { - pattern = { "*.nix" }, - desc = "auto nix file indent", - callback = function() - local opt = vim.opt - -- Tab width setting - opt.tabstop = old.tabstop - opt.shiftwidth = old.shiftwidth - opt.softtabstop = old.softtabstop - opt.expandtab = old.expandtab - end, - group = "Nix", -}) diff --git a/modules/coding/editor/neovim/nvim/lua/langs/rust.lua b/modules/coding/editor/neovim/nvim/lua/langs/rust.lua deleted file mode 100644 index 9326525..0000000 --- a/modules/coding/editor/neovim/nvim/lua/langs/rust.lua +++ /dev/null @@ -1,10 +0,0 @@ -vim.api.nvim_create_augroup("Rust", {}) -vim.api.nvim_create_autocmd("BufWritePost", { - pattern = { "*.rs" }, - desc = "auto format Rust files", - callback = function() - vim.fn.system("rustfmt " .. vim.fn.expand("%:p")) - vim.cmd("edit") - end, - group = "Rust", -}) diff --git a/modules/coding/editor/neovim/nvim/lua/plugins/lsp/lspconfig.lua b/modules/coding/editor/neovim/nvim/lua/plugins/lsp/lspconfig.lua index 854e622..662cb99 100644 --- a/modules/coding/editor/neovim/nvim/lua/plugins/lsp/lspconfig.lua +++ b/modules/coding/editor/neovim/nvim/lua/plugins/lsp/lspconfig.lua @@ -1,18 +1,4 @@ local servers = { - "lua_ls", - "pyright", - "gopls", - "clangd", - "rust_analyzer", - "ts_ls", - "jsonls", - "cssls", - "nixd", - "html", - "java_language_server", -} - -local extra_config = { lua_ls = { settings = { Lua = { @@ -52,20 +38,30 @@ local extra_config = { nixd = { settings = { nixd = { + formatting = { + command = { "nixfmt" }, + }, nixpkgs = { expr = "import { }", }, - options = { - nixos = { - expr = '(builtins.getFlake ("git+file://" + toString ./.)).nixosConfigurations.imxyy-nix.options', - }, - }, }, }, }, + tinymist = { + cmd = { "tinymist" }, + filetypes = { "typst" }, + }, qmlls = { cmd = { "qmlls", "-E" }, }, + pyright = {}, + gopls = {}, + clangd = {}, + ts_ls = {}, + jsonls = {}, + cssls = {}, + html = {}, + java_language_server = {}, } local capabilities = require("cmp_nvim_lsp").default_capabilities() @@ -74,14 +70,8 @@ capabilities.textDocument.foldingRange = { dynamicRegistration = false, lineFoldingOnly = true, } -for _, server in ipairs(servers) do - local extra = extra_config[server] or {} - local config = { - capabilities = capabilities, - } - for k, v in pairs(extra) do - config[k] = v - end +for server, config in pairs(servers) do + config["capabilities"] = capabilities vim.lsp.config(server, config) vim.lsp.enable(server) end diff --git a/modules/coding/editor/neovim/nvim/lua/plugins/plugins-setup.lua b/modules/coding/editor/neovim/nvim/lua/plugins/plugins-setup.lua index a456f74..7d2a736 100644 --- a/modules/coding/editor/neovim/nvim/lua/plugins/plugins-setup.lua +++ b/modules/coding/editor/neovim/nvim/lua/plugins/plugins-setup.lua @@ -281,6 +281,12 @@ local plugins = { ft = "pest", opts = {}, }, + + { + "nmac427/guess-indent.nvim", + event = "VeryLazy", + opts = {}, + }, } require("lazy").setup(plugins, {}) diff --git a/modules/coding/langs/all.nix b/modules/coding/langs/all.nix index 5aca8ae..717097e 100644 --- a/modules/coding/langs/all.nix +++ b/modules/coding/langs/all.nix @@ -17,6 +17,7 @@ lib.my.makeSwitch { lua.enable = true; java.enable = true; qml.enable = true; + typst.enable = true; }; }; } diff --git a/modules/coding/langs/typst.nix b/modules/coding/langs/typst.nix new file mode 100644 index 0000000..97c3d0d --- /dev/null +++ b/modules/coding/langs/typst.nix @@ -0,0 +1,21 @@ +{ + config, + lib, + pkgs, + ... +}: +lib.my.makeSwitch { + inherit config; + optionName = "Typst"; + optionPath = [ + "coding" + "langs" + "typst" + ]; + config' = { + my.hm.home.packages = with pkgs; [ + typst + tinymist + ]; + }; +} diff --git a/modules/nix.nix b/modules/nix.nix index e67beac..e69d04a 100644 --- a/modules/nix.nix +++ b/modules/nix.nix @@ -60,7 +60,10 @@ lib.my.makeSwitch { !include ${config.sops.secrets.nix-github-token.path} ''; - my.hm.home.packages = [ pkgs.nixd ]; + my.hm.home.packages = with pkgs; [ + nixd + nixfmt + ]; # uncomment to enable auto gc /*