feat(plugins): Cosmic-ui (#31)
This commit is contained in:
parent
a3332a801f
commit
3c1a01664d
11 changed files with 28 additions and 211 deletions
|
@ -80,24 +80,20 @@ return packer.startup(function()
|
||||||
require('cosmic.lsp')
|
require('cosmic.lsp')
|
||||||
end,
|
end,
|
||||||
requires = {
|
requires = {
|
||||||
{
|
|
||||||
'ray-x/lsp_signature.nvim',
|
|
||||||
config = function()
|
|
||||||
-- must happen after servers are set up
|
|
||||||
require('lsp_signature').setup({
|
|
||||||
bind = true, -- This is mandatory, otherwise border config won't get registered.
|
|
||||||
handler_opts = {
|
|
||||||
border = 'rounded',
|
|
||||||
},
|
|
||||||
})
|
|
||||||
end,
|
|
||||||
after = 'nvim-lspconfig',
|
|
||||||
},
|
|
||||||
{ 'jose-elias-alvarez/nvim-lsp-ts-utils' },
|
{ 'jose-elias-alvarez/nvim-lsp-ts-utils' },
|
||||||
{ 'williamboman/nvim-lsp-installer' },
|
{ 'williamboman/nvim-lsp-installer' },
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
use({
|
||||||
|
'CosmicNvim/cosmic-ui',
|
||||||
|
requires = { 'MunifTanjim/nui.nvim', 'nvim-lua/plenary.nvim', 'ray-x/lsp_signature.nvim' },
|
||||||
|
config = function()
|
||||||
|
require('cosmic-ui').setup({})
|
||||||
|
end,
|
||||||
|
after = 'nvim-lspconfig',
|
||||||
|
})
|
||||||
|
|
||||||
use({
|
use({
|
||||||
'jose-elias-alvarez/null-ls.nvim',
|
'jose-elias-alvarez/null-ls.nvim',
|
||||||
config = function()
|
config = function()
|
||||||
|
|
|
@ -59,7 +59,7 @@ M.init = function()
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
documentation = {
|
documentation = {
|
||||||
border = 'single',
|
border = 'rounded',
|
||||||
winhighlight = 'FloatBorder:FloatBorder,Normal:Normal',
|
winhighlight = 'FloatBorder:FloatBorder,Normal:Normal',
|
||||||
},
|
},
|
||||||
experimental = {
|
experimental = {
|
||||||
|
|
|
@ -1,68 +0,0 @@
|
||||||
local config = require('cosmic.config')
|
|
||||||
local icons = require('cosmic.theme.icons')
|
|
||||||
|
|
||||||
local defaults = {
|
|
||||||
underline = true,
|
|
||||||
signs = true,
|
|
||||||
update_in_insert = false,
|
|
||||||
severity_sort = true,
|
|
||||||
float = {
|
|
||||||
header = false,
|
|
||||||
source = 'always',
|
|
||||||
border = 'single',
|
|
||||||
},
|
|
||||||
virtual_text = {
|
|
||||||
spacing = 4,
|
|
||||||
source = 'always',
|
|
||||||
severity = {
|
|
||||||
min = vim.diagnostic.severity.HINT,
|
|
||||||
},
|
|
||||||
-- todo: icons for diagnostics?
|
|
||||||
--[[ format = function(diagnostic)
|
|
||||||
if diagnostic.severity == vim.diagnostic.severity.ERROR then
|
|
||||||
return ('E: %s'):format(diagnostic.message)
|
|
||||||
end
|
|
||||||
return diagnostic.message
|
|
||||||
end, ]]
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
local opts = vim.tbl_deep_extend('force', defaults, config.lsp.diagnostic or {})
|
|
||||||
|
|
||||||
vim.diagnostic.config(opts)
|
|
||||||
|
|
||||||
local function do_diagnostic_signs()
|
|
||||||
local signs = {
|
|
||||||
Error = icons.error .. ' ',
|
|
||||||
Warn = icons.warn .. ' ',
|
|
||||||
Hint = icons.hint .. ' ',
|
|
||||||
Info = icons.info .. ' ',
|
|
||||||
}
|
|
||||||
|
|
||||||
local t = vim.fn.sign_getdefined('DiagnosticSignWarn')
|
|
||||||
if vim.tbl_isempty(t) then
|
|
||||||
for type, icon in pairs(signs) do
|
|
||||||
local hl = 'DiagnosticSign' .. type
|
|
||||||
vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = '' })
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local function do_legacy_diagnostic_signs()
|
|
||||||
local signs = {
|
|
||||||
Error = icons.error .. ' ',
|
|
||||||
Warning = icons.warn .. ' ',
|
|
||||||
Hint = icons.hint .. ' ',
|
|
||||||
Information = icons.info .. ' ',
|
|
||||||
}
|
|
||||||
local h = vim.fn.sign_getdefined('LspDiagnosticsSignWarn')
|
|
||||||
if vim.tbl_isempty(h) then
|
|
||||||
for type, icon in pairs(signs) do
|
|
||||||
local hl = 'LspDiagnosticsSign' .. type
|
|
||||||
vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = '' })
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
do_diagnostic_signs()
|
|
||||||
do_legacy_diagnostic_signs()
|
|
|
@ -1,7 +1,4 @@
|
||||||
require('cosmic.lsp.providers')
|
-- local config = require('cosmic.config')
|
||||||
require('cosmic.lsp.diagnostics')
|
|
||||||
|
|
||||||
vim.lsp.handlers['textDocument/signatureHelp'] = vim.lsp.with(vim.lsp.handlers.signature_help, { border = 'single' })
|
-- set up lsp servers
|
||||||
vim.lsp.handlers['textDocument/hover'] = vim.lsp.with(vim.lsp.handlers.hover, {
|
require('cosmic.lsp.providers')
|
||||||
border = 'single',
|
|
||||||
})
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ map('n', 'gD', '<cmd>lua vim.lsp.buf.declaration()<cr>')
|
||||||
map('n', 'gi', '<cmd>lua require("telescope.builtin").lsp_implementations()<cr>')
|
map('n', 'gi', '<cmd>lua require("telescope.builtin").lsp_implementations()<cr>')
|
||||||
map('n', 'gt', '<cmd>lua require("telescope.builtin").lsp_type_definitions()<cr>')
|
map('n', 'gt', '<cmd>lua require("telescope.builtin").lsp_type_definitions()<cr>')
|
||||||
map('n', 'gr', '<cmd>lua require("telescope.builtin").lsp_references()<cr>')
|
map('n', 'gr', '<cmd>lua require("telescope.builtin").lsp_references()<cr>')
|
||||||
map('n', 'gn', '<cmd>lua require("cosmic.theme.ui").rename()<cr>')
|
map('n', 'gn', '<cmd>lua require("cosmic-ui").rename()<cr>')
|
||||||
|
|
||||||
-- diagnostics
|
-- diagnostics
|
||||||
map('n', '[g', '<cmd>lua vim.diagnostic.goto_prev()<cr>')
|
map('n', '[g', '<cmd>lua vim.diagnostic.goto_prev()<cr>')
|
||||||
|
|
|
@ -5,7 +5,7 @@ local condition = require('galaxyline.condition')
|
||||||
local fileinfo = require('galaxyline.providers.fileinfo')
|
local fileinfo = require('galaxyline.providers.fileinfo')
|
||||||
local utils = require('cosmic.utils')
|
local utils = require('cosmic.utils')
|
||||||
local colors = require('cosmic.theme.colors')
|
local colors = require('cosmic.theme.colors')
|
||||||
local highlight = utils.highlight
|
local highlight = require('cosmic.theme.highlight')
|
||||||
local icons = require('cosmic.theme.icons')
|
local icons = require('cosmic.theme.icons')
|
||||||
local config = require('cosmic.config')
|
local config = require('cosmic.config')
|
||||||
|
|
||||||
|
|
|
@ -33,9 +33,9 @@ end
|
||||||
packer.init({
|
packer.init({
|
||||||
display = {
|
display = {
|
||||||
open_fn = function()
|
open_fn = function()
|
||||||
return require('packer.util').float({ border = 'single' })
|
return require('packer.util').float({ border = 'rounded' })
|
||||||
end,
|
end,
|
||||||
prompt_border = 'single',
|
prompt_border = 'rounded',
|
||||||
},
|
},
|
||||||
git = {
|
git = {
|
||||||
clone_timeout = 800, -- Timeout, in seconds, for git clones
|
clone_timeout = 800, -- Timeout, in seconds, for git clones
|
||||||
|
|
9
lua/cosmic/theme/highlight.lua
Normal file
9
lua/cosmic/theme/highlight.lua
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
return function(group, bg, fg, gui)
|
||||||
|
if gui ~= nil and gui ~= '' then
|
||||||
|
vim.api.nvim_command(('hi %s guibg=%s guifg=%s gui=%s'):format(group, bg, fg, gui))
|
||||||
|
elseif bg == nil then
|
||||||
|
vim.api.nvim_command(('hi %s guifg=%s'):format(group, fg))
|
||||||
|
else
|
||||||
|
vim.api.nvim_command(('hi %s guibg=%s guifg=%s'):format(group, bg, fg))
|
||||||
|
end
|
||||||
|
end
|
|
@ -2,7 +2,7 @@ local _, colors = pcall(require, 'cosmic.theme.colors')
|
||||||
if not colors then
|
if not colors then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local highlight = require('cosmic.utils').highlight
|
local highlight = require('cosmic.theme.highlight')
|
||||||
|
|
||||||
-- diagnostic virtual text highlights
|
-- diagnostic virtual text highlights
|
||||||
highlight('DiagnosticVirtualTextError', 'None', colors.error)
|
highlight('DiagnosticVirtualTextError', 'None', colors.error)
|
||||||
|
@ -32,7 +32,7 @@ highlight('LspDiagnosticsSignInformation', 'None', colors.info)
|
||||||
highlight('LspDiagnosticsSignHint', 'None', colors.hint)
|
highlight('LspDiagnosticsSignHint', 'None', colors.hint)
|
||||||
|
|
||||||
-- signature highlight color
|
-- signature highlight color
|
||||||
highlight('LspSignatureActiveParameter', 'None', colors.orange)
|
-- highlight('LspSignatureActiveParameter', 'None', colors.orange)
|
||||||
|
|
||||||
-- currently not working?
|
-- currently not working?
|
||||||
highlight('TelescopeSelectionCaret', 'None', colors.selection_caret)
|
highlight('TelescopeSelectionCaret', 'None', colors.selection_caret)
|
||||||
|
|
|
@ -1,99 +0,0 @@
|
||||||
local M = {}
|
|
||||||
|
|
||||||
local api = vim.api
|
|
||||||
local lsp = vim.lsp
|
|
||||||
local buf, win
|
|
||||||
|
|
||||||
function M.rename()
|
|
||||||
local icons = require('cosmic.theme.icons')
|
|
||||||
local utils = require('cosmic.utils')
|
|
||||||
local config = require('cosmic.config')
|
|
||||||
local Logger = require('cosmic.utils.logger')
|
|
||||||
local highlight = utils.highlight
|
|
||||||
local prompt_str = ' ' .. icons.folder.arrow_closed .. ' '
|
|
||||||
local map_opts = { noremap = true, silent = true }
|
|
||||||
local opts = {
|
|
||||||
style = 'minimal',
|
|
||||||
border = 'single',
|
|
||||||
relative = 'cursor',
|
|
||||||
width = 25,
|
|
||||||
height = 1,
|
|
||||||
row = 1,
|
|
||||||
col = 1,
|
|
||||||
}
|
|
||||||
buf, win = api.nvim_create_buf(false, true)
|
|
||||||
api.nvim_buf_set_option(buf, 'bufhidden', 'wipe')
|
|
||||||
|
|
||||||
api.nvim_open_win(buf, true, opts)
|
|
||||||
api.nvim_win_set_option(win, 'scrolloff', 0)
|
|
||||||
api.nvim_win_set_option(win, 'sidescrolloff', 0)
|
|
||||||
api.nvim_buf_set_option(buf, 'modifiable', true)
|
|
||||||
api.nvim_buf_set_option(buf, 'buftype', 'prompt')
|
|
||||||
|
|
||||||
local _, colors = pcall(require, 'cosmic.theme.colors')
|
|
||||||
if colors then
|
|
||||||
api.nvim_buf_add_highlight(buf, -1, 'LspRenamePrompt', 0, 0, #prompt_str)
|
|
||||||
highlight('LspRenamePrompt', 'None', colors.selection_caret)
|
|
||||||
end
|
|
||||||
|
|
||||||
vim.fn.prompt_setprompt(buf, prompt_str)
|
|
||||||
|
|
||||||
vim.api.nvim_command('startinsert!')
|
|
||||||
api.nvim_buf_set_keymap(buf, 'i', '<esc>', '<CMD>stopinsert <BAR> q!<CR>', map_opts)
|
|
||||||
api.nvim_buf_set_keymap(
|
|
||||||
buf,
|
|
||||||
'i',
|
|
||||||
'<CR>',
|
|
||||||
"<CMD>stopinsert <BAR> lua require('cosmic.theme.ui')._rename()<CR>",
|
|
||||||
map_opts
|
|
||||||
)
|
|
||||||
|
|
||||||
local function handler(...)
|
|
||||||
local result
|
|
||||||
local method
|
|
||||||
local err = select(1, ...)
|
|
||||||
local is_new = not select(4, ...) or type(select(4, ...)) ~= 'number'
|
|
||||||
if is_new then
|
|
||||||
method = select(3, ...).method
|
|
||||||
result = select(2, ...)
|
|
||||||
else
|
|
||||||
method = select(2, ...)
|
|
||||||
result = select(3, ...)
|
|
||||||
end
|
|
||||||
|
|
||||||
if config.lsp.rename_notification then
|
|
||||||
if err then
|
|
||||||
Logger:error(("Error running LSP query '%s': %s"):format(method, err))
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
-- echo the resulting changes
|
|
||||||
local new_word = ''
|
|
||||||
if result and result.changes then
|
|
||||||
local msg = {}
|
|
||||||
for f, c in pairs(result.changes) do
|
|
||||||
new_word = c[1].newText
|
|
||||||
table.insert(msg, ('%d changes -> %s'):format(#c, utils.get_relative_path(f)))
|
|
||||||
end
|
|
||||||
local currName = vim.fn.expand('<cword>')
|
|
||||||
Logger:log(msg, { title = ('Rename: %s -> %s'):format(currName, new_word) })
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
vim.lsp.handlers[method](...)
|
|
||||||
end
|
|
||||||
|
|
||||||
function M._rename()
|
|
||||||
local new_name = vim.trim(vim.fn.getline('.'):sub(5, -1))
|
|
||||||
vim.cmd([[q!]])
|
|
||||||
local params = lsp.util.make_position_params()
|
|
||||||
local curr_name = vim.fn.expand('<cword>')
|
|
||||||
if not (new_name and #new_name > 0) or new_name == curr_name then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
params.newName = new_name
|
|
||||||
lsp.buf_request(0, 'textDocument/rename', params, handler)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
return M
|
|
|
@ -19,24 +19,6 @@ function M.split(str, sep)
|
||||||
return res
|
return res
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.highlight(group, bg, fg, gui)
|
|
||||||
if gui ~= nil and gui ~= '' then
|
|
||||||
vim.api.nvim_command(('hi %s guibg=%s guifg=%s gui=%s'):format(group, bg, fg, gui))
|
|
||||||
elseif bg == nil then
|
|
||||||
vim.api.nvim_command(('hi %s guifg=%s'):format(group, fg))
|
|
||||||
else
|
|
||||||
vim.api.nvim_command(('hi %s guibg=%s guifg=%s'):format(group, bg, fg))
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function M.get_relative_path(file_path)
|
|
||||||
local plenary_path = require('plenary.path')
|
|
||||||
local parsed_path, _ = file_path:gsub('file://', '')
|
|
||||||
local path = plenary_path:new(parsed_path)
|
|
||||||
local relative_path = path:make_relative(vim.fn.getcwd())
|
|
||||||
return './' .. relative_path
|
|
||||||
end
|
|
||||||
|
|
||||||
function M.get_active_lsp_client_names()
|
function M.get_active_lsp_client_names()
|
||||||
local active_clients = vim.lsp.get_active_clients()
|
local active_clients = vim.lsp.get_active_clients()
|
||||||
local client_names = {}
|
local client_names = {}
|
||||||
|
|
Loading…
Add table
Reference in a new issue