Skip to content

Commit

Permalink
fix: trouble extension. Support Trouble.nvim v3 and keep backward com…
Browse files Browse the repository at this point in the history
…patibility
  • Loading branch information
xieyonn committed Feb 20, 2025
1 parent f4f791f commit d72f3dc
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions lua/lualine/extensions/trouble.lua
Original file line number Diff line number Diff line change
@@ -1,22 +1,40 @@
local M = {}

local function get_trouble_mode()
local opts = require('trouble.config').options

local words = vim.split(opts.mode, '[%W]')
---Format mode, eg: lsp_document_symbols -> Lsp Document Symbols
---@param mode string
---@return string
local function _format_mode(mode)
local words = vim.split(mode, '[%W]')
for i, word in ipairs(words) do
words[i] = word:sub(1, 1):upper() .. word:sub(2)
end

return table.concat(words, ' ')
end

local function get_trouble_mode()
local opts = require('trouble.config').options
if opts ~= nil and opts.mode ~= nil then
return _format_mode(opts.mode)
end

local win = vim.api.nvim_get_current_win()
if vim.w[win] ~= nil then
local trouble = vim.w[win].trouble
if trouble ~= nil and trouble.mode ~= nil then
return _format_mode(trouble.mode)
end
end

return ''
end

M.sections = {
lualine_a = {
get_trouble_mode,
},
}

M.filetypes = { 'Trouble' }
M.filetypes = { 'trouble', 'Trouble' }

return M

0 comments on commit d72f3dc

Please sign in to comment.