Skip to content

Instantly share code, notes, and snippets.

@dapicester
Forked from Lamarcke/lualine.lua
Created November 9, 2023 10:00
Show Gist options
  • Select an option

  • Save dapicester/3aee36a0451a5873307c67a8a36c74ce to your computer and use it in GitHub Desktop.

Select an option

Save dapicester/3aee36a0451a5873307c67a8a36c74ce to your computer and use it in GitHub Desktop.

Revisions

  1. @Lamarcke Lamarcke revised this gist Aug 14, 2023. No changes.
  2. @Lamarcke Lamarcke revised this gist Aug 14, 2023. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion lualine.lua
    Original file line number Diff line number Diff line change
    @@ -90,7 +90,7 @@ return {
    event = { "VimEnter", "BufReadPost", "BufNewFile" },
    config = function()
    local attached_clients = {
    attached_clients,
    get_attached_clients,
    color = {
    gui = "bold"
    }
  3. @Lamarcke Lamarcke revised this gist Aug 14, 2023. 1 changed file with 80 additions and 52 deletions.
    132 changes: 80 additions & 52 deletions lualine.lua
    Original file line number Diff line number Diff line change
    @@ -1,84 +1,112 @@
    -- The LSP stuff is excerpt from Lunarvim
    local function attached_clients()
    local buf_clients = vim.lsp.get_active_clients { bufnr = 0 }
    if #buf_clients == 0 then
    return "LSP Inactive"
    end
    -- Returns a string with a list of attached LSP clients, including
    -- formatters and linters from null-ls, nvim-lint and formatter.nvim

    local buf_ft = vim.bo.filetype
    local buf_client_names = {}

    local function get_attached_clients()
    local buf_clients = vim.lsp.get_active_clients({ bufnr = 0 })
    if #buf_clients == 0 then
    return "LSP Inactive"
    end

    -- add client
    for _, client in pairs(buf_clients) do
    if client.name ~= "copilot" then
    table.insert(buf_client_names, client.name)
    end
    local buf_ft = vim.bo.filetype
    local buf_client_names = {}

    end
    -- add client
    for _, client in pairs(buf_clients) do
    if client.name ~= "copilot" and client.name ~= "null-ls" then
    table.insert(buf_client_names, client.name)
    end
    end

    -- Generally, you should use either null-ls or nvim-lint + formatter.nvim, not both.

    -- Add sources (from null-ls)
    -- null-ls registers each source as a separate attached client, so we need to filter for unique names down below.
    local null_ls_s, null_ls = pcall(require, "null-ls")
    if null_ls_s then
    local sources = null_ls.get_sources()
    for _, source in ipairs(sources) do
    if source._validated then
    for ft_name, ft_active in pairs(source.filetypes) do
    if ft_name == buf_ft and ft_active then
    table.insert(buf_client_names, source.name)
    end
    end
    end
    end
    end

    -- Add linters (from nvim-lint)
    local lint_s, lint = pcall(require, "lint")
    if lint_s then
    for ft_k, ft_v in pairs(lint.linters_by_ft) do
    if (type(ft_v) == "table") then
    for _, linter in ipairs(ft_v) do
    if buf_ft == ft_k then
    table.insert(buf_client_names, linter)
    end
    end
    elseif type(ft_v) == "string" then
    if buf_ft == ft_k then
    table.insert(buf_client_names, ft_v)
    end
    end
    end
    end
    -- Add linters (from nvim-lint)
    local lint_s, lint = pcall(require, "lint")
    if lint_s then
    for ft_k, ft_v in pairs(lint.linters_by_ft) do
    if type(ft_v) == "table" then
    for _, linter in ipairs(ft_v) do
    if buf_ft == ft_k then
    table.insert(buf_client_names, linter)
    end
    end
    elseif type(ft_v) == "string" then
    if buf_ft == ft_k then
    table.insert(buf_client_names, ft_v)
    end
    end
    end
    end

    -- Add formatters (from formatter.nvim)
    local formatter_s, formatter = pcall(require, "formatter")
    if formatter_s then
    local formatter_config = require("formatter.config")
    local user_defined_formatters = formatter_config.values.filetype
    for formatter_filetype, formatter_functions in pairs(user_defined_formatters) do
    if formatter_filetype == "*" or buf_ft == formatter_filetype then
    for _, formatter_function in ipairs(formatter_functions) do
    local formatter_info = formatter_function()
    table.insert(buf_client_names, formatter_info.exe)
    end
    end
    end
    end
    -- Add formatters (from formatter.nvim)
    local formatter_s, _ = pcall(require, "formatter")
    if formatter_s then
    local formatter_util = require("formatter.util")
    for _, formatter in ipairs(formatter_util.get_available_formatters_for_ft(buf_ft)) do
    if formatter then
    table.insert(buf_client_names, formatter)
    end
    end
    end

    -- This needs to be a string only table so we can use concat below
    local unique_client_names = {}
    for _, client_name_target in ipairs(buf_client_names) do
    local is_duplicate = false
    for _, client_name_compare in ipairs(unique_client_names) do
    if client_name_target == client_name_compare then
    is_duplicate = true
    end
    end
    if not is_duplicate then
    table.insert(unique_client_names, client_name_target)
    end
    end

    local unique_client_names = table.concat(buf_client_names, ", ")
    local language_servers = string.format("[%s]", unique_client_names)
    local client_names_str = table.concat(unique_client_names, ", ")
    local language_servers = string.format("[%s]", client_names_str)

    return language_servers
    return language_servers
    end


    return {
    "nvim-lualine/lualine.nvim",
    event = { "VimEnter", "BufReadPost", "BufNewFile" },
    config = function()
    local lsp_component = {
    local attached_clients = {
    attached_clients,
    color = {
    gui = "bold"
    }
    }
    -- Example lualine setup
    require("lualine").setup({
    options = {
    theme = "auto",
    globalstatus = true,
    component_separators = { left = "|", right = "|" },
    },


    sections = {
    lualine_b = { "branch", "diff" },
    lualine_x = { "diagnostics", lsp_component, "filetype" },
    lualine_x = { "diagnostics", attached_clients, "filetype" },

    }
    })
  4. @Lamarcke Lamarcke revised this gist Aug 14, 2023. 1 changed file with 2 additions and 10 deletions.
    12 changes: 2 additions & 10 deletions lualine.lua
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    -- The LSP+copilot_active stuff is excerpt from Lunarvim
    -- The LSP stuff is excerpt from Lunarvim
    local function attached_clients()
    local buf_clients = vim.lsp.get_active_clients { bufnr = 0 }
    if #buf_clients == 0 then
    @@ -7,17 +7,14 @@ local function attached_clients()

    local buf_ft = vim.bo.filetype
    local buf_client_names = {}
    local copilot_active = false


    -- add client
    for _, client in pairs(buf_clients) do
    if client.name ~= "copilot" then
    table.insert(buf_client_names, client.name)
    end

    if client.name == "copilot" then
    copilot_active = true
    end
    end


    @@ -58,11 +55,6 @@ local function attached_clients()
    local unique_client_names = table.concat(buf_client_names, ", ")
    local language_servers = string.format("[%s]", unique_client_names)


    if copilot_active then
    language_servers = language_servers .. "%#SLCopilot#" .. " " .. "" .. "%*"
    end

    return language_servers
    end

  5. @Lamarcke Lamarcke created this gist Aug 14, 2023.
    94 changes: 94 additions & 0 deletions lualine.lua
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,94 @@
    -- The LSP+copilot_active stuff is excerpt from Lunarvim
    local function attached_clients()
    local buf_clients = vim.lsp.get_active_clients { bufnr = 0 }
    if #buf_clients == 0 then
    return "LSP Inactive"
    end

    local buf_ft = vim.bo.filetype
    local buf_client_names = {}
    local copilot_active = false

    -- add client
    for _, client in pairs(buf_clients) do
    if client.name ~= "copilot" then
    table.insert(buf_client_names, client.name)
    end

    if client.name == "copilot" then
    copilot_active = true
    end
    end


    -- Add linters (from nvim-lint)
    local lint_s, lint = pcall(require, "lint")
    if lint_s then
    for ft_k, ft_v in pairs(lint.linters_by_ft) do
    if (type(ft_v) == "table") then
    for _, linter in ipairs(ft_v) do
    if buf_ft == ft_k then
    table.insert(buf_client_names, linter)
    end
    end
    elseif type(ft_v) == "string" then
    if buf_ft == ft_k then
    table.insert(buf_client_names, ft_v)
    end
    end
    end
    end

    -- Add formatters (from formatter.nvim)
    local formatter_s, formatter = pcall(require, "formatter")
    if formatter_s then
    local formatter_config = require("formatter.config")
    local user_defined_formatters = formatter_config.values.filetype
    for formatter_filetype, formatter_functions in pairs(user_defined_formatters) do
    if formatter_filetype == "*" or buf_ft == formatter_filetype then
    for _, formatter_function in ipairs(formatter_functions) do
    local formatter_info = formatter_function()
    table.insert(buf_client_names, formatter_info.exe)
    end
    end
    end
    end


    local unique_client_names = table.concat(buf_client_names, ", ")
    local language_servers = string.format("[%s]", unique_client_names)


    if copilot_active then
    language_servers = language_servers .. "%#SLCopilot#" .. " " .. "" .. "%*"
    end

    return language_servers
    end

    return {
    "nvim-lualine/lualine.nvim",
    event = { "VimEnter", "BufReadPost", "BufNewFile" },
    config = function()
    local lsp_component = {
    attached_clients,
    color = {
    gui = "bold"
    }
    }
    require("lualine").setup({
    options = {
    theme = "auto",
    globalstatus = true,
    component_separators = { left = "|", right = "|" },
    },


    sections = {
    lualine_b = { "branch", "diff" },
    lualine_x = { "diagnostics", lsp_component, "filetype" },

    }
    })
    end,
    }