Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: reimplement #34

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
root = true

[*]
end_of_line = lf
insert_final_newline = true
charset = utf-8
trim_trailing_whitespace = true

[*.lua]
indent_style = space
indent_size = 2
max_line_length = 120
1 change: 0 additions & 1 deletion ftdetect/idris2.vim

This file was deleted.

1 change: 0 additions & 1 deletion ftdetect/ipkg.vim

This file was deleted.

1 change: 0 additions & 1 deletion ftdetect/lidris2.vim

This file was deleted.

20 changes: 0 additions & 20 deletions ftplugin/idris2.vim

This file was deleted.

9 changes: 0 additions & 9 deletions ftplugin/ipkg.vim

This file was deleted.

144 changes: 0 additions & 144 deletions indent/idris2.vim

This file was deleted.

112 changes: 34 additions & 78 deletions lua/idris2/browse.lua
Original file line number Diff line number Diff line change
@@ -1,50 +1,9 @@
local get_identifier_at_cursor = require("idris2.utils.get_identifier_at_cursor")
local M = {}

local Input = require('nui.input')
local Menu = require('nui.menu')
local event = require('nui.utils.autocmd').event

local popup_options = {
relative = 'win',
position = {
row = '0%',
col = '100%',
},
border = {
style = 'rounded',
highlight = 'FloatBorder',
text = {
top = 'Browse Namespace',
top_align = 'center'
}
},
highlight = 'Normal:Normal',
}

local name_popup_options = {
relative = "cursor",
position = {
row = 1,
col = 0,
},
size = 30,
border = {
style = "rounded",
highlight = "FloatBorder",
text = {
top = "Namespace",
top_align = "left",
},
},
win_options = {
winhighlight = "Normal:Normal",
},
}

-- err, result, ctx
function M.menu_handler(ns, opts)
local opts = opts or { popup = true }
return function (err, result, ctx, config)
-- LSP Execute Command Request Options
function M.menu_handler(ns)
return function(err, result, _ctx, _config)
if err ~= nil then
vim.notify(err, vim.log.levels.ERROR)
return
Expand All @@ -56,52 +15,49 @@ function M.menu_handler(ns, opts)
end

local items = vim.tbl_map(function(x)
local text = x.name
return Menu.item(text, { entry = x })
local details = ''
if x.location ~= nil then
details = '(' ..
x.location.uri .. ':' .. x.location.range.start.line .. ',' .. x.location.range.start.character .. ')'
end
return {
value = x.name,
text = x.name .. details,
entry = x
}
end, result)
local menu = Menu(popup_options, {
lines = items,
max_width = 100,
max_height = 20,
separator = {
char = '-',
text_align = 'right',
},
keymap = {
focus_next = { 'j', '<Down>', '<Tab>' },
focus_prev = { 'k', '<Up>', '<S-Tab>' },
close = { '<Esc>', '<C-c>' },
submit = { '<CR>', '<Space>' },
},
on_submit = function(item)

vim.ui.select(items, {
prompt = 'Browse Namespace: ' .. ns,
format_item = function(item)
return item.text
end
}, function(item)
if item then
if item.entry.location ~= nil then
vim.lsp.util.jump_to_location(item.entry.location, 'utf-32')
else
vim.notify('Selected name is not in a physical location', vim.log.levels.ERROR)
end
end,
})

menu:mount()
if opts.popup then
menu:on(event.BufLeave, menu.menu_props.on_close, { once = true })
end
end
end)
end
end

function M.browse(opts)
local input = Input(name_popup_options, {
prompt = '> ',
default_value = '',
on_submit = function(value)
-- TODO: get list of all available imports
function M.browse()
vim.ui.input({
prompt = 'Browse Namespace: ',
default = get_identifier_at_cursor()
}, function(value)
if value then
local params = {
command = 'browseNamespace',
arguments = { value },
}
vim.lsp.buf_request(0, 'workspace/executeCommand', params, M.menu_handler(value, opts))
end,
})
input:mount()
vim.lsp.buf_request(0, 'workspace/executeCommand', params, M.menu_handler(value))
end
end)
end

return M
Loading