aboutsummaryrefslogtreecommitdiff
path: root/lua/plugins/heirline.lua
diff options
context:
space:
mode:
Diffstat (limited to 'lua/plugins/heirline.lua')
-rw-r--r--lua/plugins/heirline.lua155
1 files changed, 92 insertions, 63 deletions
diff --git a/lua/plugins/heirline.lua b/lua/plugins/heirline.lua
index 03b2a47..47ffe18 100644
--- a/lua/plugins/heirline.lua
+++ b/lua/plugins/heirline.lua
@@ -123,69 +123,98 @@ local LSPActive = {
hl = { fg = colors.lightgray, bold = false },
}
--- Navic
local Navic = {
- condition = require("nvim-navic").is_available,
- static = {
- -- create a type highlight map
- type_hl = {
- File = "Directory",
- Module = "Include",
- Namespace = "TSNamespace",
- Package = "Include",
- Class = "Struct",
- Method = "Method",
- Property = "TSProperty",
- Field = "TSField",
- Constructor = "TSConstructor ",
- Enum = "TSField",
- Interface = "Type",
- Function = "Function",
- Variable = "TSVariable",
- Constant = "Constant",
- String = "String",
- Number = "Number",
- Boolean = "Boolean",
- Array = "TSField",
- Object = "Type",
- Key = "TSKeyword",
- Null = "Comment",
- EnumMember = "TSField",
- Struct = "Struct",
- Event = "Keyword",
- Operator = "Operator",
- TypeParameter = "Type",
- },
- },
- init = function(self)
- local data = require("nvim-navic").get_data() or {}
- local children = {}
- -- create a child for each level
- for i, d in ipairs(data) do
- local child = {
- {
- provider = d.icon,
- hl = self.type_hl[d.type],
- },
- {
- provider = d.name,
- -- highlight icon only or location name as well
- -- hl = self.type_hl[d.type],
- },
- }
- -- add a separator only if needed
- if #data > 1 and i < #data then
- table.insert(child, {
- provider = " > ",
- hl = { fg = colors.white },
- })
- end
- table.insert(children, child)
- end
- -- instantiate the new child, overwriting the previous one
- self[1] = self:new(children, 1)
- end,
- hl = { fg = colors.white },
+ condition = require("nvim-navic").is_available,
+ static = {
+ -- create a type highlight map
+ type_hl = {
+ File = "Directory",
+ Module = "@include",
+ Namespace = "@namespace",
+ Package = "@include",
+ Class = "@structure",
+ Method = "@method",
+ Property = "@property",
+ Field = "@field",
+ Constructor = "@constructor",
+ Enum = "@field",
+ Interface = "@type",
+ Function = "@function",
+ Variable = "@variable",
+ Constant = "@constant",
+ String = "@string",
+ Number = "@number",
+ Boolean = "@boolean",
+ Array = "@field",
+ Object = "@type",
+ Key = "@keyword",
+ Null = "@comment",
+ EnumMember = "@field",
+ Struct = "@structure",
+ Event = "@keyword",
+ Operator = "@operator",
+ TypeParameter = "@type",
+ },
+ -- bit operation dark magic, see below...
+ enc = function(line, col, winnr)
+ return bit.bor(bit.lshift(line, 16), bit.lshift(col, 6), winnr)
+ end,
+ -- line: 16 bit (65535); col: 10 bit (1023); winnr: 6 bit (63)
+ dec = function(c)
+ local line = bit.rshift(c, 16)
+ local col = bit.band(bit.rshift(c, 6), 1023)
+ local winnr = bit.band(c, 63)
+ return line, col, winnr
+ end
+ },
+ init = function(self)
+ local data = require("nvim-navic").get_data() or {}
+ local children = {}
+ -- create a child for each level
+ for i, d in ipairs(data) do
+ -- encode line and column numbers into a single integer
+ local pos = self.enc(d.scope.start.line, d.scope.start.character, self.winnr)
+ local child = {
+ {
+ provider = d.icon,
+ hl = self.type_hl[d.type],
+ },
+ {
+ -- escape `%`s (elixir) and buggy default separators
+ provider = d.name:gsub("%%", "%%%%"):gsub("%s*->%s*", ''),
+ -- highlight icon only or location name as well
+ -- hl = self.type_hl[d.type],
+
+ on_click = {
+ -- pass the encoded position through minwid
+ minwid = pos,
+ callback = function(_, minwid)
+ -- decode
+ local line, col, winnr = self.dec(minwid)
+ vim.api.nvim_win_set_cursor(vim.fn.win_getid(winnr), {line, col})
+ end,
+ name = "heirline_navic",
+ },
+ },
+ }
+ -- add a separator only if needed
+ if #data > 1 and i < #data then
+ table.insert(child, {
+ provider = " > ",
+ hl = { fg = 'bright_fg' },
+ })
+ end
+ table.insert(children, child)
+ end
+ -- instantiate the new child, overwriting the previous one
+ self.child = self:new(children, 1)
+ end,
+ -- evaluate the children containing navic components
+ provider = function(self)
+ return self.child:eval()
+ end,
+ hl = { fg = colors.white },
+ update = 'CursorMoved'
}
-- Diagnostics
@@ -723,7 +752,7 @@ local left = {
}
local middle = {
{ Align, hl = { bg = utils.get_highlight("statusline").bg, force = true } },
- { Navic, hl = { bg = utils.get_highlight("statusline").bg, force = true } },
+ --{ Navic, hl = { bg = utils.get_highlight("statusline").bg, force = true } },
{ DAPMessages, hl = { bg = utils.get_highlight("statusline").bg, force = true } },
{ Align, hl = { bg = utils.get_highlight("statusline").bg, force = true } },
}