info.lua 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. local M = {}
  2. local u = require "utils"
  3. local null_ls_handler = require "lsp.null-ls"
  4. local indent = " "
  5. M.banner = {
  6. "",
  7. "",
  8. "⠀⣿⡟⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⠀ ⠀⠀⠀ ⠀⠀ ⣺⡿⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀",
  9. "⠀⣿⠇⠀⠀⠀⠀⠀⣤⡄⠀⠀⢠⣤⡄⠀.⣠⣤⣤⣤⡀⠀⠀⢀⣤⣤⣤⣤⡄⠀⠀⠀⣤⣄⣤⣤⣤⠀⠀ ⣿⣯ ⣿⡟⠀ ⣤⣤⠀⠀⠀⠀⣠⣤⣤⣤⣄⣤⣤",
  10. "⢠⣿⠀⠀⠀⠀⠀⠀⣿⠃⠀⠀⣸⣿⠁⠀⣿⣿⠉⠀⠈⣿⡇⠀⠀⠛⠋⠀⠀⢹⣿⠀⠀⠀⣿⠏⠀⠸⠿⠃⠀⣿⣿⠀⣰⡟⠀⠀⠀⠀⠀⢸⣿⠀⠀⠀⠀⣿⡟⢸⣿⡇⢀⣿",
  11. "⣸⡇⠀⠀⠀⠀⠀⢸⣿⠀⠀⠀⣿⡟⠀⢠⣿⡇⠀⠀⢰⣿⡇⠀⣰⣾⠟⠛⠛⣻⡇⠀⠀⢸⡿⠀⠀⠀⠀⠀⠀⢻⣿⢰⣿⠀⠀⠀⠀⠀⠀⣾⡇⠀⠀⠀⢸⣿⠇⢸⣿⠀⢸⡏",
  12. "⣿⣧⣤⣤⣤⡄⠀⠘⣿⣤⣤⡤⣿⠇⠀⢸⣿⠁⠀⠀⣼⣿⠀⠀⢿⣿⣤⣤⠔⣿⠃⠀⠀⣾⡇⠀⠀⠀⠀⠀⠀⢸⣿⣿⠋⠀⠀⠀⢠⣤⣤⣿⣥⣤⡄⠀⣼⣿⠀⣸⡏⠀⣿⠃",
  13. "⠉⠉⠉⠉⠉⠁⠀⠀⠈⠉⠉⠀⠉⠀⠀⠈⠉⠀⠀⠀⠉⠉⠀⠀⠀⠉⠉⠁⠈⠉⠀⠀⠀⠉⠀⠀⠀⠀⠀⠀⠀⠈⠉⠉⠀⠀⠀⠀⠈⠉⠉⠉⠉⠉⠁⠀⠉⠁⠀⠉⠁⠀⠉⠀",
  14. "",
  15. "",
  16. }
  17. local function str_list(list)
  18. return "[ " .. table.concat(list, ", ") .. " ]"
  19. end
  20. local function get_formatter_suggestion_msg(ft)
  21. local supported_formatters = u.get_supported_formatters_by_filetype(ft)
  22. return {
  23. "-------------------------------------------------------------------",
  24. "",
  25. "  HINT ",
  26. "",
  27. indent .. "* List of supported formatters: " .. str_list(supported_formatters),
  28. "",
  29. indent .. "You can enable a supported formatter by adding this to your config.lua",
  30. "",
  31. indent
  32. .. "lvim.lang."
  33. .. tostring(ft)
  34. .. [[.formatting = { { exe = ']]
  35. .. table.concat(supported_formatters, "|")
  36. .. [[' } }]],
  37. "",
  38. "-------------------------------------------------------------------",
  39. }
  40. end
  41. local function get_linter_suggestion_msg(ft)
  42. local supported_linters = u.get_supported_linters_by_filetype(ft)
  43. return {
  44. "-------------------------------------------------------------------",
  45. "",
  46. "  HINT ",
  47. "",
  48. indent .. "* List of supported linters: " .. str_list(supported_linters),
  49. "",
  50. indent .. "You can enable a supported linter by adding this to your config.lua",
  51. "",
  52. indent
  53. .. "lvim.lang."
  54. .. tostring(ft)
  55. .. [[.linters = { { exe = ']]
  56. .. table.concat(supported_linters, "|")
  57. .. [[' } }]],
  58. "",
  59. "-------------------------------------------------------------------",
  60. }
  61. end
  62. ---creates an average size popup
  63. ---@param buf_lines a list of lines to print
  64. ---@param callback could be used to set syntax highlighting rules for example
  65. ---@return bufnr buffer number of the created buffer
  66. ---@return win_id window ID of the created popup
  67. function M.create_simple_popup(buf_lines, callback)
  68. -- runtime/lua/vim/lsp/util.lua
  69. local bufnr = vim.api.nvim_create_buf(false, true)
  70. local height_percentage = 0.7
  71. local width_percentage = 0.8
  72. local row_start_percentage = (1 - height_percentage) / 2
  73. local col_start_percentage = (1 - width_percentage) / 2
  74. local opts = {}
  75. opts.relative = "editor"
  76. opts.height = math.ceil(vim.o.lines * height_percentage)
  77. opts.row = math.ceil(vim.o.lines * row_start_percentage)
  78. opts.col = math.floor(vim.o.columns * col_start_percentage)
  79. opts.width = math.floor(vim.o.columns * width_percentage)
  80. opts.border = {
  81. "┌",
  82. "-",
  83. "┐",
  84. "|",
  85. "┘",
  86. "-",
  87. "└",
  88. "|",
  89. }
  90. local win_id = vim.api.nvim_open_win(bufnr, true, opts)
  91. vim.api.nvim_win_set_buf(win_id, bufnr)
  92. -- this needs to be window option!
  93. vim.api.nvim_win_set_option(win_id, "number", false)
  94. vim.cmd "setlocal nocursorcolumn"
  95. vim.cmd "setlocal wrap"
  96. -- set buffer options
  97. vim.api.nvim_buf_set_option(bufnr, "filetype", "lspinfo")
  98. vim.lsp.util.close_preview_autocmd({ "BufHidden", "BufLeave" }, win_id)
  99. buf_lines = vim.lsp.util._trim(buf_lines, {})
  100. vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, buf_lines)
  101. vim.api.nvim_buf_set_option(bufnr, "modifiable", false)
  102. if type(callback) == "function" then
  103. callback()
  104. end
  105. return bufnr, win_id
  106. end
  107. function M.toggle_popup(ft)
  108. local client = u.get_active_client_by_ft(ft)
  109. local is_client_active = not client.is_stopped()
  110. local client_enabled_caps = require("lsp").get_ls_capabilities(client.id)
  111. local num_caps = vim.tbl_count(client_enabled_caps)
  112. local null_ls_providers = null_ls_handler.get_registered_providers_by_filetype(ft)
  113. local missing_linters = lvim.lang[ft].linters._failed_requests or {}
  114. local missing_formatters = lvim.lang[ft].formatters._failed_requests or {}
  115. local buf_lines = {}
  116. vim.list_extend(buf_lines, M.banner)
  117. local header = {
  118. "Detected filetype is: " .. tostring(ft),
  119. "",
  120. "Treesitter active: " .. tostring(next(vim.treesitter.highlighter.active) ~= nil),
  121. "",
  122. "",
  123. }
  124. vim.list_extend(buf_lines, header)
  125. local lsp_info = {
  126. "Associated language-server: " .. client.name,
  127. indent .. "* Active: " .. tostring(is_client_active) .. ", id: " .. tostring(client.id),
  128. indent .. "* Formatting support: " .. tostring(client.resolved_capabilities.document_formatting),
  129. indent .. "* Capabilities list: " .. table.concat(vim.list_slice(client_enabled_caps, 1, num_caps / 2), ", "),
  130. indent .. indent .. indent .. table.concat(vim.list_slice(client_enabled_caps, ((num_caps / 2) + 1)), ", "),
  131. "",
  132. }
  133. vim.list_extend(buf_lines, lsp_info)
  134. local null_ls_info = {
  135. "Configured providers: " .. table.concat(null_ls_providers, "  , ") .. "  ",
  136. "",
  137. }
  138. vim.list_extend(buf_lines, null_ls_info)
  139. local missing_formatters_status
  140. if vim.tbl_count(missing_formatters) > 0 then
  141. missing_formatters_status = { "Missing formatters: " .. table.concat(missing_formatters, "  , ") .. "  ", "" }
  142. vim.list_extend(buf_lines, missing_formatters_status)
  143. end
  144. local missing_linters_status
  145. if vim.tbl_count(missing_linters) > 0 then
  146. missing_linters_status = { "Missing linters: " .. table.concat(missing_linters, "  , ") .. "  ", "" }
  147. vim.list_extend(buf_lines, missing_linters_status)
  148. end
  149. vim.list_extend(buf_lines, get_formatter_suggestion_msg(ft))
  150. vim.list_extend(buf_lines, get_linter_suggestion_msg(ft))
  151. local function set_syntax_hl()
  152. --TODO: highlighting is either inconsistent or not working :\
  153. vim.cmd("syntax match Identifier /filetype is: .*\\zs\\<" .. ft .. "\\>/")
  154. vim.cmd("syntax match Identifier /server: .*\\zs\\<" .. client.name .. "\\>/")
  155. vim.cmd("syntax match Identifier /providers: .*\\zs\\<" .. table.concat(null_ls_providers, ", ") .. "\\>/")
  156. vim.cmd("syntax match Identifier /formatters: .*\\zs\\<" .. table.concat(missing_formatters, ", ") .. "\\>/")
  157. vim.cmd("syntax match Identifier /linters: .*\\zs\\<" .. table.concat(missing_linters, ", ") .. "\\>/")
  158. end
  159. return M.create_simple_popup(buf_lines, set_syntax_hl)
  160. end
  161. return M