-
Notifications
You must be signed in to change notification settings - Fork 482
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: trouble extension. Support Trouble.nvim v3 and keep backward com…
…patibility
- Loading branch information
Showing
1 changed file
with
23 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |