Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: trouble extension. Works on Trouble.nvim v3 and keep backward compatibility. #1383

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading