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
32 changes: 27 additions & 5 deletions lua/swift/features/lsp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -124,18 +124,23 @@ function M.default_on_attach(client, bufnr)
vim.keymap.set("n", "<leader>e", vim.diagnostic.open_float, opts)
vim.keymap.set("n", "<leader>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)
Expand Down Expand Up @@ -214,14 +219,31 @@ 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")
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

Expand Down
5 changes: 5 additions & 0 deletions lua/swift/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Loading