nix-community / nixvim

Configure Neovim with Nix! [maintainers=@GaetanLepage, @traxys, @mattsturgeon, @khaneliman]
https://nix-community.github.io/nixvim
MIT License
1.78k stars 276 forks source link

No longer able to use clippy with rust-analyzer #264

Closed pupbrained closed 1 year ago

pupbrained commented 1 year ago

Plugin affected: LSP/rust-analyzer Nixpkgs channel: Unstable Home-manager version: Master branch

Description

As of the latest commit at the time of writing (6544e323966d81306f74842781a4a8c00a53a077), the rust-analyzer plugin no longer seems to support using a custom command for checkOnSave.

error: A definition for option `home-manager.users.<username>.programs.nixvim.plugins.lsp.servers.rust-analyzer.settings.checkOnSave' is not of type `null or boolean'. Definition values:
       - In `/nix/store/8xwhf0dk1q5j0szf5vwv7c9v4g7xmlwa-source/pkgs/nixvim.nix':
           {
             command = "clippy";
           }

Config

{
  inputs,
  pkgs,
  ...
}: let
  sources = pkgs.callPackage ./_sources/generated.nix {};

  alternate-toggler-nvim = pkgs.vimUtils.buildVimPlugin {
    inherit (sources.alternate-toggler-nvim) src pname version;
  };

  copilot-vim = pkgs.vimPlugins.copilot-vim.overrideAttrs (_: {
    inherit (sources.copilot-vim) src pname version;
  });

  nvim-cokeline = pkgs.vimUtils.buildVimPlugin {
    inherit (sources.nvim-cokeline) src pname version;
  };

  inherit (inputs.nixpkgs-stable.legacyPackages.${pkgs.system}.vimPlugins) catppuccin-nvim;
in {
  programs.nixvim = {
    enable = true;
    package = inputs.neovim.packages.${pkgs.system}.default;
    colorscheme = "catppuccin";

    options = {
      number = true;
      relativenumber = true;
      shiftwidth = 0;
      tabstop = 2;
      showtabline = 2;
      expandtab = true;
      smarttab = true;
      showmode = false;
      undofile = true;
      list = true;
      completeopt = "menuone,menuone,noselect";
    };

    globals = {
      mapleader = " ";
      rust_recommended_style = false;
      neovide_cursor_animation_length = 0.025;
      neovide_cursor_vfx_mode = "railgun";
      neovide_background_color = "#1e1e2ed9";
      neovide_refresh_rate = 165;
      neovide_transparency = 0.0;
      terminal_color_0 = "#45475A";
      terminal_color_1 = "#F38BA8";
      terminal_color_2 = "#A6E3A1";
      terminal_color_3 = "#F9E2AF";
      terminal_color_4 = "#89B4FA";
      terminal_color_5 = "#F5C2E7";
      terminal_color_6 = "#94E2D5";
      terminal_color_7 = "#BAC2DE";
      terminal_color_8 = "#45475A";
      terminal_color_9 = "#F38BA8";
      terminal_color_10 = "#A6E3A1";
      terminal_color_11 = "#F9E2AF";
      terminal_color_12 = "#89B4FA";
      terminal_color_13 = "#F5C2E7";
      terminal_color_14 = "#94E2D5";
      terminal_color_15 = "#BAC2DE";
    };

    maps = {
      normal = {
        "<C-t>" = {
          silent = true;
          action = "<CMD>lua require('FTerm').toggle()<CR>";
        };
        "<C-h>" = {
          silent = true;
          action = "<Plug>(cokeline-focus-pkgs)";
        };
        "<C-l>" = {
          silent = true;
          action = "<Plug>(cokeline-focus-next)";
        };
        "<Leader>lg" = {
          silent = true;
          action = "<CMD>LazyGit<CR>";
        };
        "<Leader>la" = {
          silent = true;
          action = "<CMD>lua vim.lsp.buf.code_action()<CR>";
        };
        "<Leader>lk" = {
          silent = true;
          action = "<CMD>lua vim.lsp.buf.hover()<CR>";
        };
        "<Leader>be" = {
          silent = true;
          action = "<Plug>(cokeline-pick-close)";
        };
        "<Leader>bj" = {
          silent = true;
          action = "<Plug>(cokeline-pick-focus)";
        };
        "<Leader>e" = {
          silent = true;
          action = "<CMD>NvimTreeToggle<CR>";
        };
        "<Leader>a" = {
          silent = true;
          action = "<CMD>lua require('alternate-toggler').toggleAlternate()<CR>";
        };
      };

      terminal."<C-t>" = {
        silent = true;
        action = "<C-\\><C-n><CMD>lua require('FTerm').toggle()<CR>";
      };
    };

    extraConfigLua = ''
      vim.cmd('set mouse=a')
      vim.cmd('set guifont=CartographCF\\ Nerd\\ Font:h14')

      require('indent_blankline').setup()
      require('gitsigns').setup()
      require('colorizer').setup({
        user_default_options = {
          names = false,
          mode = 'virtualtext',
        },
      })
      require('FTerm').setup({border = 'rounded', dimensions = {height = 0.9, width = 0.9}})
      require('mini.starter').setup()
      require('mini.trailspace').setup()
      require('mini.comment').setup()
      require('mini.surround').setup()
      require('mini.move').setup()
      require('mini.indentscope').setup({
        symbol = '│',
        draw = {
          delay = 50,
        },
      })
      require('mini.jump2d').setup({
        mappings = {
          start_jumping = 's',
        },
      })

      require('catppuccin').setup({
        styles = {
          comments = { 'italic' },
          conditionals = { 'italic' },
          loops = {},
          functions = { 'italic' },
          keywords = {},
          strings = {},
          variables = { 'italic' },
          numbers = {},
          booleans = { 'italic' },
          properties = {},
          types = {},
          operators = {},
        },
      })

      local a = {
        blue = '#89b4fa',
        cyan = '#94e2d5',
        black = '#1e1e2e',
        white = '#cdd6f4',
        violet = '#cba6f7',
        grey = '#181d2d',
      }

      local b = {
        normal = {a = {fg = a.black, bg = a.violet}, b = {fg = a.white, bg = a.grey}, c = {fg = a.black, bg = a.black}},
        insert = {a = {fg = a.black, bg = a.blue}},
        visual = {a = {fg = a.black, bg = a.cyan}},
        replace = {a = {fg = a.black, bg = a.white}},
        inactive = {a = {fg = a.white, bg = a.black}, b = {fg = a.white, bg = a.black}, c = {fg = a.black, bg = a.black}}
      }

      local c = {
        function()
          return string.rep(' ', vim.api.nvim_win_get_width(require 'nvim-tree.view'.get_winnr()) - 1)
        end,
        cond = require('nvim-tree.view').is_visible, color = 'NvimTreeNormal'
      }

      require('lualine').setup {
        options = {
            theme = b,
            component_separators = '|',
            section_separators = {left = '', right = ''},
            refresh = {statusline = 100, tabline = 100, winbar = 100}
        },
        sections = {
            lualine_a = {c, {'mode', separator = {left = ''}, right_padding = 2}},
            lualine_b = {'filename', 'branch'},
            lualine_c = {'fileformat'},
            lualine_x = {'lsp_progress'},
            lualine_y = {'filetype', 'progress'},
            lualine_z = {{'location', separator = {right = ''}, left_padding = 2}}
        },
        inactive_sections = {
            lualine_a = {'filename'},
            lualine_b = {},
            lualine_c = {},
            lualine_x = {},
            lualine_y = {},
            lualine_z = {'location'}
        },
        tabline = {},
        extensions = {}
      }

      local d = require('cokeline/utils').get_hex
      local e = require('cokeline/mappings').is_picking_focus
      local f = require('cokeline/mappings').is_picking_close
      require('cokeline').setup({
        show_if_buffers_are_at_least = 2,
        default_hl = {
          fg = function(g)
            return g.is_focused and d('Normal', 'fg') or d('Comment', 'fg')
          end,
          bg = d('ColorColumn', 'bg')
        },
        components = {
          {text = ' ', bg = d('Normal', 'bg')},
          {text = '', fg = d('ColorColumn', 'bg'), bg = d('Normal', 'bg')},
          {text = function(g)
                    if e() or f() then
                      return g.pick_letter .. ' '
                    end
                    return g.devicon.icon
                  end,
           fg = function(g)
                  if e() then
                    return yellow
                  end
                  if f() then
                    return red
                  end
                  if g.is_focused then
                    return dark
                  else
                    return light
                  end
                end,
           style = function(h)
                    return (e() or f()) and 'italic,bold' or nil
                   end
          },
          {text = ' '},
          {text = function(g)
                    return g.filename .. '  '
                  end,
           style = function(g)
                   end
          },
          {text = '', delete_buffer_on_left_click = true},
          {text = '', fg = d('ColorColumn', 'bg'), bg = d('Normal', 'bg')}
        }
      })
    '';

    plugins = {
      cmp_luasnip.enable = true;
      cmp-buffer.enable = true;
      cmp-path.enable = true;
      cmp-nvim-lsp.enable = true;
      nvim-autopairs.enable = true;

      lsp = {
        enable = true;
        onAttach = ''
          if client.supports_method('textDocument/formatting') then
            vim.api.nvim_clear_autocmds({ group = augroup, buffer = bufnr })
            vim.api.nvim_create_autocmd('BufWritePre', {
              group = augroup,
              buffer = bufnr,
              callback = function()
                if client.name == 'null-ls' then
                  local util = require 'vim.lsp.util'
                  local params = util.make_formatting_params({})
                  client.request('textDocument/formatting', params, nil, bufnr)
                end
                vim.lsp.buf.format({bufnr = bufnr})
                require('mini.trailspace').trim()
                require('mini.trailspace').trim_last_lines()
              end,
            })
            vim.api.nvim_create_autocmd('BufWritePre', {
              pattern = { '*.tsx', '*.ts', '*.jsx', '*.js' },
              command = 'silent! EslintFixAll',
              group = vim.api.nvim_create_augroup('MyAutocmdsJavaScripFormatting', {}),
            })
          end
        '';

        servers = {
          denols.enable = true;
          eslint.enable = true;
          rnix-lsp.enable = true;
          rust-analyzer = {
            enable = true;

            settings = {
              checkOnSave.command = "clippy";

              imports.granularity = {
                enforce = true;
                group = "item";
              };
            };

            extraSettings = {
              unstable_features = true;
              tab_spaces = 2;
              reorder_impl_items = true;
              indent_style = "Block";
              normalize_comments = true;
              max_width = 100;
            };
          };
          tsserver.enable = true;
          gopls.enable = true;
        };
      };

      null-ls = {
        enable = true;
        sources = {
          formatting = {
            alejandra.enable = true;
          };
        };
      };

      nvim-cmp = {
        enable = true;

        formatting.format = ''
          require('lspkind').cmp_format({mode = 'symbol', maxwidth = 50})
        '';

        mapping = {
          "<C-b>" = "cmp.mapping.scroll_docs(-4)";
          "<C-f>" = "cmp.mapping.scroll_docs(4)";
          "<C-Space>" = "cmp.mapping.complete()";
          "<C-e>" = "cmp.mapping.close()";
          "<CR>" = "cmp.mapping.confirm({ select = true })";
        };

        snippet.expand = "luasnip";

        sources = [
          {name = "nvim_lsp";}
          {name = "luasnip";}
          {name = "path";}
          {name = "buffer";}
        ];

        window = {
          completion.border = "rounded";
          documentation.border = "rounded";
        };
      };

      nvim-tree = {
        enable = true;
        git.enable = true;
        disableNetrw = true;

        diagnostics = {
          enable = true;
          icons = {
            hint = "";
            info = "";
            warning = "";
            error = "";
          };
        };
      };

      telescope = {
        enable = true;
        extensions.fzf-native.enable = true;
      };

      treesitter = {
        enable = true;
        nixGrammars = true;
      };
    };

    extraPlugins = with pkgs.vimPlugins; [
      alternate-toggler-nvim
      catppuccin-nvim
      copilot-vim
      FTerm-nvim
      gitsigns-nvim
      indent-blankline-nvim
      lazygit-nvim
      lspkind-nvim
      lualine-lsp-progress
      lualine-nvim
      luasnip
      markdown-preview-nvim
      mini-nvim
      mkdir-nvim
      nvim-cokeline
      nvim-colorizer-lua
      nvim-lightbulb
      nvim-web-devicons
      presence-nvim
      trouble-nvim
      vim-cool
      vim-smoothie
      vim-unimpaired
      vim-visual-multi
      zen-mode-nvim
    ];
  };
}
pupbrained commented 1 year ago

After viewing rust-analyzer-config.nix, it seems that none of the checkOnSave submodule options exist anymore, either, making some of the documentation incorrect.

traxys commented 1 year ago

The option was renamed to check.command on upstream, because we extract upstream options this would have broken some setups.

I updated my config with the following commit: https://github.com/traxys/nvim-flake/commit/ba5aab678fcb558e9596fcb19de71060bac5ed16

pupbrained commented 1 year ago

The option was renamed to check.command on upstream, because we extract upstream options this would have broken some setups.

I updated my config with the following commit: traxys/nvim-flake@ba5aab6

Oh, awesome, thank you. I think the documentation still needs to be modified to reflect those changes if it hasn't been already.