From a1fbdf49fdc97b615030bde532bff19632c49403 Mon Sep 17 00:00:00 2001 From: Venkatesan Ravi Date: Sat, 5 Apr 2025 01:32:58 +0000 Subject: [PATCH] lsp: add inlayHints support --- docs/release-notes/rl-0.8.md | 1 + modules/plugins/lsp/config.nix | 20 ++++++++++++++++++++ modules/plugins/lsp/module.nix | 3 +++ 3 files changed, 24 insertions(+) diff --git a/docs/release-notes/rl-0.8.md b/docs/release-notes/rl-0.8.md index a245b006..8b87ae99 100644 --- a/docs/release-notes/rl-0.8.md +++ b/docs/release-notes/rl-0.8.md @@ -300,6 +300,7 @@ - Add neo-tree integration for Bufferline. - Add more applicable filetypes to illuminate denylist. - Disable mini.indentscope for applicable filetypes. +- Enable inlay hints support - `config.vim.lsp.inlayHints`. [tebuevd](https://github.com/tebuevd): diff --git a/modules/plugins/lsp/config.nix b/modules/plugins/lsp/config.nix index 0fa16e47..3702ac5f 100644 --- a/modules/plugins/lsp/config.nix +++ b/modules/plugins/lsp/config.nix @@ -4,6 +4,7 @@ pkgs, ... }: let + inherit (lib.generators) mkLuaInline; inherit (lib.modules) mkIf; inherit (lib.strings) optionalString; inherit (lib.trivial) boolToString; @@ -28,6 +29,25 @@ in { sourcePlugins = ["cmp-nvim-lsp"]; }; + autocmds = + if cfg.inlayHints.enable + then [ + { + callback = mkLuaInline '' + function(event) + local bufnr = event.buf + local client = vim.lsp.get_client_by_id(event.data.client_id) + if client and client.supports_method(vim.lsp.protocol.Methods.textDocument_inlayHint) then + vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled({ bufnr = bufnr }), { bufnr = bufnr }) + end + end + ''; + desc = "LSP on-attach enable inlay hints autocmd"; + event = ["LspAttach"]; + } + ] + else []; + pluginRC.lsp-setup = '' vim.g.formatsave = ${boolToString cfg.formatOnSave}; diff --git a/modules/plugins/lsp/module.nix b/modules/plugins/lsp/module.nix index b16f9c13..f408d873 100644 --- a/modules/plugins/lsp/module.nix +++ b/modules/plugins/lsp/module.nix @@ -5,6 +5,9 @@ in { options.vim.lsp = { enable = mkEnableOption "LSP, also enabled automatically through null-ls and lspconfig options"; formatOnSave = mkEnableOption "format on save"; + inlayHints = { + enable = mkEnableOption "inlay hints"; + }; mappings = { goToDefinition = mkMappingOption "Go to definition"