diff --git a/README.md b/README.md index dd5ec49..f04900e 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,8 @@ Add to your Neovim configuration (using lazy.nvim): cmd = { "iwes" }, name = "iwes", debounce_text_changes = 500, - auto_format_on_save = true + auto_format_on_save = true, + enable_inlay_hints = true }, mappings = { enable_markdown_mappings = true, @@ -87,7 +88,7 @@ Open any `.md` file in your IWE project and enjoy: | Command | Description | |---------|-------------| | `:IWE init` | Initialize IWE project in current directory | -| `:IWE lsp start/stop/restart/status` | Control LSP server | +| `:IWE lsp start/stop/restart/status/toggle_inlay_hints` | Control LSP server | | `:IWE telescope find_files/paths/roots/grep/backlinks/headers` | Launch Telescope pickers | | `:IWE info` | Show plugin status and configuration | @@ -111,6 +112,7 @@ require('iwe').setup({ lsp = { cmd = { "iwes" }, auto_format_on_save = true, + enable_inlay_hints = true, debounce_text_changes = 500 }, mappings = { diff --git a/lua/iwe/commands.lua b/lua/iwe/commands.lua index 98a29b3..7b39e92 100644 --- a/lua/iwe/commands.lua +++ b/lua/iwe/commands.lua @@ -8,7 +8,7 @@ local telescope = require('iwe.telescope') ---Get completion for LSP commands ---@return string[] local function complete_lsp_commands() - return { 'start', 'stop', 'restart', 'status' } + return { 'start', 'stop', 'restart', 'status', 'toggle_inlay_hints' } end ---Get completion for Telescope commands @@ -77,6 +77,8 @@ local function handle_lsp_command(subcmd) else vim.notify("IWE LSP server is not running") end + elseif subcmd == 'toggle_inlay_hints' then + lsp.toggle_inlay_hints() else vim.notify(string.format("Unknown LSP command: %s", subcmd), vim.log.levels.ERROR) end @@ -125,7 +127,7 @@ local function iwe_command(opts) if subcmd == 'lsp' then if #args < 2 then - vim.notify("Usage: IWE lsp ", vim.log.levels.ERROR) + vim.notify("Usage: IWE lsp ", vim.log.levels.ERROR) return end handle_lsp_command(args[2]) @@ -146,6 +148,7 @@ local function iwe_command(opts) string.format(" Command: %s", table.concat(config.lsp.cmd, " ")), string.format(" Name: %s", config.lsp.name), string.format(" Auto Format: %s", config.lsp.auto_format_on_save), + string.format(" Inlay Hints: %s", config.lsp.enable_inlay_hints), string.format(" Debounce: %dms", config.lsp.debounce_text_changes), "", "Mappings Configuration:", diff --git a/lua/iwe/config.lua b/lua/iwe/config.lua index c0c7e92..3fdd7aa 100644 --- a/lua/iwe/config.lua +++ b/lua/iwe/config.lua @@ -9,6 +9,7 @@ ---@field name string Name of the LSP server ---@field debounce_text_changes number Debounce time for text changes ---@field auto_format_on_save boolean Whether to format on save +---@field enable_inlay_hints boolean Whether to enable inlay hints ---@class IWE.Config.Mappings ---@field enable_markdown_mappings boolean Whether to enable core markdown editing key mappings @@ -30,7 +31,8 @@ M.defaults = { cmd = { "iwes" }, name = "iwes", debounce_text_changes = 500, - auto_format_on_save = true + auto_format_on_save = true, + enable_inlay_hints = true }, mappings = { enable_markdown_mappings = true, diff --git a/lua/iwe/lsp.lua b/lua/iwe/lsp.lua index b3e594c..9632224 100644 --- a/lua/iwe/lsp.lua +++ b/lua/iwe/lsp.lua @@ -9,6 +9,23 @@ function M.is_available() return vim.fn.executable('iwes') == 1 end +---Toggle inlay hints for the current buffer +---@param bufnr? number Buffer number (defaults to current buffer) +function M.toggle_inlay_hints(bufnr) + bufnr = bufnr or vim.api.nvim_get_current_buf() + + if not vim.lsp.inlay_hint then + vim.notify("Inlay hints not available in this Neovim version", vim.log.levels.WARN) + return + end + + local enabled = vim.lsp.inlay_hint.is_enabled({ bufnr = bufnr }) + vim.lsp.inlay_hint.enable(not enabled, { bufnr = bufnr }) + + local status = enabled and "disabled" or "enabled" + vim.notify(string.format("Inlay hints %s", status), vim.log.levels.INFO) +end + ---Start the IWE LSP server for the current buffer ---@param bufnr? number Buffer number (defaults to current buffer) function M.start(bufnr) @@ -50,12 +67,18 @@ function M.setup_autocmds() }) -- Setup LSP attach behavior - if opts.lsp.auto_format_on_save then - vim.api.nvim_create_autocmd("LspAttach", { - group = vim.api.nvim_create_augroup("IWE_LSP_Attach", { clear = true }), - callback = function(args) - local client = vim.lsp.get_client_by_id(args.data.client_id) - if client and client.name == opts.lsp.name then + vim.api.nvim_create_autocmd("LspAttach", { + group = vim.api.nvim_create_augroup("IWE_LSP_Attach", { clear = true }), + callback = function(args) + local client = vim.lsp.get_client_by_id(args.data.client_id) + if client and client.name == opts.lsp.name then + -- Enable inlay hints if configured and supported + if opts.lsp.enable_inlay_hints and vim.lsp.inlay_hint and client.supports_method('textDocument/inlayHint') then + vim.lsp.inlay_hint.enable(true, { bufnr = args.buf }) + end + + -- Setup auto-formatting on save if enabled + if opts.lsp.auto_format_on_save then vim.api.nvim_create_autocmd("BufWritePre", { buffer = args.buf, callback = function() @@ -78,10 +101,10 @@ function M.setup_autocmds() desc = 'Format IWE markdown on save' }) end - end, - desc = 'Setup IWE LSP formatting on attach' - }) - end + end + end, + desc = 'Setup IWE LSP features on attach' + }) end return M diff --git a/lua/iwe/mappings.lua b/lua/iwe/mappings.lua index ebf6447..168a692 100644 --- a/lua/iwe/mappings.lua +++ b/lua/iwe/mappings.lua @@ -174,6 +174,13 @@ function M.setup_plug_mappings() silent = true, desc = 'Go to next diagnostic' }) + + create_plug_mapping('lsp-toggle-inlay-hints', function() + require('iwe.lsp').toggle_inlay_hints() + end, 'n', { + silent = true, + desc = 'Toggle inlay hints' + }) end ---Setup markdown keymaps (only if enabled in config)