Skip to content

Commit

Permalink
Prepare for initial release
Browse files Browse the repository at this point in the history
  • Loading branch information
speelbarrow committed May 1, 2024
1 parent 4fa493e commit 19e33a7
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
26 changes: 26 additions & 0 deletions doc/spLauncher.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Table of Contents *spLauncher-toc*
2. Handlers |spLauncher-handlers|
3. Configuration |spLauncher-config|
4. spLaunching |spLauncher-spLaunch|
5. Utility functions |spLauncher-utils|

==============================================================================
1. The Action Map *spLauncher-actions*
Expand Down Expand Up @@ -229,4 +230,29 @@ table/VimScript dictionary):
>lua
require "spLauncher".direct_spLaunch(--[[ command ]], 0, ...)
<
==============================================================================
5. Utility functions *spLauncher-utils*

Utility functions can be accessed through the `"spLauncher.util"` Lua module.
The following functions are provided:

- `workspace`: Overrides the action map for the buffer when a language server
attaches with a valid `root_dir`
- Arguments:
- `lsp` (`string`): The language server that should be checked for a
| `root_dir`
- `config` (`spLauncher.Config`): The override configuration for
|spLauncher-config| | 'workspace' mode to be merged in
- `bufnr` (`integer | nil`): The buffer whose action map should be
| modified, defaults to |nvim_get_current_buf()|

- Example: `ftplugin/lua.lua`>lua
vim.b.spLauncherActionMap = {
-- ... regular config ...
}

require "spLauncher.util".workspace("lua_ls", {
-- ... special workspace config ...
})
<
vim:tw=78:ft=help:norl:et:ts=2:sw=2:fen:fdl=0:
2 changes: 1 addition & 1 deletion lua/spLauncher/types.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---@meta spLauncher
---@meta _

---@class spLauncher.ActionMap See `:help splauncher-actions`
---@field base? string
Expand Down
20 changes: 20 additions & 0 deletions lua/spLauncher/util.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
local M = {}

--- Override the action map for the buffer when a language server attaches with a valid `root_dir`
---@param lsp string The language server name
---@param config spLauncher.Config The override configuration for 'workspace' mode to be merged in
---@param bufnr? integer The buffer whose action map should be modified, defaults to `vim.api.nvim_get_current_buf()`
function M.workspace(lsp, config, bufnr)
vim.api.nvim_create_autocmd("LspAttach", {
buffer = bufnr or vim.api.nvim_get_current_buf(),
callback = function(args)
local client = vim.lsp.get_client_by_id(args.data.client_id)

if client and client.name == lsp and client.config.root_dir ~= nil and client.config.root_dir ~= "" then
vim.b[args.buf].spLauncherActionMap = vim.tbl_deep_extend("force", vim.b[args.buf].spLauncherActionMap, config)
end
end,
})
end

return M

0 comments on commit 19e33a7

Please sign in to comment.