From 7b5241304b50f03bc1e70efce1d725929747f68f Mon Sep 17 00:00:00 2001 From: xinyangli Date: Thu, 22 Aug 2024 11:48:45 +0800 Subject: [PATCH] lsp: use nvim-metals instead of lsp-config for scala --- config/lsp/default.nix | 1 + config/lsp/lsp.nix | 20 +++++++++++++++---- config/lsp/nvim-metals.nix | 41 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+), 4 deletions(-) create mode 100644 config/lsp/nvim-metals.nix diff --git a/config/lsp/default.nix b/config/lsp/default.nix index f401b06..5ea86d0 100644 --- a/config/lsp/default.nix +++ b/config/lsp/default.nix @@ -3,5 +3,6 @@ ./lsp.nix ./lsp-format.nix ./lspkind.nix + ./nvim-metals.nix ]; } diff --git a/config/lsp/lsp.nix b/config/lsp/lsp.nix index 4af99ad..1b2061d 100644 --- a/config/lsp/lsp.nix +++ b/config/lsp/lsp.nix @@ -1,4 +1,4 @@ -{ ... }: +{ helpers, ... }: { plugins.lsp = { @@ -16,9 +16,6 @@ nixd = { enable = true; }; - metals = { - enable = true; - }; }; inlayHints = true; keymaps = { @@ -73,4 +70,19 @@ }; }; }; + + keymaps = [ + { + mode = [ "n" ]; + key = "th"; + action = helpers.mkRaw '' + function() + vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled()) + end + ''; + options = { + desc = "Toggle inlay hints"; + }; + } + ]; } diff --git a/config/lsp/nvim-metals.nix b/config/lsp/nvim-metals.nix new file mode 100644 index 0000000..83b4a70 --- /dev/null +++ b/config/lsp/nvim-metals.nix @@ -0,0 +1,41 @@ +{ pkgs, helpers, ... }: + +{ + extraPlugins = [ + pkgs.vimPlugins.nvim-metals + pkgs.vimPlugins.plenary-nvim + ]; + + extraPackages = [ + pkgs.metals + ]; + + autoGroups.nvim_metals_group = { + clear = true; + }; + + autoCmd = [ + { + event = "FileType"; + group = "nvim_metals_group"; + desc = "Initialize nvim-metals"; + callback = helpers.mkRaw '' + function() + metals_config = require("metals").bare_config() + metals_config.init_options.statusBarProvider = "off" + metals_config.settings = { + showInferredType = true, + showImplicitArguments = false, + showImplicitConversionsAndClasses = false, + metalsBinaryPath = "${pkgs.lib.getExe pkgs.metals}", + useGlobalExecutable = true + } + vim.lsp.inlay_hint.enable(true) + require("metals").initialize_or_attach(metals_config) + end + ''; + } + ]; + + plugins.fidget.enable = true; +}