Skip to content

Commit

Permalink
fix: get_highlight_value can't format boolean
Browse files Browse the repository at this point in the history
when try to inspect group for example { fg = "#ff0000", italic = true, we can't run this function: string.format("#%02x", true)
  • Loading branch information
loctvl842 committed Mar 6, 2023
1 parent 8b20b4b commit 59fcff8
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 12 deletions.
2 changes: 2 additions & 0 deletions lazy-lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"noice.nvim": { "branch": "main", "commit": "c22651651da01239fc4afac4cdb7261797d5f02e" },
"nui.nvim": { "branch": "main", "commit": "0dc148c6ec06577fcf06cbab3b7dac96d48ba6be" },
"null-ls.nvim": { "branch": "main", "commit": "456cd2754c56c991c5e4df60a807d054c1bc7148" },
"nvim": { "branch": "main", "commit": "e406cf07a1573c77ab83e142cc0d8c9d798d5c81" },
"nvim-cmp": { "branch": "main", "commit": "01f697a68905f9dcae70960a9eb013695a17f9a2" },
"nvim-colorizer.lua": { "branch": "master", "commit": "dde3084106a70b9a79d48f426f6d6fec6fd203f7" },
"nvim-jdtls": { "branch": "master", "commit": "a5c6f38f8151d7b4f5b32c005a95022fa66f4c9d" },
Expand All @@ -50,6 +51,7 @@
"persistence.nvim": { "branch": "main", "commit": "adcf6913693a0434665d162ee45a186230496f8a" },
"playground": { "branch": "master", "commit": "4044b53c4d4fcd7a78eae20b8627f78ce7dc6f56" },
"plenary.nvim": { "branch": "master", "commit": "253d34830709d690f013daf2853a9d21ad7accab" },
"project.nvim": { "branch": "main", "commit": "1c2e9c93c7c85126c2197f5e770054f53b1926fb" },
"promise-async": { "branch": "main", "commit": "38a4575da9497326badd3995e768b4ccf0bb153e" },
"renamer.nvim": { "branch": "master", "commit": "1614d466df53899f11dd5395eaac3c09a275c384" },
"rnvimr": { "branch": "main", "commit": "4f4fbd29e2e0869bea9a8376e06fca4331de60c9" },
Expand Down
14 changes: 7 additions & 7 deletions lua/tvl/config/lualine/highlights.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ local function generate(config, palette)
local float = config.float
local colorful = config.colorful
if colorful then
palette.yellow = util.get_highlight_value("String").foreground
palette.white = util.get_highlight_value("Normal").foreground
palette.red = util.get_highlight_value("DiagnosticError").foreground
palette.orange = util.get_highlight_value("DiagnosticWarn").foreground
palette.blue = util.get_highlight_value("DiagnosticHint").foreground
palette.magenta = util.get_highlight_value("Statement").foreground
palette.green = util.get_highlight_value("healthSuccess").foreground
palette.yellow = util.get_highlight_value("String").foreground or "#ffff00"
palette.white = util.get_highlight_value("Normal").foreground or "#ffffff"
palette.red = util.get_highlight_value("DiagnosticError").foreground or "#ff0000"
palette.orange = util.get_highlight_value("DiagnosticWarn").foreground or "#ff7700"
palette.blue = util.get_highlight_value("DiagnosticHint").foreground or "#00ffff"
palette.magenta = util.get_highlight_value("Statement").foreground or "#ff00ff"
palette.green = util.get_highlight_value("healthSuccess").foreground or "#00ff00"
end
return {
SLGitIcon = {
Expand Down
5 changes: 5 additions & 0 deletions lua/tvl/core/resources/coding.lua
Original file line number Diff line number Diff line change
Expand Up @@ -173,4 +173,9 @@ return {
"glepnir/lspsaga.nvim",
lazy = true,
},

{
"ahmedkhalf/project.nvim",
lazy = true,
},
}
2 changes: 2 additions & 0 deletions lua/tvl/core/resources/colorscheme.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
return {
"catppuccin/nvim",

{
"folke/tokyonight.nvim",
lazy = true,
Expand Down
2 changes: 1 addition & 1 deletion lua/tvl/core/resources/ui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ return {
"nvim-lualine/lualine.nvim",
event = "VeryLazy",
opts = {
float = true,
float = false,
separator = "bubble", -- bubble | triangle
---@type any
colorful = true,
Expand Down
11 changes: 7 additions & 4 deletions lua/tvl/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,13 @@ M.on_attach = function(on_attach)
end

M.get_highlight_value = function(group)
local hl = vim.api.nvim_get_hl_by_name(group, true)
local found, hl = pcall(vim.api.nvim_get_hl_by_name, group, true)
if not found then
error("Invalid highlight name: " .. group)
end
local hl_config = {}
for key, value in pairs(hl) do
hl_config[key] = string.format("#%02x", value)
_, hl_config[key] = pcall(string.format, "#%02x", value)
end
return hl_config
end
Expand All @@ -35,8 +38,8 @@ function M.get_root()
and vim.tbl_map(function(ws)
return vim.uri_to_fname(ws.uri)
end, workspace)
or client.config.root_dir and { client.config.root_dir }
or {}
or client.config.root_dir and { client.config.root_dir }
or {}
for _, p in ipairs(paths) do
local r = vim.loop.fs_realpath(p)
if path:find(r, 1, true) then
Expand Down

0 comments on commit 59fcff8

Please sign in to comment.