Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 |

Expand All @@ -111,6 +112,7 @@ require('iwe').setup({
lsp = {
cmd = { "iwes" },
auto_format_on_save = true,
enable_inlay_hints = true,
debounce_text_changes = 500
},
mappings = {
Expand Down
7 changes: 5 additions & 2 deletions lua/iwe/commands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -125,7 +127,7 @@ local function iwe_command(opts)

if subcmd == 'lsp' then
if #args < 2 then
vim.notify("Usage: IWE lsp <start|stop|restart|status>", vim.log.levels.ERROR)
vim.notify("Usage: IWE lsp <start|stop|restart|status|toggle_inlay_hints>", vim.log.levels.ERROR)
return
end
handle_lsp_command(args[2])
Expand All @@ -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:",
Expand Down
4 changes: 3 additions & 1 deletion lua/iwe/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down
43 changes: 33 additions & 10 deletions lua/iwe/lsp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand All @@ -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
7 changes: 7 additions & 0 deletions lua/iwe/mappings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading