From 4a22c35e6dc28379abc5c0888adee2c98afbf20f Mon Sep 17 00:00:00 2001 From: Matt Sturgeon Date: Sat, 23 Mar 2024 17:03:15 +0000 Subject: [PATCH] plugins/lsp: add inlay-hint option `onAttach` code is based on [this comment](https://github.com/lvimuser/lsp-inlayhints.nvim/issues/46#issuecomment-1949916683). Documented upstream at [`:h lsp-inlay_hint`](https://neovim.io/doc/user/lsp.html#lsp-inlay_hint) --- plugins/lsp/default.nix | 15 +++++++++++++++ tests/test-sources/plugins/lsp/_lsp.nix | 1 + 2 files changed, 16 insertions(+) diff --git a/plugins/lsp/default.nix b/plugins/lsp/default.nix index 406f288c..25616c76 100644 --- a/plugins/lsp/default.nix +++ b/plugins/lsp/default.nix @@ -112,6 +112,12 @@ in visible = false; }; + inlayHints = mkEnableOption '' + LSP inlay-hints. Only affects language servers with inlay-hints support. + + See [`:h lsp-inlay_hint`](https://neovim.io/doc/user/lsp.html#lsp-inlay_hint). + ''; + onAttach = mkOption { type = types.lines; description = "A lua function to be run when a new LSP buffer is attached. The argument `client` and `bufnr` is provided."; @@ -196,6 +202,15 @@ in ++ (mkMaps "vim.lsp.buf." cfg.keymaps.lspBuf) ++ cfg.keymaps.extra; + # Enable inlay-hints + plugins.lsp.onAttach = mkIf cfg.inlayHints '' + -- LSP Inlay Hints {{{ + if client.server_capabilities.inlayHintProvider and vim.lsp.inlay_hint then + vim.lsp.inlay_hint.enable(bufnr, true) + end + -- }}} + ''; + # Enable all LSP servers extraConfigLua = '' -- LSP {{{ diff --git a/tests/test-sources/plugins/lsp/_lsp.nix b/tests/test-sources/plugins/lsp/_lsp.nix index 06ede9d0..2ed31d50 100644 --- a/tests/test-sources/plugins/lsp/_lsp.nix +++ b/tests/test-sources/plugins/lsp/_lsp.nix @@ -7,6 +7,7 @@ example = { plugins.lsp = { enable = true; + inlayHints = true; keymaps = { silent = true;