feat: add lsp_lines
This commit is contained in:
parent
fd1e2abf2b
commit
202e8a3c8d
5 changed files with 81 additions and 22 deletions
|
@ -77,6 +77,14 @@ local config = {
|
||||||
diagnostic = {},
|
diagnostic = {},
|
||||||
-- See :h gitsigns-usage
|
-- See :h gitsigns-usage
|
||||||
gitsigns = {},
|
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 <leader>ld to toggle
|
||||||
|
enable_on_start = true,
|
||||||
|
},
|
||||||
-- See https://github.com/ray-x/lsp_signature.nvim#full-configuration-with-default-values
|
-- See https://github.com/ray-x/lsp_signature.nvim#full-configuration-with-default-values
|
||||||
lsp_signature = {},
|
lsp_signature = {},
|
||||||
-- See https://github.com/nvim-lualine/lualine.nvim#default-configuration
|
-- See https://github.com/nvim-lualine/lualine.nvim#default-configuration
|
||||||
|
|
|
@ -5,6 +5,15 @@ local default_config = {
|
||||||
border = 'rounded',
|
border = 'rounded',
|
||||||
disable_builtin_plugins = {},
|
disable_builtin_plugins = {},
|
||||||
add_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 <leader>ld to toggle
|
||||||
|
enable_on_start = true,
|
||||||
|
},
|
||||||
|
},
|
||||||
lsp = {
|
lsp = {
|
||||||
format_on_save = true, -- true/false or table of filetypes {'.ts', '.js',}
|
format_on_save = true, -- true/false or table of filetypes {'.ts', '.js',}
|
||||||
format_timeout = 3000,
|
format_timeout = 3000,
|
||||||
|
|
|
@ -1,21 +1,8 @@
|
||||||
local u = require('cosmic.utils')
|
local u = require('cosmic.utils')
|
||||||
local icons = require('cosmic.utils.icons')
|
local icons = require('cosmic.utils.icons')
|
||||||
local config = require('cosmic.core.user')
|
local user_config = require('cosmic.core.user')
|
||||||
|
|
||||||
-- set up LSP signs
|
local function format_diagnostic(diagnostic)
|
||||||
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 icon = icons.error
|
local icon = icons.error
|
||||||
if diagnostic.severity == vim.diagnostic.severity.WARN then
|
if diagnostic.severity == vim.diagnostic.severity.WARN then
|
||||||
icon = icons.warn
|
icon = icons.warn
|
||||||
|
@ -29,20 +16,18 @@ local function format(diagnostic)
|
||||||
return message
|
return message
|
||||||
end
|
end
|
||||||
|
|
||||||
-- set up vim.diagnostics
|
local config = u.merge({
|
||||||
-- vim.diagnostic.config opts
|
|
||||||
vim.diagnostic.config(u.merge({
|
|
||||||
underline = true,
|
underline = true,
|
||||||
signs = true,
|
signs = true,
|
||||||
update_in_insert = false,
|
update_in_insert = false,
|
||||||
severity_sort = true,
|
severity_sort = true,
|
||||||
float = {
|
float = {
|
||||||
border = config.border,
|
border = user_config.border,
|
||||||
focusable = false,
|
focusable = false,
|
||||||
header = { icons.debug .. ' Diagnostics:', 'Normal' },
|
header = { icons.debug .. ' Diagnostics:', 'Normal' },
|
||||||
scope = 'line',
|
scope = 'line',
|
||||||
source = false,
|
source = false,
|
||||||
format = format,
|
format = format_diagnostic,
|
||||||
},
|
},
|
||||||
virtual_text = {
|
virtual_text = {
|
||||||
prefix = '•',
|
prefix = '•',
|
||||||
|
@ -51,6 +36,8 @@ vim.diagnostic.config(u.merge({
|
||||||
severity = {
|
severity = {
|
||||||
min = vim.diagnostic.severity.HINT,
|
min = vim.diagnostic.severity.HINT,
|
||||||
},
|
},
|
||||||
format = format,
|
format = format_diagnostic,
|
||||||
},
|
},
|
||||||
}, config.diagnostic or {}))
|
}, user_config.diagnostic or {})
|
||||||
|
|
||||||
|
return config
|
19
lua/cosmic/lsp/diagnostics/init.lua
Normal file
19
lua/cosmic/lsp/diagnostics/init.lua
Normal file
|
@ -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)
|
36
lua/cosmic/plugins/lsp-lines/init.lua
Normal file
36
lua/cosmic/plugins/lsp-lines/init.lua
Normal file
|
@ -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', '<leader>ld', '', {
|
||||||
|
callback = toggle,
|
||||||
|
})
|
||||||
|
end,
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue