2021-12-23 05:37:39 +00:00
|
|
|
-- https://github.com/lukas-reineke/dotfiles/blob/master/vim/lua/lsp/rename.lua
|
|
|
|
local M = {}
|
|
|
|
local util = require('navigator.util')
|
2022-06-06 10:20:20 +00:00
|
|
|
local gutil = require('guihua.util')
|
|
|
|
local lsphelper = require('navigator.lspwrapper')
|
|
|
|
local symbols_to_items = lsphelper.symbols_to_items
|
2022-07-03 10:09:28 +00:00
|
|
|
local vfn = vim.fn
|
2021-12-23 05:37:39 +00:00
|
|
|
|
|
|
|
M.add_workspace_folder = function()
|
|
|
|
util.log(vim.ui.input)
|
|
|
|
local input = require('guihua.floating').input
|
2022-07-03 10:09:28 +00:00
|
|
|
input({ prompt = 'Workspace To Add: ', default = vfn.expand('%:p:h') }, function(inputs)
|
2021-12-23 05:37:39 +00:00
|
|
|
vim.lsp.buf.add_workspace_folder(inputs)
|
|
|
|
end)
|
|
|
|
end
|
|
|
|
|
|
|
|
M.remove_workspace_folder = function()
|
|
|
|
local select = require('guihua.gui').select
|
|
|
|
local folders = vim.lsp.buf.list_workspace_folders()
|
|
|
|
|
|
|
|
if #folders > 1 then
|
2022-07-26 16:37:26 +00:00
|
|
|
return select(folders, { prompt = 'select workspace to delete' }, function(workspace)
|
2021-12-23 05:37:39 +00:00
|
|
|
vim.lsp.buf.remove_workspace_folder(workspace)
|
|
|
|
end)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
M.workspace_symbol = function()
|
2021-12-24 06:30:56 +00:00
|
|
|
local input = require('guihua.floating').input
|
2022-06-06 10:20:20 +00:00
|
|
|
input({ prompt = 'Search symbol: ', default = '' }, function(inputs)
|
2021-12-24 06:30:56 +00:00
|
|
|
util.log(inputs)
|
|
|
|
vim.lsp.buf.workspace_symbol(inputs)
|
|
|
|
end)
|
2021-12-23 05:37:39 +00:00
|
|
|
end
|
|
|
|
|
2022-06-06 10:20:20 +00:00
|
|
|
function M.workspace_symbol_live()
|
2022-06-11 05:03:28 +00:00
|
|
|
local height = _NgConfigValues.height or 0.4
|
2022-07-03 10:09:28 +00:00
|
|
|
height = math.floor(height * vfn.winheight('%'))
|
2022-06-11 05:03:28 +00:00
|
|
|
local width = _NgConfigValues.width or 0.7
|
|
|
|
width = math.floor(width * vfn.winwidth('%'))
|
2022-06-06 10:20:20 +00:00
|
|
|
local bufnr = vim.api.nvim_get_current_buf()
|
2022-06-11 05:03:28 +00:00
|
|
|
local ft = vim.o.ft
|
2022-06-06 10:20:20 +00:00
|
|
|
local data = { { text = 'input the symbol name to start fuzzy search' } }
|
|
|
|
for _ = 1, height do
|
|
|
|
table.insert(data, { text = '' })
|
|
|
|
end
|
|
|
|
local ListView = require('guihua.listview')
|
|
|
|
local opt = {
|
|
|
|
api = ' ',
|
2022-07-17 21:45:23 +00:00
|
|
|
bg = 'GuihuaListDark',
|
2022-06-06 10:20:20 +00:00
|
|
|
data = data,
|
|
|
|
items = data,
|
|
|
|
enter = true,
|
2022-06-11 05:03:28 +00:00
|
|
|
ft = ft,
|
2022-06-06 10:20:20 +00:00
|
|
|
loc = 'top_center',
|
|
|
|
transparency = 50,
|
|
|
|
prompt = true,
|
|
|
|
on_confirm = function(item)
|
|
|
|
vim.defer_fn(function()
|
|
|
|
if item and item.name then
|
|
|
|
require('navigator.symbols').workspace_symbols(item.name)
|
|
|
|
end
|
|
|
|
end, 10)
|
|
|
|
end,
|
|
|
|
on_input_filter = function(text)
|
|
|
|
local params = { query = text or '#' }
|
2022-06-06 16:19:53 +00:00
|
|
|
local results = vim.lsp.buf_request_sync(bufnr, 'workspace/symbol', params)
|
|
|
|
local result
|
|
|
|
for _, r in pairs(results) do
|
|
|
|
-- util.log(r)
|
|
|
|
if r.result then
|
|
|
|
result = r.result
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if not result then
|
|
|
|
result = {}
|
|
|
|
end
|
|
|
|
|
2022-06-06 10:20:20 +00:00
|
|
|
local items = symbols_to_items(result)
|
|
|
|
items = gutil.dedup(items, 'name', 'kind')
|
|
|
|
return items
|
|
|
|
end,
|
2022-06-11 05:03:28 +00:00
|
|
|
rect = { height = height, pos_x = 0, pos_y = 0, width = width },
|
2022-06-06 10:20:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
local win = ListView:new(opt)
|
|
|
|
win:on_draw({})
|
|
|
|
-- require('guihua.gui').new_list_view(opt)
|
|
|
|
end
|
|
|
|
|
2021-12-23 05:37:39 +00:00
|
|
|
M.list_workspace_folders = function()
|
|
|
|
local folders = vim.lsp.buf.list_workspace_folders()
|
|
|
|
if #folders > 0 then
|
|
|
|
return require('navigator.gui').new_list_view({
|
|
|
|
items = folders,
|
|
|
|
border = 'single',
|
|
|
|
rawdata = true,
|
2022-06-06 10:20:20 +00:00
|
|
|
on_move = function() end,
|
2021-12-23 05:37:39 +00:00
|
|
|
})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return M
|