From 3add3d06af15c0457075f994e0b4a91289737c74 Mon Sep 17 00:00:00 2001 From: Minijackson Date: Wed, 15 May 2024 22:03:04 +0200 Subject: common/vim: switch to nixvim --- common/default.nix | 1 + common/nixvim.nix | 508 ++++++++++++++++++++++++++++ common/vim.nix | 2 +- flake.lock | 296 ++++++++++++++++ flake.nix | 42 ++- usecases/desktop/development.nix | 3 +- usecases/desktop/development/nixvim-dev.nix | 300 ++++++++++++++++ 7 files changed, 1132 insertions(+), 20 deletions(-) create mode 100644 common/nixvim.nix create mode 100644 usecases/desktop/development/nixvim-dev.nix diff --git a/common/default.nix b/common/default.nix index 16093b6..a791e8d 100644 --- a/common/default.nix +++ b/common/default.nix @@ -8,6 +8,7 @@ inputs: (import ./commandline.nix inputs) (import ./localization.nix inputs) (import ./nix.nix inputs) + (import ./nixvim.nix inputs) (import ./ssh.nix inputs) (import ./theme.nix inputs) (import ./tinc.nix inputs) diff --git a/common/nixvim.nix b/common/nixvim.nix new file mode 100644 index 0000000..cfb33bb --- /dev/null +++ b/common/nixvim.nix @@ -0,0 +1,508 @@ +inputs: +{ + config, + lib, + pkgs, + ... +}: + +let + inherit (inputs.nixvim.legacyPackages.x86_64-linux) makeNixvim; +in +{ + options.programs.nixvim = lib.mkOption { + type = lib.types.submodule { + freeformType = lib.types.anything; + config.finalPackage = makeNixvim (builtins.removeAttrs config.programs.nixvim [ "finalPackage" ]); + }; + }; + + config.programs.nixvim = { + # enable = true; + luaLoader.enable = true; + + globals = { + mapleader = ";"; + maplocalleader = ","; + }; + + opts = { + backup = true; + # Use `//` at the end to store the absolute file name + backupdir.__raw = "vim.fn.stdpath('data') .. '/backup//'"; + colorcolumn = "80"; + completeopt = [ + "menu" + "menuone" + "noinsert" + "noselect" + ]; + cursorline = true; + diffopt = [ + "internal" + "filler" + "closeoff" + "linematch:60" + ]; + grepformat = "%f:%l:%c:%m,%f:%l:%m,%f:%l%m,%f %l%m"; + grepprg = "${lib.getExe pkgs.ripgrep} --vim-grep --smart-case"; + ignorecase = true; + inccommand = "split"; + list = true; + listchars = { + extends = ">"; + nbsp = "+"; + precedes = "<"; + tab = " "; + trail = "-"; + }; + scrolloff = 3; + shiftwidth = 4; + shortmess = "ncAxoTOtfFli"; + showmode = false; + sidescrolloff = 5; + smartcase = true; + smartindent = true; + tabstop = 4; + title = true; + undofile = true; + updatetime = 1000; + wildmode = [ + "longest:full" + "full" + ]; + }; + + colorschemes.gruvbox = { + enable = true; + + settings = { + # bold = true; + # italics = true; + # underline = true; + # undercurl = true; + italic.strings = false; + overrides = { + GitSignsAdd.link = "GruvboxGreenSign"; + GitSignsChange.link = "GruvboxOrangeSign"; + GitSignsDelete.link = "GruvboxRedSign"; + IblScope.link = "GruvboxAqua"; + }; + }; + }; + + highlight = { + TSDefinition.link = "GruvboxBlueSign"; + TSDefinitionUsage.link = "GruvboxAquaSign"; + }; + + keymaps = [ + { + key = "fu"; + action = "require('telescope').extensions.undo.undo"; + lua = true; + options = { + silent = true; + desc = "Telescope undo"; + }; + } + + { + key = "-"; + action = "require('oil').open"; + lua = true; + options.desc = "Open parent directory"; + } + + # TODO: add "] " and "[ " + + # Gitsigns + + # TODO: that was not exactly that + # { + # key = "]g"; + # action = "require('gitsigns').next_hunk"; + # lua = true; + # } + + # TODO: noremap? buffer local? silent? + { + key = "gs"; + action = "require('gitsigns').stage_hunk"; + lua = true; + options.desc = "Stage hunk"; + } + + { + key = "gr"; + action = "require('gitsigns').reset_hunk"; + lua = true; + options.desc = "Reset hunk"; + } + + # TODO: visual stage/reset + + { + key = "gS"; + action = "require('gitsigns').stage_buffer"; + lua = true; + options.desc = "Stage buffer"; + } + + { + key = "gR"; + action = "require('gitsigns').reset_buffer"; + lua = true; + options.desc = "Stage buffer"; + } + + { + key = "gu"; + action = "require('gitsigns').undo_stage_hunk"; + lua = true; + options.desc = "Undo stage hunk"; + } + + { + key = "gp"; + action = "require('gitsigns').preview_hunk_inline"; + lua = true; + options.desc = "Preview hunk"; + } + + { + key = "gb"; + action = "function() require('gitsigns').blame_line { full = true } end"; + lua = true; + options.desc = "Blame line"; + } + ]; + + # TODO: + # extraPlugins = with pkgs.unstable.vimPlugins; [ + extraPlugins = with inputs.nixpkgs-unstable.legacyPackages.x86_64-linux.vimPlugins; [ + highlight-undo-nvim + vim-abolish + + # TODO: make that modular + playground + + vim-rhubarb + fugitive-gitlab-vim + ]; + + plugins = { + cmp = { + enable = true; + + settings = { + mapping.__raw = '' + cmp.mapping.preset.insert { + [''] = cmp.mapping.confirm({ select = false }), + + [""] = cmp.mapping(function(fallback) + local luasnip = require("luasnip") + if luasnip.locally_jumpable(1) then + luasnip.jump(1) + else + fallback() + end + end, { "i", "s" }), + + [""] = cmp.mapping(function(fallback) + local luasnip = require("luasnip") + if luasnip.locally_jumpable(-1) then + luasnip.jump(-1) + else + fallback() + end + end, { "i", "s" }), + } + ''; + + snippet.expand = '' + function(args) + require('luasnip').lsp_expand(args.body) + end + ''; + + sources = [ + { name = "nvim_lsp"; } + { name = "nvim_lsp_signature_help"; } + { name = "cmp_pandoc"; } + # TODO: make this modular + { name = "crates"; } + { name = "luasnip"; } + { name = "calc"; } + { name = "path"; } + { name = "treesitter"; } + { name = "git"; } + { name = "tmux"; } + { name = "spell"; } + # Use \k for iskeyword because of UTF-8 + { + name = "buffer"; + option.keyword_pattern = ''\k\+''; + } + ]; + }; + }; + # cmp-buffer.enable = true; + # cmp-calc.enable = true; + # cmp-cmdline.enable = true; + # cmp-git.enable = true; + + comment.enable = true; + + dressing.enable = true; + + fidget = { + enable = true; + notification.overrideVimNotify = true; + }; + + # TODO: add xdg-open for :GBrowse? + fugitive.enable = true; + + gitignore.enable = true; + + gitsigns.enable = true; + + indent-blankline = { + enable = true; + settings.indent = { + char = "│"; + tab_char = "│"; + }; + }; + + lastplace.enable = true; + + lualine = { + enable = true; + iconsEnabled = false; + + componentSeparators.left = ""; + componentSeparators.right = ""; + + sectionSeparators.left = ""; + sectionSeparators.right = ""; + }; + + luasnip.enable = true; + + vim-matchup = { + enable = true; + treesitterIntegration.enable = true; + }; + + mini = { + enable = true; + modules = { + ai = { }; + align = { }; + bracketed = { }; + clue = { + triggers = [ + { + mode = "n"; + keys = "["; + } + { + mode = "n"; + keys = "]"; + } + { + mode = "n"; + keys = ""; + } + ]; + }; + surround = { }; + trailspace = { }; + }; + }; + + none-ls = { + enable = true; + sources = { + code_actions = { + gitrebase.enable = true; + gitsigns.enable = true; + # TODO: maybe? + #refactoring.enable = true; + statix.enable = true; + }; + + diagnostics = { + deadnix.enable = true; + statix.enable = true; + vale = { + enable = true; + withArgs = '' + { filetypes = { "markdown", "pandoc", "rst", "tex", "asciidoc" }, } + ''; + }; + }; + + formatting.shfmt.enable = true; + }; + }; + + nvim-osc52 = { + enable = true; + keymaps.enable = true; + }; + + oil.enable = true; + + # TODO: maybe + #refactoring.enable = true; + + spider = { + enable = true; + keymaps.motions = { + b = "b"; + e = "e"; + ge = "ge"; + w = "w"; + }; + }; + + telescope = { + enable = true; + settings = { }; + + extensions.undo.enable = true; + + keymapsSilent = true; + keymaps = { + "fb" = { + action = "buffers"; + options.desc = "Telescope buffers"; + }; + + "ff" = { + action = "find_files"; + options.desc = "Telescope find files"; + }; + + "fg" = { + action = "live_grep"; + options.desc = "Telescope live grep"; + }; + + "fh" = { + action = "help_tags"; + options.desc = "Telescope help tags"; + }; + + "fo" = { + action = "oldfiles"; + options.desc = "Telescope old files"; + }; + + "fs" = { + action = "spell_suggest"; + options.desc = "Telescope spell suggest"; + }; + + "ft" = { + action = "treesitter"; + options.desc = "Telescope treesitter"; + }; + + "fw" = { + action = "git_status"; + options.desc = "Telescope git status"; + }; + }; + }; + + treesitter = { + enable = true; + indent = true; + + incrementalSelection.enable = true; + nixvimInjections = true; + }; + + treesitter-context = { + enable = true; + settings = { + max_lines = 5; + min_window_height = 20; + }; + }; + + treesitter-refactor = { + enable = true; + highlightDefinitions.enable = true; + }; + + treesitter-textobjects = { + enable = true; + lspInterop = { + enable = true; + peekDefinitionCode = { + "df" = { + query = "@function.outer"; + desc = "Peek outer function"; + }; + "dF" = { + query = "@class.outer"; + desc = "Peek outer class"; + }; + }; + }; + select = { + enable = true; + lookahead = true; + # selectionModes = "V"; + keymaps = let + keymap = object: type: { + query = "@${object}.${type}"; + desc = "Select ${type} ${object}"; + }; + in { + "af" = keymap "function" "outer"; + "if" = keymap "function" "inner"; + "aF" = keymap "call" "outer"; + "iF" = keymap "call" "inner"; + "aC" = keymap "comment" "outer"; + "iC" = keymap "comment" "inner"; + "ab" = keymap "block" "outer"; + "ib" = keymap "block" "inner"; + "aa" = keymap "parameter" "outer"; + "ia" = keymap "parameter" "inner"; + }; + }; + }; + }; + + extraConfigLuaPost = '' + vim.api.nvim_create_autocmd("TextYankPost", { + desc = "Highlight yanked text", + callback = function() + vim.highlight.on_yank() + end, + }) + + require('highlight-undo').setup() + + + -- For fugitive's :GBrowse + + vim.api.nvim_create_user_command("Browse", function(opts) + local Job = require('plenary.job') + + Job:new({ + command = 'xdg-open', + args = { opts.args }, + }):start() + end, { nargs = 1 }) + ''; + }; + + config.environment.systemPackages = [config.programs.nixvim.finalPackage]; +} diff --git a/common/vim.nix b/common/vim.nix index 23aa7e9..10a8705 100644 --- a/common/vim.nix +++ b/common/vim.nix @@ -177,7 +177,7 @@ in { }; }; - environment.systemPackages = [myNeovim]; + # environment.systemPackages = [myNeovim]; environment.variables = { EDITOR = "nvim"; diff --git a/flake.lock b/flake.lock index 516cbe7..23a2bbd 100644 --- a/flake.lock +++ b/flake.lock @@ -1,5 +1,93 @@ { "nodes": { + "devshell": { + "inputs": { + "flake-utils": "flake-utils_2", + "nixpkgs": [ + "nixvim", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1713532798, + "narHash": "sha256-wtBhsdMJA3Wa32Wtm1eeo84GejtI43pMrFrmwLXrsEc=", + "owner": "numtide", + "repo": "devshell", + "rev": "12e914740a25ea1891ec619bb53cf5e6ca922e40", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "devshell", + "type": "github" + } + }, + "flake-compat": { + "locked": { + "lastModified": 1696426674, + "narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=", + "rev": "0f9255e01c2351cc7d116c072cb317785dd33b33", + "revCount": 57, + "type": "tarball", + "url": "https://api.flakehub.com/f/pinned/edolstra/flake-compat/1.0.1/018afb31-abd1-7bff-a5e4-cff7e18efb7a/source.tar.gz" + }, + "original": { + "type": "tarball", + "url": "https://flakehub.com/f/edolstra/flake-compat/1.tar.gz" + } + }, + "flake-compat_2": { + "flake": false, + "locked": { + "lastModified": 1673956053, + "narHash": "sha256-4gtG9iQuiKITOjNQQeQIpoIB6b16fm+504Ch3sNKLd8=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "35bb57c0c8d8b62bbfd284272c928ceb64ddbde9", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, + "flake-parts": { + "inputs": { + "nixpkgs-lib": [ + "nixvim", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1714641030, + "narHash": "sha256-yzcRNDoyVP7+SCNX0wmuDju1NUCt8Dz9+lyUXEI0dbI=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "e5d10a24b66c3ea8f150e47dfdb0416ab7c3390e", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "flake-parts", + "type": "github" + } + }, + "flake-root": { + "locked": { + "lastModified": 1713493429, + "narHash": "sha256-ztz8JQkI08tjKnsTpfLqzWoKFQF4JGu2LRz8bkdnYUk=", + "owner": "srid", + "repo": "flake-root", + "rev": "bc748b93b86ee76e2032eecda33440ceb2532fcd", + "type": "github" + }, + "original": { + "owner": "srid", + "repo": "flake-root", + "type": "github" + } + }, "flake-utils": { "inputs": { "systems": "systems" @@ -18,6 +106,64 @@ "type": "github" } }, + "flake-utils_2": { + "inputs": { + "systems": "systems_2" + }, + "locked": { + "lastModified": 1701680307, + "narHash": "sha256-kAuep2h5ajznlPMD9rnQyffWG8EM/C73lejGofXvdM8=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "4022d587cbbfd70fe950c1e2083a02621806a725", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_3": { + "inputs": { + "systems": "systems_3" + }, + "locked": { + "lastModified": 1685518550, + "narHash": "sha256-o2d0KcvaXzTrPRIo0kOLV0/QXHhDQ5DTi+OxcjO8xqY=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "a1720a10a6cfe8234c0e93907ffe81be440f4cef", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "gitignore": { + "inputs": { + "nixpkgs": [ + "nixvim", + "pre-commit-hooks", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1660459072, + "narHash": "sha256-8DFJjXG8zqoONA1vXtgeKXy68KdJL5UaXR8NtVMUbx8=", + "owner": "hercules-ci", + "repo": "gitignore.nix", + "rev": "a20de23b925fd8264fd7fad6454652e142fd7f73", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "gitignore.nix", + "type": "github" + } + }, "home-manager": { "inputs": { "nixpkgs": [ @@ -39,6 +185,27 @@ "type": "github" } }, + "home-manager_2": { + "inputs": { + "nixpkgs": [ + "nixvim", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1715486357, + "narHash": "sha256-4pRuzsHZOW5W4CsXI9uhKtiJeQSUoe1d2M9mWU98HC4=", + "owner": "nix-community", + "repo": "home-manager", + "rev": "44677a1c96810a8e8c4ffaeaad10c842402647c1", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "home-manager", + "type": "github" + } + }, "musnix": { "flake": false, "locked": { @@ -55,6 +222,27 @@ "type": "github" } }, + "nix-darwin": { + "inputs": { + "nixpkgs": [ + "nixvim", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1713946171, + "narHash": "sha256-lc75rgRQLdp4Dzogv5cfqOg6qYc5Rp83oedF2t0kDp8=", + "owner": "lnl7", + "repo": "nix-darwin", + "rev": "230a197063de9287128e2c68a7a4b0cd7d0b50a7", + "type": "github" + }, + "original": { + "owner": "lnl7", + "repo": "nix-darwin", + "type": "github" + } + }, "nixpkgs": { "locked": { "lastModified": 1715542476, @@ -87,6 +275,62 @@ "type": "github" } }, + "nixvim": { + "inputs": { + "devshell": "devshell", + "flake-compat": "flake-compat", + "flake-parts": "flake-parts", + "flake-root": "flake-root", + "home-manager": "home-manager_2", + "nix-darwin": "nix-darwin", + "nixpkgs": [ + "nixpkgs-unstable" + ], + "pre-commit-hooks": "pre-commit-hooks", + "treefmt-nix": "treefmt-nix" + }, + "locked": { + "lastModified": 1715582453, + "narHash": "sha256-pW8a12PHt/PUphG8Tn0nb+mfbTS7JS4YbThGPepCcb0=", + "owner": "nix-community", + "repo": "nixvim", + "rev": "4530a35bad28a0e8b21905b0817a225e6387811c", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "nixvim", + "type": "github" + } + }, + "pre-commit-hooks": { + "inputs": { + "flake-compat": "flake-compat_2", + "flake-utils": "flake-utils_3", + "gitignore": "gitignore", + "nixpkgs": [ + "nixvim", + "nixpkgs" + ], + "nixpkgs-stable": [ + "nixvim", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1703939133, + "narHash": "sha256-Gxe+mfOT6bL7wLC/tuT2F+V+Sb44jNr8YsJ3cyIl4Mo=", + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "rev": "9d3d7e18c6bc4473d7520200d4ddab12f8402d38", + "type": "github" + }, + "original": { + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "type": "github" + } + }, "root": { "inputs": { "flake-utils": "flake-utils", @@ -94,6 +338,7 @@ "musnix": "musnix", "nixpkgs": "nixpkgs", "nixpkgs-unstable": "nixpkgs-unstable", + "nixvim": "nixvim", "rycee-nur": "rycee-nur", "shmart-prompt-dir": "shmart-prompt-dir" } @@ -144,6 +389,57 @@ "repo": "default", "type": "github" } + }, + "systems_2": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "systems_3": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "treefmt-nix": { + "inputs": { + "nixpkgs": [ + "nixvim", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1714058656, + "narHash": "sha256-Qv4RBm4LKuO4fNOfx9wl40W2rBbv5u5m+whxRYUMiaA=", + "owner": "numtide", + "repo": "treefmt-nix", + "rev": "c6aaf729f34a36c445618580a9f95a48f5e4e03f", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "treefmt-nix", + "type": "github" + } } }, "root": "root", diff --git a/flake.nix b/flake.nix index 5ef18a9..9ae5f3a 100644 --- a/flake.nix +++ b/flake.nix @@ -1,24 +1,30 @@ { description = "My NixOS configurations"; - inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.11"; - inputs.nixpkgs-unstable.url = "github:NixOS/nixpkgs/nixos-unstable"; - inputs.flake-utils.url = "github:numtide/flake-utils"; - inputs.home-manager = { - url = "github:nix-community/home-manager/release-23.11"; - inputs.nixpkgs.follows = "nixpkgs"; - }; - inputs.rycee-nur = { - url = "gitlab:rycee/nur-expressions"; - flake = false; - }; - inputs.musnix = { - url = "github:musnix/musnix"; - flake = false; - }; - inputs.shmart-prompt-dir = { - url = "github:minijackson/shmart-prompt-dir"; - flake = false; + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.11"; + nixpkgs-unstable.url = "github:NixOS/nixpkgs/nixos-unstable"; + flake-utils.url = "github:numtide/flake-utils"; + home-manager = { + url = "github:nix-community/home-manager/release-23.11"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + rycee-nur = { + url = "gitlab:rycee/nur-expressions"; + flake = false; + }; + musnix = { + url = "github:musnix/musnix"; + flake = false; + }; + nixvim = { + url = "github:nix-community/nixvim"; + inputs.nixpkgs.follows = "nixpkgs-unstable"; + }; + shmart-prompt-dir = { + url = "github:minijackson/shmart-prompt-dir"; + flake = false; + }; }; outputs = inputs @ { self, nixpkgs, home-manager, ... }: { diff --git a/usecases/desktop/development.nix b/usecases/desktop/development.nix index f919ae1..d32e5ec 100644 --- a/usecases/desktop/development.nix +++ b/usecases/desktop/development.nix @@ -30,8 +30,9 @@ inputs: { luaFormat = inputs.self.lib.generators.lua {}; in { imports = [ - (import ./development/latex.nix inputs) (import ./development/adb.nix inputs) + (import ./development/latex.nix inputs) + (import ./development/nixvim-dev.nix inputs) ]; options = with lib; diff --git a/usecases/desktop/development/nixvim-dev.nix b/usecases/desktop/development/nixvim-dev.nix new file mode 100644 index 0000000..83f5d10 --- /dev/null +++ b/usecases/desktop/development/nixvim-dev.nix @@ -0,0 +1,300 @@ +_inputs: _: + +# TODO: neodev +# TODO: pandoc +{ + programs.nixvim = { + # TODO: + # extraConfigLuaPost = '' + # local function set_ltex_lang(lang) + # local ltex = vim.lsp.get_active_clients({ name = "ltex" })[1] + # if ltex == nil then + # return + # end + # + # if lang == nil then + # lang = vim.opt_local.spelllang:get()[1] + # end + # + # if lang == "en" then + # lang = "en-US" + # end + # + # ltex.config.settings.ltex.language = lang + # end + # + # vim.api.nvim_create_user_command( + # "LTeXSetLang", + # function(opts) + # local lang = opts.fargs[1] + # set_ltex_lang(lang) + # end, + # { + # nargs = 1, + # complete = function() return { "en", "fr" } end, + # } + # ) + # + # vim.api.nvim_create_autocmd("OptionSet", { + # desc = "Set LTex language on spell change", + # callback = function(ev) + # if ev.match ~= "spelllang" then + # return + # end + # set_ltex_lang() + # end, + # }) + # + # vim.api.nvim_create_autocmd("LspAttach", { + # desc = "Set LTex language on attach", + # callback = function(ev) + # local client = vim.lsp.get_client_by_id(ev.data.client_id) + # if client.config.name ~= "ltex" then + # return + # end + # set_ltex_lang() + # end, + # }) + # ''; + + plugins = { + # TODO: + #conform-nvim.enable = true; + + clangd-extensions.enable = true; + + crates-nvim = { + enable = true; + extraOptions.null_ls.enabled = true; + }; + + lsp = { + enable = true; + + keymaps = { + diagnostic = { + "se" = { + action = "open_float"; + desc = "LSP diagnostic"; + }; + "sl" = { + action = "setloclist"; + desc = "LSP set loclist"; + }; + "sq" = { + action = "setqflist"; + desc = "LSP set quickfixlist"; + }; + }; + + extra = [ + { + key = "gd"; + action = "require('telescope.builtin').lsp_definitions"; + lua = true; + options.desc = "LSP definitions"; + } + { + key = "gr"; + action = "require('telescope.builtin').lsp_references"; + lua = true; + options.desc = "LSP references"; + } + { + key = "sd"; + action = "require('lsp_lines').toggle"; + lua = true; + options.desc = "LSP toggle inline diagnostics"; + } + { + key = "sE"; + action = "require('telescope.builtin').diagnostics"; + lua = true; + options.desc = "LSP all diagnostics"; + } + { + key = "ss"; + action = "require('telescope.builtin').lsp_document_symbols"; + lua = true; + options.desc = "LSP document symbols"; + } + { + key = "sS"; + action = "require('telescope.builtin').lsp_workspace_symbols"; + lua = true; + options.desc = "LSP workspace symbols"; + } + ]; + + lspBuf = { + K = { + action = "hover"; + desc = "LSP hover"; + }; + gr = { + action = "references"; + desc = "LSP references"; + }; + # TODO setup actions-preview-nvim + "sa" = { + action = "code_action"; + desc = "LSP code actions"; + }; + "sf" = { + action = "format"; + desc = "LSP format"; + }; + "si" = { + action = "implementation"; + desc = "LSP implementation"; + }; + "sr" = { + action = "rename"; + desc = "LSP rename"; + }; + "st" = { + action = "type_definition"; + desc = "LSP type definition"; + }; + }; + }; + + onAttach = '' + require("clangd_extensions.inlay_hints").setup_autocmd() + require("clangd_extensions.inlay_hints").set_inlay_hints() + ''; + + servers = { + bashls.enable = true; + clangd = { + enable = true; + extraOptions.cmd = [ + "clangd" + "--background-index" + "--clang-tidy" + "--fallback-style=WebKit" + "--header-insertion-decorators" + "--header-insertion=iwyu" + ]; + }; + elixirls.enable = true; + # TODO: buggy with lsp-lines? + ltex = { + enable = true; + filetypes = [ + "bib" + "gitcommit" + "markdown" + "org" + "plaintex" + "rst" + "rnoweb" + "tex" + # vv Added this one vv + "typst" + "pandoc" + "quarto" + "rmd" + "context" + "html" + "xhtml" + ]; + }; + lua-ls.enable = true; + # completion.callSnippet = "Replace";? + marksman.enable = true; + nixd = { + enable = true; + # TODO: doesn't work with string substitution + settings.formatting.command = [ "nixfmt" ]; + }; + pylsp = { + enable = true; + settings.plugins.ruff.enabled = true; + }; + taplo.enable = true; + typos-lsp.enable = true; + typst-lsp.enable = true; + }; + }; + + lsp-lines = { + enable = true; + # TODO: seems buggy with multiple sources? + # currentLine = true; + }; + + rustaceanvim = { + enable = true; + server = { + onAttach = '' + function(client, bufnr) + __lspOnAttach(client, bufnr) + + vim.keymap.set( + -- {"n", "v"}, + "n", + "J", + function() vim.cmd.RustLsp('joinLines') end, + { + silent = true, + buffer = bufnr, + desc = "rust-analyzer join lines", + } + ) + + vim.keymap.set( + "n", + "", + function() vim.cmd.RustLsp({ "moveItem", "up" }) end, + { + silent = true, + buffer = bufnr, + desc = "rust-analyzer move item up", + } + ) + + vim.keymap.set( + "n", + "", + function() vim.cmd.RustLsp({ "moveItem", "down" }) end, + { + silent = true, + buffer = bufnr, + desc = "rust-analyzer move item down", + } + ) + + vim.keymap.set( + "n", + "sR", + function() vim.cmd.RustLsp('runnables') end, + { + silent = true, + buffer = bufnr, + desc = "rust-analyzer runnables", + } + ) + + vim.keymap.set( + "n", + "sx", + function() vim.cmd.RustLsp('explainError') end, + { + silent = true, + buffer = bufnr, + desc = "rust-analyzer explain error", + } + ) + end + ''; + # TODO? + # settings.rust-analyzer = { + # checkOnSave.command = "clippy"; + # experimental.procAttrMacros = true; + # }; + }; + }; + }; + }; +} -- cgit v1.2.3