breadcrumbs.lua 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. local M = {}
  2. -- local Log = require "lvim.core.log"
  3. M.config = function()
  4. local status_ok, navic = pcall(require, "nvim-navic")
  5. if not status_ok then
  6. return
  7. end
  8. navic.setup {
  9. icons = {
  10. Text = " ",
  11. -- Method = "m",
  12. -- Function = "",
  13. -- Constructor = "",
  14. Method = " ",
  15. Function = " ",
  16. Constructor = " ",
  17. Field = " ",
  18. -- Variable = "",
  19. Variable = " ",
  20. Class = " ",
  21. Interface = " ",
  22. -- Module = "",
  23. Module = " ",
  24. Property = " ",
  25. Unit = " ",
  26. Value = " ",
  27. Enum = " ",
  28. -- Keyword = "",
  29. Keyword = " ",
  30. -- Snippet = "",
  31. Snippet = " ",
  32. Color = " ",
  33. File = " ",
  34. Reference = " ",
  35. Folder = " ",
  36. EnumMember = " ",
  37. Constant = " ",
  38. Struct = " ",
  39. Event = " ",
  40. Operator = " ",
  41. TypeParameter = " ",
  42. Array = " ",
  43. Number = " ",
  44. String = " ",
  45. Boolean = "蘒",
  46. Object = " ",
  47. Package = " ",
  48. Namespace = "",
  49. Key = "",
  50. Null = "ﳠ",
  51. },
  52. highlight = true,
  53. separator = " " .. ">" .. " ",
  54. depth_limit = 0,
  55. depth_limit_indicator = "..",
  56. }
  57. end
  58. M.winbar_filetype_exclude = {
  59. "help",
  60. "startify",
  61. "dashboard",
  62. "packer",
  63. "neogitstatus",
  64. "NvimTree",
  65. "Trouble",
  66. "alpha",
  67. "lir",
  68. "Outline",
  69. "spectre_panel",
  70. "toggleterm",
  71. "DressingSelect",
  72. "Jaq",
  73. "harpoon",
  74. "dapui_scopes",
  75. "dapui_breakpoints",
  76. "dapui_stacks",
  77. "dapui_watches",
  78. "dap-repl",
  79. "dap-terminal",
  80. "dapui_console",
  81. "lab",
  82. "Markdown",
  83. "",
  84. }
  85. M.get_filename = function()
  86. local filename = vim.fn.expand "%:t"
  87. local extension = vim.fn.expand "%:e"
  88. local f = require "lvim.utils.functions"
  89. if not f.isempty(filename) then
  90. local file_icon, file_icon_color =
  91. require("nvim-web-devicons").get_icon_color(filename, extension, { default = true })
  92. local hl_group = "FileIconColor" .. extension
  93. vim.api.nvim_set_hl(0, hl_group, { fg = file_icon_color })
  94. if f.isempty(file_icon) then
  95. file_icon = ""
  96. end
  97. local navic_text = vim.api.nvim_get_hl_by_name("Normal", true)
  98. vim.api.nvim_set_hl(0, "Winbar", { fg = navic_text.foreground })
  99. return " " .. "%#" .. hl_group .. "#" .. file_icon .. "%*" .. " " .. "%#Winbar#" .. filename .. "%*"
  100. end
  101. end
  102. local get_gps = function()
  103. local status_gps_ok, gps = pcall(require, "nvim-navic")
  104. if not status_gps_ok then
  105. return ""
  106. end
  107. local status_ok, gps_location = pcall(gps.get_location, {})
  108. if not status_ok then
  109. return ""
  110. end
  111. if not gps.is_available() or gps_location == "error" then
  112. return ""
  113. end
  114. if not require("lvim.utils.functions").isempty(gps_location) then
  115. -- TODO: replace with chevron
  116. return ">" .. " " .. gps_location
  117. else
  118. return ""
  119. end
  120. end
  121. local excludes = function()
  122. if vim.tbl_contains(M.winbar_filetype_exclude, vim.bo.filetype) then
  123. vim.opt_local.winbar = nil
  124. return true
  125. end
  126. return false
  127. end
  128. M.get_winbar = function()
  129. if excludes() then
  130. return
  131. end
  132. local f = require "lvim.utils.functions"
  133. local value = M.get_filename()
  134. local gps_added = false
  135. if not f.isempty(value) then
  136. local gps_value = get_gps()
  137. value = value .. " " .. gps_value
  138. if not f.isempty(gps_value) then
  139. gps_added = true
  140. end
  141. end
  142. if not f.isempty(value) and f.get_buf_option "mod" then
  143. -- TODO: replace with circle
  144. local mod = "%#LspCodeLens#" .. "" .. "%*"
  145. if gps_added then
  146. value = value .. " " .. mod
  147. else
  148. value = value .. mod
  149. end
  150. end
  151. local num_tabs = #vim.api.nvim_list_tabpages()
  152. if num_tabs > 1 and not f.isempty(value) then
  153. local tabpage_number = tostring(vim.api.nvim_tabpage_get_number(0))
  154. value = value .. "%=" .. tabpage_number .. "/" .. tostring(num_tabs)
  155. end
  156. local status_ok, _ = pcall(vim.api.nvim_set_option_value, "winbar", value, { scope = "local" })
  157. if not status_ok then
  158. return
  159. end
  160. end
  161. M.create_winbar = function()
  162. vim.api.nvim_create_augroup("_winbar", {})
  163. if vim.fn.has "nvim-0.8" == 1 then
  164. vim.api.nvim_create_autocmd(
  165. { "CursorMoved", "CursorHold", "BufWinEnter", "BufFilePost", "InsertEnter", "BufWritePost", "TabClosed" },
  166. {
  167. group = "_winbar",
  168. callback = function()
  169. local status_ok, _ = pcall(vim.api.nvim_buf_get_var, 0, "lsp_floating_window")
  170. if not status_ok then
  171. -- TODO:
  172. require("lvim.core.breadcrumbs").get_winbar()
  173. end
  174. end,
  175. }
  176. )
  177. end
  178. end
  179. M.create_winbar()
  180. return M