Fix the galaxyline null pointer issue (#1179)

This commit is contained in:
Abouzar Parvan 2021-07-30 23:14:25 +04:30 committed by GitHub
parent 176106f223
commit ce8c63c6bf
WARNING! Although there is a key with this ID in the database it does not verify this commit! This commit is SUSPICIOUS.
GPG key ID: 4AEE18F83AFDEB23

View file

@ -200,19 +200,38 @@ table.insert(gls.right, {
}, },
}) })
-- TODO: this function doesn't need to be this complicated
local function get_attached_provider_name(msg) local function get_attached_provider_name(msg)
msg = msg or "LSP Inactive" msg = msg or "LSP Inactive"
local buf_ft = vim.bo.filetype local buf_ft = vim.bo.filetype
local buf_clients = vim.lsp.buf_get_clients() local buf_clients = vim.lsp.buf_get_clients()
if next(buf_clients) == nil then if next(buf_clients) == nil then
return msg return msg
end end
local utils = require "utils"
local config = require("null-ls.config").get()
local builtins = require "null-ls.builtins"
-- concat all the builtin formatters and linters from null-ls
local all_things = builtins.formatting
for k, v in pairs(builtins.diagnostics) do
all_things[k] = v
end
-- if we open multiple filetypes in the same session
-- null-ls will register multiple formatter/linters
-- but only use the ones that support vim.bo.filetype
-- so we need to filter them
local buf_client_names = {} local buf_client_names = {}
for _, client in pairs(buf_clients) do for _, client in pairs(buf_clients) do
if client.name == "null-ls" then if client.name == "null-ls" then
table.insert(buf_client_names, lvim.lang[buf_ft].linters[1]) -- for every registered formatter/linter in the current buffer
table.insert(buf_client_names, lvim.lang[buf_ft].formatter.exe) for _, v in pairs(config._names) do
-- show only the ones that are being used for the current filetype
if utils.has_value(all_things[v].filetypes, buf_ft) then
table.insert(buf_client_names, v)
end
end
else else
table.insert(buf_client_names, client.name) table.insert(buf_client_names, client.name)
end end