feat(core): Check out renaming now :)
* Added nvim-notify to alert user of rename changes * Use notify as vim.notify if installed
This commit is contained in:
parent
3b6e4213b9
commit
cfc22daed3
6 changed files with 88 additions and 6 deletions
|
@ -7,6 +7,7 @@ local colors = {
|
||||||
blue = themeColors.blue,
|
blue = themeColors.blue,
|
||||||
purple = themeColors.magenta,
|
purple = themeColors.magenta,
|
||||||
orange = themeColors.orange,
|
orange = themeColors.orange,
|
||||||
|
trace = themeColors.orange,
|
||||||
hint = themeColors.teal,
|
hint = themeColors.teal,
|
||||||
red = themeColors.red,
|
red = themeColors.red,
|
||||||
diffAdd = themeColors.git.add,
|
diffAdd = themeColors.git.add,
|
||||||
|
|
|
@ -37,6 +37,20 @@ highlight('TelescopeSelectionCaret', 'None', colors.selection_caret)
|
||||||
-- autocomplete highlights
|
-- autocomplete highlights
|
||||||
highlight('CmpItemAbbrDeprecated', 'None', colors.warn)
|
highlight('CmpItemAbbrDeprecated', 'None', colors.warn)
|
||||||
|
|
||||||
|
-- notification highlights
|
||||||
|
highlight('NotifyINFOBorder', nil, colors.hint)
|
||||||
|
highlight('NotifyINFOTitle', nil, colors.hint)
|
||||||
|
highlight('NotifyINFOIcon', nil, colors.hint)
|
||||||
|
highlight('NotifyWARNBorder', nil, colors.warn)
|
||||||
|
highlight('NotifyWARNTitle', nil, colors.warn)
|
||||||
|
highlight('NotifyWARNIcon', nil, colors.warn)
|
||||||
|
highlight('NotifyERRORBorder', nil, colors.error)
|
||||||
|
highlight('NotifyERRORTitle', nil, colors.error)
|
||||||
|
highlight('NotifyERRORIcon', nil, colors.error)
|
||||||
|
highlight('NotifyTRACEBorder', nil, colors.trace)
|
||||||
|
highlight('NotifyTRACETitle', nil, colors.trace)
|
||||||
|
highlight('NotifyTRACEIcon', nil, colors.trace)
|
||||||
|
|
||||||
vim.cmd([[
|
vim.cmd([[
|
||||||
highlight clear NormalFloat
|
highlight clear NormalFloat
|
||||||
highlight link NormalFloat Normal
|
highlight link NormalFloat Normal
|
||||||
|
|
|
@ -16,6 +16,8 @@ local icons = {
|
||||||
information = '',
|
information = '',
|
||||||
symlink = '',
|
symlink = '',
|
||||||
line_number = '',
|
line_number = '',
|
||||||
|
debug = '',
|
||||||
|
trace = '✎',
|
||||||
git = {
|
git = {
|
||||||
unstaged = '✗',
|
unstaged = '✗',
|
||||||
staged = '✓',
|
staged = '✓',
|
||||||
|
|
|
@ -1,14 +1,15 @@
|
||||||
local colors = require('cosmic.core.theme.colors')
|
|
||||||
local icons = require('cosmic.core.theme.icons')
|
|
||||||
local highlight = require('cosmic.utils').highlight
|
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
local api = vim.api
|
local api = vim.api
|
||||||
local lsp = vim.lsp
|
local lsp = vim.lsp
|
||||||
local buf, win
|
local buf, win
|
||||||
local prompt_str = ' ' .. icons.folder.arrow_closed .. ' '
|
|
||||||
|
|
||||||
function M.rename()
|
function M.rename()
|
||||||
|
local colors = require('cosmic.core.theme.colors')
|
||||||
|
local icons = require('cosmic.core.theme.icons')
|
||||||
|
local utils = require('cosmic.utils')
|
||||||
|
local highlight = utils.highlight
|
||||||
|
local prompt_str = ' ' .. icons.folder.arrow_closed .. ' '
|
||||||
local map_opts = { noremap = true, silent = true }
|
local map_opts = { noremap = true, silent = true }
|
||||||
local opts = {
|
local opts = {
|
||||||
style = 'minimal',
|
style = 'minimal',
|
||||||
|
@ -27,7 +28,7 @@ function M.rename()
|
||||||
api.nvim_win_set_option(win, 'sidescrolloff', 0)
|
api.nvim_win_set_option(win, 'sidescrolloff', 0)
|
||||||
api.nvim_buf_set_option(buf, 'modifiable', true)
|
api.nvim_buf_set_option(buf, 'modifiable', true)
|
||||||
api.nvim_buf_set_option(buf, 'buftype', 'prompt')
|
api.nvim_buf_set_option(buf, 'buftype', 'prompt')
|
||||||
api.nvim_buf_add_highlight(buf, -1, "LspRenamePrompt", 0, 0, #prompt_str)
|
api.nvim_buf_add_highlight(buf, -1, 'LspRenamePrompt', 0, 0, #prompt_str)
|
||||||
highlight('LspRenamePrompt', 'None', colors.selection_caret)
|
highlight('LspRenamePrompt', 'None', colors.selection_caret)
|
||||||
|
|
||||||
vim.fn.prompt_setprompt(buf, prompt_str)
|
vim.fn.prompt_setprompt(buf, prompt_str)
|
||||||
|
@ -42,6 +43,31 @@ function M.rename()
|
||||||
map_opts
|
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 err then
|
||||||
|
vim.notify(("Error running LSP query '%s': %s"):format(method, err), vim.log.levels.ERROR)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
-- echo the resulting changes
|
||||||
|
if result and result.changes then
|
||||||
|
for f, c in pairs(result.changes) do
|
||||||
|
vim.notify(('%d changes -> %s'):format(#c, utils.get_relative_path(f)), vim.log.levels.INFO)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
vim.lsp.handlers[method](...)
|
||||||
|
end
|
||||||
|
|
||||||
function M._rename()
|
function M._rename()
|
||||||
local newName = vim.trim(vim.fn.getline('.'):sub(5, -1))
|
local newName = vim.trim(vim.fn.getline('.'):sub(5, -1))
|
||||||
vim.cmd([[q!]])
|
vim.cmd([[q!]])
|
||||||
|
@ -51,7 +77,7 @@ function M.rename()
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
params.newName = newName
|
params.newName = newName
|
||||||
lsp.buf_request(0, 'textDocument/rename', params)
|
lsp.buf_request(0, 'textDocument/rename', params, handler)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -37,6 +37,24 @@ return packer.startup(function()
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
use({
|
||||||
|
'rcarriga/nvim-notify',
|
||||||
|
config = function()
|
||||||
|
local icons = require('cosmic.core.theme.icons')
|
||||||
|
require('notify').setup({
|
||||||
|
icons = {
|
||||||
|
ERROR = icons.error,
|
||||||
|
WARN = icons.warn,
|
||||||
|
INFO = icons.info,
|
||||||
|
DEBUG = icons.debug,
|
||||||
|
TRACE = icons.trace,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
vim.notify = require('notify')
|
||||||
|
end,
|
||||||
|
disable = vim.tbl_contains(user_plugins.disable, 'notify'),
|
||||||
|
})
|
||||||
|
|
||||||
use({ -- color scheme
|
use({ -- color scheme
|
||||||
'folke/tokyonight.nvim',
|
'folke/tokyonight.nvim',
|
||||||
config = function()
|
config = function()
|
||||||
|
|
|
@ -35,9 +35,30 @@ end
|
||||||
function M.highlight(group, bg, fg, gui)
|
function M.highlight(group, bg, fg, gui)
|
||||||
if gui ~= nil and gui ~= '' then
|
if gui ~= nil and gui ~= '' then
|
||||||
vim.api.nvim_command(('hi %s guibg=%s guifg=%s gui=%s'):format(group, bg, fg, gui))
|
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
|
else
|
||||||
vim.api.nvim_command(('hi %s guibg=%s guifg=%s'):format(group, bg, fg))
|
vim.api.nvim_command(('hi %s guibg=%s guifg=%s'):format(group, bg, fg))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function M.get_relative_path(path)
|
||||||
|
local split_path = M.split(path, '/')
|
||||||
|
local split_cwd = M.split(vim.fn.getcwd(), '/')
|
||||||
|
local curr_dir = split_cwd[#split_cwd]
|
||||||
|
local nice_path = ''
|
||||||
|
|
||||||
|
local ok = false
|
||||||
|
for _, dir in ipairs(split_path) do
|
||||||
|
if dir == curr_dir then
|
||||||
|
ok = true
|
||||||
|
end
|
||||||
|
if ok then
|
||||||
|
nice_path = nice_path .. '/' .. dir
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return '.' .. nice_path
|
||||||
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|
Loading…
Add table
Reference in a new issue