Skip to content

Commit

Permalink
Merge pull request #32 from mikehaertl/30-client-capabilities
Browse files Browse the repository at this point in the history
Issue #30 Add utility to get client capabilities for LSP server config
  • Loading branch information
antosha417 authored Jun 15, 2024
2 parents 223aca8 + 3de296f commit 92a673d
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,28 @@ require("lsp-file-operations").setup {
timeout_ms = 10000,
}
```
Some LSP servers also expect to be informed about the extended client capabilities.
If you use [nvim-lspconfig](https:/neovim/nvim-lspconfig) you can configure the default client capabilities that will
be sent to all servers like this:

```lua
local lspconfig = require'lspconfig'

-- Set global defaults for all servers
lspconfig.util.default_config = vim.tbl_extend(
'force',
lspconfig.util.default_config,
{
capabilities = vim.tbl_deep_extend(
"force",
vim.lsp.protocol.make_client_capabilities(),
-- returns configured operations if setup() was already called
-- or default operations if not
require'lsp-file-operations'.default_capabilities(),
)
}
)
```

## Contributing

Expand Down
24 changes: 24 additions & 0 deletions lua/lsp-file-operations.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ local modules = {
didDeleteFiles = "lsp-file-operations.did-delete",
}

local capabilities = {
willRenameFiles = "willRename",
didRenameFiles = "didRename",
willCreateFiles = "willCreate",
didCreateFiles = "didCreate",
willDeleteFiles = "willDelete",
didDeleteFiles = "didDelete",
}

---@alias HandlerMap table<string, string[]> a mapping from modules to events that trigger it

--- helper function to subscribe events to a given module callback
Expand Down Expand Up @@ -108,4 +117,19 @@ M.setup = function(opts)
end
end

--- The extra client capabilities provided by this plugin. To be merged with
--- vim.lsp.protocol.make_client_capabilities() and sent to the LSP server.
M.default_capabilities = function()
local config = M.config or default_config
local result = {
workspace = {
fileOperations = {}
}
}
for operation, capability in pairs(capabilities) do
result.workspace.fileOperations[capability] = config.operations[operation]
end
return result
end

return M

0 comments on commit 92a673d

Please sign in to comment.