mirror of
https://github.com/LunarVim/LunarVim.git
synced 2024-09-21 02:55:09 +02:00
feat: get null-ls registered providers by filetype (#1186)
This commit is contained in:
parent
f36082da0d
commit
8157f50d13
3 changed files with 41 additions and 10 deletions
|
@ -203,25 +203,19 @@ table.insert(gls.right, {
|
|||
local function get_attached_provider_name(msg)
|
||||
msg = msg or "LSP Inactive"
|
||||
local buf_clients = vim.lsp.buf_get_clients()
|
||||
local utils = require "utils"
|
||||
if next(buf_clients) == nil then
|
||||
return msg
|
||||
end
|
||||
local buf_ft = vim.bo.filetype
|
||||
local buf_client_names = {}
|
||||
local null_ls_providers = require("lsp.null-ls").requested_providers
|
||||
local null_ls_providers = require("lsp.null-ls").get_registered_providers_by_filetype(buf_ft)
|
||||
for _, client in pairs(buf_clients) do
|
||||
if client.name == "null-ls" then
|
||||
for _, provider in pairs(null_ls_providers) do
|
||||
if vim.tbl_contains(provider.filetypes, buf_ft) then
|
||||
if not vim.tbl_contains(buf_client_names, provider.name) then
|
||||
table.insert(buf_client_names, provider.name)
|
||||
end
|
||||
end
|
||||
end
|
||||
else
|
||||
if client.name ~= "null-ls" then
|
||||
table.insert(buf_client_names, client.name)
|
||||
end
|
||||
end
|
||||
utils.list_extend_unique(buf_client_names, null_ls_providers)
|
||||
return table.concat(buf_client_names, ", ")
|
||||
end
|
||||
|
||||
|
|
|
@ -6,6 +6,17 @@ local nodejs_local_providers = { "prettier", "prettierd", "prettier_d_slim", "es
|
|||
|
||||
M.requested_providers = {}
|
||||
|
||||
function M.get_registered_providers_by_filetype(ft)
|
||||
local matches = {}
|
||||
for _, provider in pairs(M.requested_providers) do
|
||||
if vim.tbl_contains(provider.filetypes, ft) then
|
||||
table.insert(matches, provider.name)
|
||||
end
|
||||
end
|
||||
|
||||
return matches
|
||||
end
|
||||
|
||||
local function is_nodejs_provider(provider)
|
||||
for _, local_provider in ipairs(nodejs_local_providers) do
|
||||
if local_provider == provider.exe then
|
||||
|
|
|
@ -110,6 +110,32 @@ function utils.is_string(t)
|
|||
return type(t) == "string"
|
||||
end
|
||||
|
||||
--- Extends a list-like table with the unique values of another list-like table.
|
||||
---
|
||||
--- NOTE: This mutates dst!
|
||||
---
|
||||
--@see |vim.tbl_extend()|
|
||||
---
|
||||
--@param dst list which will be modified and appended to.
|
||||
--@param src list from which values will be inserted.
|
||||
--@param start Start index on src. defaults to 1
|
||||
--@param finish Final index on src. defaults to #src
|
||||
--@returns dst
|
||||
function utils.list_extend_unique(dst, src, start, finish)
|
||||
vim.validate {
|
||||
dst = { dst, "t" },
|
||||
src = { src, "t" },
|
||||
start = { start, "n", true },
|
||||
finish = { finish, "n", true },
|
||||
}
|
||||
for i = start or 1, finish or #src do
|
||||
if not vim.tbl_contains(dst, src[i]) then
|
||||
table.insert(dst, src[i])
|
||||
end
|
||||
end
|
||||
return dst
|
||||
end
|
||||
|
||||
function utils.unrequire(m)
|
||||
package.loaded[m] = nil
|
||||
_G[m] = nil
|
||||
|
|
Loading…
Reference in a new issue