components.lua 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. local conditions = require "lvim.core.lualine.conditions"
  2. local colors = require "lvim.core.lualine.colors"
  3. local function diff_source()
  4. local gitsigns = vim.b.gitsigns_status_dict
  5. if gitsigns then
  6. return {
  7. added = gitsigns.added,
  8. modified = gitsigns.changed,
  9. removed = gitsigns.removed,
  10. }
  11. end
  12. end
  13. local location_color = "SLBranchName"
  14. local branch = "%#SLGitIcon#" .. lvim.icons.git.Branch .. "%*" .. "%#SLBranchName#"
  15. return {
  16. mode = {
  17. function()
  18. return " " .. lvim.icons.ui.Target .. " "
  19. end,
  20. padding = { left = 0, right = 0 },
  21. color = {},
  22. cond = nil,
  23. },
  24. branch = {
  25. "b:gitsigns_head",
  26. icon = branch,
  27. color = { gui = "bold" },
  28. },
  29. filename = {
  30. "filename",
  31. color = {},
  32. cond = nil,
  33. },
  34. diff = {
  35. "diff",
  36. source = diff_source,
  37. symbols = {
  38. added = lvim.icons.git.LineAdded .. " ",
  39. modified = lvim.icons.git.LineModified .. " ",
  40. removed = lvim.icons.git.LineRemoved .. " ",
  41. },
  42. padding = { left = 2, right = 1 },
  43. diff_color = {
  44. added = { fg = colors.green },
  45. modified = { fg = colors.yellow },
  46. removed = { fg = colors.red },
  47. },
  48. cond = nil,
  49. },
  50. python_env = {
  51. function()
  52. local utils = require "lvim.core.lualine.utils"
  53. if vim.bo.filetype == "python" then
  54. local venv = os.getenv "CONDA_DEFAULT_ENV" or os.getenv "VIRTUAL_ENV"
  55. if venv then
  56. local icons = require "nvim-web-devicons"
  57. local py_icon, _ = icons.get_icon ".py"
  58. return string.format(" " .. py_icon .. " (%s)", utils.env_cleanup(venv))
  59. end
  60. end
  61. return ""
  62. end,
  63. color = { fg = colors.green },
  64. cond = conditions.hide_in_width,
  65. },
  66. diagnostics = {
  67. "diagnostics",
  68. sources = { "nvim_diagnostic" },
  69. symbols = {
  70. error = lvim.icons.diagnostics.BoldError .. " ",
  71. warn = lvim.icons.diagnostics.BoldWarning .. " ",
  72. info = lvim.icons.diagnostics.BoldInformation .. " ",
  73. hint = lvim.icons.diagnostics.BoldHint .. " ",
  74. },
  75. -- cond = conditions.hide_in_width,
  76. },
  77. treesitter = {
  78. function()
  79. return lvim.icons.ui.Tree
  80. end,
  81. color = function()
  82. local buf = vim.api.nvim_get_current_buf()
  83. local ts = vim.treesitter.highlighter.active[buf]
  84. return { fg = ts and not vim.tbl_isempty(ts) and colors.green or colors.red }
  85. end,
  86. cond = conditions.hide_in_width,
  87. },
  88. lsp = {
  89. function(msg)
  90. msg = msg or "LS Inactive"
  91. local buf_clients = vim.lsp.buf_get_clients()
  92. if next(buf_clients) == nil then
  93. -- TODO: clean up this if statement
  94. if type(msg) == "boolean" or #msg == 0 then
  95. return "LS Inactive"
  96. end
  97. return msg
  98. end
  99. local buf_ft = vim.bo.filetype
  100. local buf_client_names = {}
  101. local copilot_active = false
  102. -- add client
  103. for _, client in pairs(buf_clients) do
  104. if client.name ~= "null-ls" and client.name ~= "copilot" then
  105. table.insert(buf_client_names, client.name)
  106. end
  107. if client.name == "copilot" then
  108. copilot_active = true
  109. end
  110. end
  111. -- add formatter
  112. local formatters = require "lvim.lsp.null-ls.formatters"
  113. local supported_formatters = formatters.list_registered(buf_ft)
  114. vim.list_extend(buf_client_names, supported_formatters)
  115. -- add linter
  116. local linters = require "lvim.lsp.null-ls.linters"
  117. local supported_linters = linters.list_registered(buf_ft)
  118. vim.list_extend(buf_client_names, supported_linters)
  119. local unique_client_names = vim.fn.uniq(buf_client_names)
  120. local language_servers = "[" .. table.concat(unique_client_names, ", ") .. "]"
  121. if copilot_active then
  122. language_servers = language_servers .. "%#SLCopilot#" .. " " .. lvim.icons.git.Octoface .. "%*"
  123. end
  124. return language_servers
  125. end,
  126. color = { gui = "bold" },
  127. cond = conditions.hide_in_width,
  128. },
  129. location = { "location", color = location_color },
  130. progress = {
  131. "progress",
  132. fmt = function()
  133. return "%P/%L"
  134. end,
  135. color = {},
  136. },
  137. spaces = {
  138. function()
  139. local shiftwidth = vim.api.nvim_buf_get_option(0, "shiftwidth")
  140. return lvim.icons.ui.Tab .. " " .. shiftwidth
  141. end,
  142. padding = 1,
  143. },
  144. encoding = {
  145. "o:encoding",
  146. fmt = string.upper,
  147. color = {},
  148. cond = conditions.hide_in_width,
  149. },
  150. filetype = { "filetype", cond = nil, padding = { left = 1, right = 1 } },
  151. scrollbar = {
  152. function()
  153. local current_line = vim.fn.line "."
  154. local total_lines = vim.fn.line "$"
  155. local chars = { "__", "▁▁", "▂▂", "▃▃", "▄▄", "▅▅", "▆▆", "▇▇", "██" }
  156. local line_ratio = current_line / total_lines
  157. local index = math.ceil(line_ratio * #chars)
  158. return chars[index]
  159. end,
  160. padding = { left = 0, right = 0 },
  161. color = "SLProgress",
  162. cond = nil,
  163. },
  164. }