Skip to content

Commit

Permalink
Update root_dir to take bufnr as second argument when function; updat…
Browse files Browse the repository at this point in the history
…e root_dir function to support async when returns function
  • Loading branch information
chipsenkbeil committed Jun 26, 2023
1 parent 2024af2 commit d78a92e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
6 changes: 6 additions & 0 deletions lua/distant-core/api/searcher.lua
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,16 @@ M.__index = M
--- @field include? distant.core.api.search.QueryCondition
--- @field exclude? distant.core.api.search.QueryCondition
--- @field follow_symbolic_links? boolean
--- @field ignore_hidden? boolean
--- @field limit? integer
--- @field max_depth? integer
--- @field pagination? integer
--- @field upward? boolean
--- @field use_git_exclude_files? boolean
--- @field use_git_ignore_files? boolean
--- @field use_global_git_ignore_files? boolean
--- @field use_ignore_files? boolean
--- @field use_parent_ignore_files? boolean

--- @param opts {transport:distant.core.api.Transport}
--- @return distant.core.api.Searcher
Expand Down
18 changes: 15 additions & 3 deletions lua/distant-core/client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,12 @@ function M:connect_lsp_clients(opts)
elseif type(config_root_dir) == 'table' then
root_dir = find(config_root_dir, path_starts_with)
elseif config_root_dir and callable(config_root_dir) then
root_dir = config_root_dir(path)
root_dir = config_root_dir(path, opts.bufnr)
end

-- Only apply client with a root directory that contains this file
if root_dir then
--- Performs actual process of attaching a client to a buffer using the `root_dir`.
--- @param root_dir string
local function do_connect_client(root_dir)
log.fmt_trace('File %s is within %s of %s', path, root_dir, label)

-- Check if this lsp is filtered by filetype, and if so make sure that
Expand Down Expand Up @@ -222,6 +223,17 @@ function M:connect_lsp_clients(opts)
end
end
end

-- Only apply client with a root directory that contains this file. If the root_dir
-- was set to a function, we assume that we are running async and instead provide
-- a callback function that will perform the connection.
if type(root_dir) == 'string' then
do_connect_client(root_dir)
elseif root_dir ~= nil and callable(root_dir) then
vim.schedule(function()
root_dir(do_connect_client)
end)
end
end
end

Expand Down
2 changes: 1 addition & 1 deletion lua/distant/default.lua
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ local DEFAULT_SETTINGS = {
default = {},
},

--- @alias distant.plugin.settings.server.lsp.RootDirFn fun(path:string):string|nil
--- @alias distant.plugin.settings.server.lsp.RootDirFn fun(path:string, bufnr:number):string|nil
--- @class distant.plugin.settings.server.lsp.ServerSettings
--- @field cmd string|string[]
--- @field root_dir string|string[]|distant.plugin.settings.server.lsp.RootDirFn
Expand Down

0 comments on commit d78a92e

Please sign in to comment.