summaryrefslogtreecommitdiff
path: root/.config/nvim/lua/core/info.lua
diff options
context:
space:
mode:
authorGustaf Rydholm <gustaf.rydholm@gmail.com>2021-09-06 21:53:56 +0200
committerGustaf Rydholm <gustaf.rydholm@gmail.com>2021-09-06 21:53:56 +0200
commit6a1732982287ef5aff2a6de171192b9e2bb90758 (patch)
tree543f94f80d548b9ed7a9d0daecb08575a01a9a45 /.config/nvim/lua/core/info.lua
parentb89e893bfc7b8893dc4c13aa55f627096b32758a (diff)
Updates to nvim from lvim
Diffstat (limited to '.config/nvim/lua/core/info.lua')
-rw-r--r--.config/nvim/lua/core/info.lua325
1 files changed, 159 insertions, 166 deletions
diff --git a/.config/nvim/lua/core/info.lua b/.config/nvim/lua/core/info.lua
index 5b7ef53..83e3542 100644
--- a/.config/nvim/lua/core/info.lua
+++ b/.config/nvim/lua/core/info.lua
@@ -1,208 +1,201 @@
-local M = {}
-local u = require "utils"
-local null_ls_handler = require "lsp.null-ls"
-local indent = " "
-
-M.banner = {
- "",
- "",
- " ⠀⠀⠀ ⠀⠀ ⣺⡿⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀",
- " ⣿⣯ ⣿⡟⠀ ⣤⣤⠀⠀⠀⠀⣠⣤⣤⣤⣄⣤⣤",
- "⠀⣿⣿⠀⣰⡟⠀⠀⠀⠀⠀⢸⣿⠀⠀⠀⠀⣿⡟⢸⣿⡇⢀⣿",
- "⠀⢻⣿⢰⣿⠀⠀⠀⠀⠀⠀⣾⡇⠀⠀⠀⢸⣿⠇⢸⣿⠀⢸⡏",
- "⠀⢸⣿⣿⠋⠀⠀⠀⢠⣤⣤⣿⣥⣤⡄⠀⣼⣿⠀⣸⡏⠀⣿⠃",
- "⠀⠈⠉⠉⠀⠀⠀⠀⠈⠉⠉⠉⠉⠉⠁⠀⠉⠁⠀⠉⠁⠀⠉⠀",
- "",
- "",
+local M = {
+ banner = {
+ "",
+ [[ _ ___ ]],
+ [[| | / (_)___ ___ ]],
+ [[| | / / / __ `__ \]],
+ [[| |/ / / / / / / /]],
+ [[|___/_/_/ /_/ /_/ ]],
+ },
}
+local fmt = string.format
+
local function str_list(list)
- return "[ " .. table.concat(list, ", ") .. " ]"
+ return fmt("[ %s ]", table.concat(list, ", "))
end
local function get_formatter_suggestion_msg(ft)
- local supported_formatters = u.get_supported_formatters_by_filetype(ft)
- return {
- "-------------------------------------------------------------------",
- "",
- "  HINT ",
- "",
- indent .. "* List of supported formatters: " .. str_list(supported_formatters),
- "",
- indent .. "You can enable a supported formatter by adding this to your config.lua",
- "",
- indent
- .. "options.lang."
- .. tostring(ft)
- .. [[.formatting = { { exe = ']]
- .. table.concat(supported_formatters, "|")
- .. [[' } }]],
+ local config = require "config"
+ local null_formatters = require "lsp.null-ls.formatters"
+ local supported_formatters = null_formatters.list_available(ft)
+ local section = {
+ " HINT ",
"",
- "-------------------------------------------------------------------",
+ fmt("* List of supported formatters: %s", str_list(supported_formatters)),
}
+
+ if not vim.tbl_isempty(supported_formatters) then
+ vim.list_extend(section, {
+ "* Configured formatter needs to be installed and executable.",
+ fmt("* Enable installed formatter(s) with following config in %s", config.path),
+ "",
+ fmt(
+ " options.lang.%s.formatters = { { exe = '%s' } }",
+ ft,
+ table.concat(supported_formatters, "│")
+ ),
+ })
+ end
+
+ return section
end
local function get_linter_suggestion_msg(ft)
- local supported_linters = u.get_supported_linters_by_filetype(ft)
- return {
- "-------------------------------------------------------------------",
- "",
- "  HINT ",
+ local config = require "config"
+ local null_linters = require "lsp.null-ls.linters"
+ local supported_linters = null_linters.list_available(ft)
+ local section = {
+ " HINT ",
"",
- indent .. "* List of supported linters: " .. str_list(supported_linters),
- "",
- indent .. "You can enable a supported linter by adding this to your config.lua",
- "",
- indent
- .. "options.lang."
- .. tostring(ft)
- .. [[.linters = { { exe = ']]
- .. table.concat(supported_linters, "|")
- .. [[' } }]],
- "",
- "-------------------------------------------------------------------",
+ fmt("* List of supported linters: %s", str_list(supported_linters)),
}
-end
----creates an average size popup
----@param buf_lines a list of lines to print
----@param callback could be used to set syntax highlighting rules for example
----@return bufnr buffer number of the created buffer
----@return win_id window ID of the created popup
-function M.create_simple_popup(buf_lines, callback)
- -- runtime/lua/vim/lsp/util.lua
- local bufnr = vim.api.nvim_create_buf(false, true)
- local height_percentage = 0.7
- local width_percentage = 0.8
- local row_start_percentage = (1 - height_percentage) / 2
- local col_start_percentage = (1 - width_percentage) / 2
- local opts = {}
- opts.relative = "editor"
- opts.height = math.ceil(vim.o.lines * height_percentage)
- opts.row = math.ceil(vim.o.lines * row_start_percentage)
- opts.col = math.floor(vim.o.columns * col_start_percentage)
- opts.width = math.floor(vim.o.columns * width_percentage)
- opts.border = {
- "┌",
- "-",
- "┐",
- "|",
- "┘",
- "-",
- "└",
- "|",
- }
+ if not vim.tbl_isempty(supported_linters) then
+ vim.list_extend(section, {
+ "* Configured linter needs to be installed and executable.",
+ fmt("* Enable installed linter(s) with following config in %s", config.path),
+ "",
+ fmt(
+ " options.lang.%s.linters = { { exe = '%s' } }",
+ ft,
+ table.concat(supported_linters, "│")
+ ),
+ })
+ end
- local win_id = vim.api.nvim_open_win(bufnr, true, opts)
-
- vim.api.nvim_win_set_buf(win_id, bufnr)
- -- this needs to be window option!
- vim.api.nvim_win_set_option(win_id, "number", false)
- vim.cmd "setlocal nocursorcolumn"
- vim.cmd "setlocal wrap"
- -- set buffer options
- vim.api.nvim_buf_set_option(bufnr, "filetype", "lspinfo")
- vim.lsp.util.close_preview_autocmd({ "BufHidden", "BufLeave" }, win_id)
- buf_lines = vim.lsp.util._trim(buf_lines, {})
- vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, buf_lines)
- vim.api.nvim_buf_set_option(bufnr, "modifiable", false)
- if type(callback) == "function" then
- callback()
+ return section
+end
+
+local function tbl_set_highlight(terms, highlight_group)
+ for _, v in pairs(terms) do
+ vim.cmd('let m=matchadd("' .. highlight_group .. '", "' .. v .. "[ ,│']\")")
end
- return bufnr, win_id
end
function M.toggle_popup(ft)
- local client = u.get_active_client_by_ft(ft)
- local is_client_active = not client.is_stopped()
- local client_enabled_caps = require("lsp").get_ls_capabilities(client.id)
- local num_caps = vim.tbl_count(client_enabled_caps)
- local null_ls_providers = null_ls_handler.get_registered_providers_by_filetype(ft)
-
- local missing_linters = options.lang[ft].linters._failed_requests or {}
- local missing_formatters = options.lang[ft].formatters._failed_requests or {}
-
- local buf_lines = {}
- vim.list_extend(buf_lines, M.banner)
+ local lsp_utils = require "lsp.utils"
+ local client = lsp_utils.get_active_client_by_ft(ft)
+ local is_client_active = false
+ local client_enabled_caps = {}
+ local client_name = ""
+ local client_id = 0
+ local document_formatting = false
+ if client ~= nil then
+ is_client_active = not client.is_stopped()
+ client_enabled_caps = require("lsp").get_ls_capabilities(client.id)
+ client_name = client.name
+ client_id = client.id
+ document_formatting = client.resolved_capabilities.document_formatting
+ end
local header = {
- "Detected filetype is: " .. tostring(ft),
- "",
- "Treesitter active: " .. tostring(next(vim.treesitter.highlighter.active) ~= nil),
- "",
- "",
+ fmt("Detected filetype: %s", ft),
+ fmt(
+ "Treesitter active: %s",
+ tostring(next(vim.treesitter.highlighter.active) ~= nil)
+ ),
}
- vim.list_extend(buf_lines, header)
+ local text = require "interface.text"
local lsp_info = {
- "Associated language-server: " .. client.name,
- indent .. "* Active: " .. tostring(is_client_active) .. ", id: " .. tostring(
- client.id
- ),
- indent .. "* Formatting support: " .. tostring(
- client.resolved_capabilities.document_formatting
- ),
- indent .. "* Capabilities list: " .. table.concat(
- vim.list_slice(client_enabled_caps, 1, num_caps / 2),
- ", "
- ),
- indent .. indent .. indent .. table.concat(
- vim.list_slice(client_enabled_caps, ((num_caps / 2) + 1)),
- ", "
- ),
- "",
+ "Language Server Protocol (LSP) info",
+ fmt("* Associated server: %s", client_name),
+ fmt("* Active: %s (id: %d)", tostring(is_client_active), client_id),
+ fmt("* Supports formatting: %s", tostring(document_formatting)),
}
- vim.list_extend(buf_lines, lsp_info)
-
+ if not vim.tbl_isempty(client_enabled_caps) then
+ local caps_text = "* Capabilities list: "
+ local caps_text_len = caps_text:len()
+ local enabled_caps = text.format_table(client_enabled_caps, 3, " | ")
+ enabled_caps = text.shift_left(enabled_caps, caps_text_len)
+ enabled_caps[1] = fmt("%s%s", caps_text, enabled_caps[1]:sub(caps_text_len + 1))
+ vim.list_extend(lsp_info, enabled_caps)
+ end
+ local null_ls = require "lsp.null-ls"
+ local registered_providers = null_ls.list_supported_provider_names(ft)
+ local registered_count = vim.tbl_count(registered_providers)
local null_ls_info = {
- "Configured providers: " .. table.concat(null_ls_providers, "  , ") .. "  ",
- "",
+ "Formatters and linters",
+ fmt(
+ "* Configured providers: %s%s",
+ table.concat(registered_providers, "  , "),
+ registered_count > 0 and "  " or ""
+ ),
}
- vim.list_extend(buf_lines, null_ls_info)
- local missing_formatters_status
- if vim.tbl_count(missing_formatters) > 0 then
+ local null_formatters = require "lsp.null-ls.formatters"
+ local missing_formatters = null_formatters.list_unsupported_names(ft)
+ local missing_formatters_status = {}
+ if not vim.tbl_isempty(missing_formatters) then
missing_formatters_status = {
- "Missing formatters: " .. table.concat(missing_formatters, "  , ") .. "  ",
- "",
+ fmt(
+ "* Missing formatters: %s",
+ table.concat(missing_formatters, "  , ") .. "  "
+ ),
}
- vim.list_extend(buf_lines, missing_formatters_status)
end
- local missing_linters_status
- if vim.tbl_count(missing_linters) > 0 then
+ local null_linters = require "lsp.null-ls.linters"
+ local missing_linters = null_linters.list_unsupported_names(ft)
+ local missing_linters_status = {}
+ if not vim.tbl_isempty(missing_linters) then
missing_linters_status = {
- "Missing linters: " .. table.concat(missing_linters, "  , ") .. "  ",
- "",
+ fmt(
+ "* Missing linters: %s",
+ table.concat(missing_linters, "  , ") .. "  "
+ ),
}
- vim.list_extend(buf_lines, missing_linters_status)
end
- vim.list_extend(buf_lines, get_formatter_suggestion_msg(ft))
-
- vim.list_extend(buf_lines, get_linter_suggestion_msg(ft))
+ local content_provider = function(popup)
+ local content = {}
+
+ for _, section in ipairs {
+ M.banner,
+ { "" },
+ { "" },
+ header,
+ { "" },
+ lsp_info,
+ { "" },
+ null_ls_info,
+ missing_formatters_status,
+ missing_linters_status,
+ { "" },
+ { "" },
+ get_formatter_suggestion_msg(ft),
+ { "" },
+ { "" },
+ get_linter_suggestion_msg(ft),
+ } do
+ vim.list_extend(content, section)
+ end
+
+ return text.align(popup, content, 0.5)
+ end
local function set_syntax_hl()
- --TODO: highlighting is either inconsistent or not working :\
- vim.cmd("syntax match Identifier /filetype is: .*\\zs\\<" .. ft .. "\\>/")
- vim.cmd("syntax match Identifier /server: .*\\zs\\<" .. client.name .. "\\>/")
- vim.cmd(
- "syntax match Identifier /providers: .*\\zs\\<"
- .. table.concat(null_ls_providers, ", ")
- .. "\\>/"
- )
- vim.cmd(
- "syntax match Identifier /formatters: .*\\zs\\<"
- .. table.concat(missing_formatters, ", ")
- .. "\\>/"
- )
- vim.cmd(
- "syntax match Identifier /linters: .*\\zs\\<"
- .. table.concat(missing_linters, ", ")
- .. "\\>/"
- )
+ vim.cmd [[highlight NvimInfoIdentifier gui=bold]]
+ vim.cmd [[highlight link NvimInfoHeader Type]]
+ vim.cmd [[let m=matchadd("NvimInfoHeader", "Language Server Protocol (LSP) info")]]
+ vim.cmd [[let m=matchadd("NvimInfoHeader", "Formatters and linters")]]
+ vim.cmd('let m=matchadd("NvimInfoIdentifier", " ' .. ft .. '$")')
+ vim.cmd 'let m=matchadd("string", "true")'
+ vim.cmd 'let m=matchadd("error", "false")'
+ tbl_set_highlight(registered_providers, "NvimInfoIdentifier")
+ tbl_set_highlight(missing_formatters, "NvimInfoIdentifier")
+ tbl_set_highlight(missing_linters, "NvimInfoIdentifier")
+ vim.cmd('let m=matchadd("NvimInfoIdentifier", "' .. client_name .. '")')
end
- return M.create_simple_popup(buf_lines, set_syntax_hl)
+ local Popup = require("interface.popup"):new {
+ win_opts = { number = false },
+ buf_opts = { modifiable = false, filetype = "lspinfo" },
+ }
+ Popup:display(content_provider)
+ set_syntax_hl()
+
+ return Popup
end
return M