-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve ex.lsp.single and ex.lsp.all components (#6)
* docs: improve readme * fix: remove options from pre and post init args * refactor: simplify ex.lsp component implementation using ex.component * fix: match_rendered_component method * docs: improve docs * chore: improve tools * refactor: separate ex.lsp.all and ex.lsp.single * test: add tests for the ex.lsp.single component * test: tests for ex.lsp.all * refactor!: rewrite deep_merge as merge * feat!: introduce hls cache * refactor: move hls cache to the ex.component * refactor!: remove is_enabled from the ex.component options * improve: actualize components on update * chore: improve readme and makefile * fix: ci
- Loading branch information
1 parent
02cb0f5
commit 515c51d
Showing
19 changed files
with
956 additions
and
469 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
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
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
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
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 |
---|---|---|
@@ -0,0 +1,90 @@ | ||
local log = require('plenary.log').new({ plugin = 'ex.lsp.all' }) | ||
local ex = require('lualine.ex') | ||
local SingleLsp = require('lualine.components.ex.lsp.single') | ||
|
||
local function str_escape(str) | ||
str = str:gsub('-', '_') | ||
return str | ||
end | ||
|
||
---@class AllLspOptions: SingleLspOptions | ||
---@field only_attached boolean | ||
---@field icons_only boolean | ||
|
||
---@class AllLspComponent: ExComponent | ||
---@field options AllLspOptions | ||
---@field components table | ||
local AllLsp = require('lualine.ex.component'):extend(SingleLsp.default_options) | ||
|
||
---@protected | ||
function AllLsp:pre_init() | ||
self.options.component_name = 'ex_lsp_all' | ||
self.components = {} | ||
-- will be used to avoid duplicate highlights: | ||
self.__hls_cache = {} | ||
end | ||
|
||
function AllLsp:is_enabled() | ||
return not ex.is_empty(self:__clients()) | ||
end | ||
|
||
---@private | ||
function AllLsp:__clients() | ||
if self.options.only_attached == true then | ||
return vim.lsp.get_active_clients({ bufnr = 0 }) | ||
else | ||
return vim.lsp.get_active_clients() | ||
end | ||
end | ||
|
||
local function key(client) | ||
return client.name .. '_' .. client.id | ||
end | ||
|
||
---@protected | ||
function AllLsp:update_status(is_focused) | ||
local status = '' | ||
if self:is_enabled() then | ||
self.options.icon = nil | ||
local clients = self:__clients() | ||
self:__actualize_components(clients) | ||
for _, client in pairs(clients) do | ||
local key = key(client) | ||
local lsp = self.components[key] | ||
if not lsp then | ||
lsp = SingleLsp:new({ | ||
client = client, | ||
component_name = str_escape('inner_lsp_' .. client.name), | ||
hls_cache = self.__hls_cache, | ||
self = self.options.self, | ||
icons = self.options.icons, | ||
icons_enabled = self.options.icons_enabled, | ||
always_show_icon = self.options.always_show_icon, | ||
icons_only = self.options.icons_only, | ||
disabled_color = self.options.disabled_color, | ||
disabled_icon_color = self.options.disabled_icon_color, | ||
}) | ||
self.components[key] = lsp | ||
end | ||
status = status .. lsp:draw(self.default_hl, is_focused) | ||
end | ||
else | ||
self.options.icon = self.options.icons.lsp_is_off | ||
end | ||
return status | ||
end | ||
|
||
---@private | ||
function AllLsp:__actualize_components(clients) | ||
local actual_components = {} | ||
for _, client in ipairs(clients) do | ||
local key = key(client) | ||
local component = self.components[key] | ||
if component then | ||
actual_components[key] = component | ||
end | ||
end | ||
self.components = actual_components | ||
end | ||
|
||
return AllLsp |
Oops, something went wrong.