diff --git a/lua/cosmic/config/examples/config.lua b/lua/cosmic/config/examples/config.lua index f6c2b5a..3c28e85 100644 --- a/lua/cosmic/config/examples/config.lua +++ b/lua/cosmic/config/examples/config.lua @@ -77,6 +77,14 @@ local config = { diagnostic = {}, -- See :h gitsigns-usage gitsigns = {}, + -- See https://git.sr.ht/~whynothugo/lsp_lines.nvim + lsp_lines = { + -- additional flag only for CosmicNvim + -- true - loads plugin and is enabled at start + -- false - loads plugin but is not enabled at start + -- you may use ld to toggle + enable_on_start = true, + }, -- See https://github.com/ray-x/lsp_signature.nvim#full-configuration-with-default-values lsp_signature = {}, -- See https://github.com/nvim-lualine/lualine.nvim#default-configuration diff --git a/lua/cosmic/core/user.lua b/lua/cosmic/core/user.lua index 0d296a3..016cc8a 100644 --- a/lua/cosmic/core/user.lua +++ b/lua/cosmic/core/user.lua @@ -5,6 +5,15 @@ local default_config = { border = 'rounded', disable_builtin_plugins = {}, add_plugins = {}, + plugins = { + lsp_lines = { + -- additional flag only for CosmicNvim + -- true - loads plugin and is enabled at start + -- false - loads plugin but is not enabled at start + -- you may use ld to toggle + enable_on_start = true, + }, + }, lsp = { format_on_save = true, -- true/false or table of filetypes {'.ts', '.js',} format_timeout = 3000, diff --git a/lua/cosmic/lsp/diagnostics.lua b/lua/cosmic/lsp/diagnostics/config.lua similarity index 58% rename from lua/cosmic/lsp/diagnostics.lua rename to lua/cosmic/lsp/diagnostics/config.lua index 602f285..7c5d6ea 100644 --- a/lua/cosmic/lsp/diagnostics.lua +++ b/lua/cosmic/lsp/diagnostics/config.lua @@ -1,21 +1,8 @@ local u = require('cosmic.utils') local icons = require('cosmic.utils.icons') -local config = require('cosmic.core.user') +local user_config = require('cosmic.core.user') --- set up LSP signs -local signs = { - Error = icons.error .. ' ', - Warn = icons.warn .. ' ', - Hint = icons.hint .. ' ', - Info = icons.info .. ' ', -} - -for type, icon in pairs(signs) do - local hl = 'DiagnosticSign' .. type - vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = '' }) -end - -local function format(diagnostic) +local function format_diagnostic(diagnostic) local icon = icons.error if diagnostic.severity == vim.diagnostic.severity.WARN then icon = icons.warn @@ -29,20 +16,18 @@ local function format(diagnostic) return message end --- set up vim.diagnostics --- vim.diagnostic.config opts -vim.diagnostic.config(u.merge({ +local config = u.merge({ underline = true, signs = true, update_in_insert = false, severity_sort = true, float = { - border = config.border, + border = user_config.border, focusable = false, header = { icons.debug .. ' Diagnostics:', 'Normal' }, scope = 'line', source = false, - format = format, + format = format_diagnostic, }, virtual_text = { prefix = '•', @@ -51,6 +36,8 @@ vim.diagnostic.config(u.merge({ severity = { min = vim.diagnostic.severity.HINT, }, - format = format, + format = format_diagnostic, }, -}, config.diagnostic or {})) +}, user_config.diagnostic or {}) + +return config diff --git a/lua/cosmic/lsp/diagnostics/init.lua b/lua/cosmic/lsp/diagnostics/init.lua new file mode 100644 index 0000000..ee71c88 --- /dev/null +++ b/lua/cosmic/lsp/diagnostics/init.lua @@ -0,0 +1,19 @@ +local icons = require('cosmic.utils.icons') +local config = require('cosmic.lsp.diagnostics.config') + +-- set up LSP signs +local signs = { + Error = icons.error .. ' ', + Warn = icons.warn .. ' ', + Hint = icons.hint .. ' ', + Info = icons.info .. ' ', +} + +-- Set up diagnostic signs +for type, icon in pairs(signs) do + local hl = 'DiagnosticSign' .. type + vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = '' }) +end + +-- set up diagnostics +vim.diagnostic.config(config) diff --git a/lua/cosmic/plugins/lsp-lines/init.lua b/lua/cosmic/plugins/lsp-lines/init.lua new file mode 100644 index 0000000..7da803c --- /dev/null +++ b/lua/cosmic/plugins/lsp-lines/init.lua @@ -0,0 +1,36 @@ +return { + event = 'VeryLazy', + url = 'https://git.sr.ht/~whynothugo/lsp_lines.nvim', + config = function() + local user_config = require('cosmic.core.user') + local u = require('cosmic.utils') + local map = require('cosmic.utils').map + local vt_config = require('cosmic.lsp.diagnostics.config') + local is_plugin_enabled = user_config.plugins.lsp_lines.enable_on_start + + -- init lsp_lines + require('lsp_lines').setup() + + local function toggle() + if is_plugin_enabled then + vim.diagnostic.config(u.merge(vt_config, { + virtual_text = false, + virtual_lines = true, + })) + else + vim.diagnostic.config(u.merge(vt_config, { + virtual_lines = false, + })) + end + is_plugin_enabled = not is_plugin_enabled + end + + -- run once to properly show/hide based on user config + toggle() + + -- map for toggling lines + map('n', 'ld', '', { + callback = toggle, + }) + end, +}