From f619bcc0c2089fc62f97c914c88bd13ec9916ef3 Mon Sep 17 00:00:00 2001 From: Asiel Cabrera Date: Sun, 3 May 2026 16:06:52 -0400 Subject: [PATCH] feat(lsp): enable inlay hints by default for Neovim 0.10+ - Guards inlay hint activation with vim.fn.has('nvim-0.10') check - Adds toggle_inlay_hints() function with clear on/off notification - Adds global :SwiftToggleInlayHints command - Adds :SwiftTelescopeSchemes and :SwiftTelescopeTargets to main commands - Fixes deprecated vim.lsp.get_active_clients() -> vim.lsp.get_clients() --- lua/swift/features/lsp.lua | 32 +++++++++++++++++++++++++++----- lua/swift/init.lua | 5 +++++ 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/lua/swift/features/lsp.lua b/lua/swift/features/lsp.lua index aa6a2ea..cfc908e 100644 --- a/lua/swift/features/lsp.lua +++ b/lua/swift/features/lsp.lua @@ -124,18 +124,23 @@ function M.default_on_attach(client, bufnr) vim.keymap.set("n", "e", vim.diagnostic.open_float, opts) vim.keymap.set("n", "q", vim.diagnostic.setloclist, opts) - -- Inlay hints + -- Inlay hints (requires Neovim 0.10+) if config.inlay_hints and client.server_capabilities.inlayHintProvider then - if vim.lsp.inlay_hint then + if vim.fn.has("nvim-0.10") == 1 and vim.lsp.inlay_hint then vim.lsp.inlay_hint.enable(true, { bufnr = bufnr }) end end - -- Semantic tokens + -- Semantic tokens (enabled by default in Neovim 0.9+) if config.semantic_tokens and client.server_capabilities.semanticTokensProvider then - -- Semantic tokens are enabled by default in Neovim 0.9+ + -- Semantic tokens are handled automatically by Neovim end + -- Toggle inlay hints command (buffer-local) + vim.api.nvim_buf_create_user_command(bufnr, "SwiftToggleInlayHints", function() + M.toggle_inlay_hints(bufnr) + end, { desc = "Toggle Swift inlay hints" }) + -- Call user's on_attach if provided if config.on_attach then config.on_attach(client, bufnr) @@ -214,6 +219,22 @@ function M.get_lsp_config() } end +-- Toggle inlay hints for a buffer +function M.toggle_inlay_hints(bufnr) + bufnr = bufnr or vim.api.nvim_get_current_buf() + + if vim.fn.has("nvim-0.10") == 0 or not vim.lsp.inlay_hint then + vim.notify("Inlay hints require Neovim 0.10+", vim.log.levels.WARN, { title = "swift.nvim" }) + return + end + + local enabled = vim.lsp.inlay_hint.is_enabled({ bufnr = bufnr }) + vim.lsp.inlay_hint.enable(not enabled, { bufnr = bufnr }) + + local state = not enabled and "enabled" or "disabled" + vim.notify("Inlay hints " .. state, vim.log.levels.INFO, { title = "swift.nvim" }) +end + -- Restart LSP server function M.restart() vim.cmd("LspRestart sourcekit") @@ -221,7 +242,8 @@ end -- Get LSP client info function M.get_client() - local clients = vim.lsp.get_active_clients({ name = "sourcekit" }) + local get_clients = vim.lsp.get_clients or vim.lsp.get_active_clients + local clients = get_clients({ name = "sourcekit" }) return clients[1] end diff --git a/lua/swift/init.lua b/lua/swift/init.lua index 5723831..566ca35 100644 --- a/lua/swift/init.lua +++ b/lua/swift/init.lua @@ -73,6 +73,11 @@ function M.setup_commands() local telescope = require("swift.integrations.telescope") telescope.swift_targets() end, { desc = "Select Swift Target with Telescope" }) + + vim.api.nvim_create_user_command("SwiftToggleInlayHints", function() + local lsp = require("swift.features.lsp") + lsp.toggle_inlay_hints() + end, { desc = "Toggle inlay hints for current buffer (Neovim 0.10+)" }) end function M.setup_autocmds()