mirror of
https://github.com/zoriya/dotfiles.git
synced 2026-06-06 20:12:16 +00:00
wip: async select
This commit is contained in:
@@ -1,22 +1,31 @@
|
|||||||
local Job = require 'plenary.job'
|
local Job = require 'plenary.job'
|
||||||
|
local a = require("plenary.async_lib")
|
||||||
|
local async, await = a.async, a.await
|
||||||
|
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
M.pattern = "*.sln"
|
M.pattern = "*.sln"
|
||||||
|
|
||||||
M.list = function()
|
M.list = async(function()
|
||||||
local projs = io.popen("dotnet sln list | tail -n +3")
|
local ignore = 3
|
||||||
local ret = {}
|
local ret = {}
|
||||||
for line in projs:lines() do
|
|
||||||
table.insert(ret, {
|
Job:new({
|
||||||
name = line:match("([^/]+).csproj$"),
|
args = { "sln", "list" },
|
||||||
csproj = line,
|
on_stdout = function(_, proj)
|
||||||
icon = "",
|
if ignore > 0 then
|
||||||
})
|
ignore = ignore - 1
|
||||||
end
|
return
|
||||||
projs:close()
|
end
|
||||||
|
table.insert(ret, {
|
||||||
|
name = proj:match("([^/]+).csproj$"),
|
||||||
|
csproj = proj,
|
||||||
|
icon = "",
|
||||||
|
})
|
||||||
|
end,
|
||||||
|
}):sync()
|
||||||
return ret
|
return ret
|
||||||
end
|
end)
|
||||||
|
|
||||||
M.build = function(proj)
|
M.build = function(proj)
|
||||||
local function add_to_qf(err, data)
|
local function add_to_qf(err, data)
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
local has_icon, nwicon = pcall(require, 'nvim-web-devicons')
|
local has_icon, nwicon = pcall(require, 'nvim-web-devicons')
|
||||||
|
local a = require("plenary.async_lib")
|
||||||
|
local async, await = a.async, a.await
|
||||||
|
|
||||||
local M = {
|
local M = {
|
||||||
adapters = {},
|
adapters = {},
|
||||||
@@ -10,12 +12,12 @@ local M = {
|
|||||||
|
|
||||||
table.insert(M.adapters, require "build.adapters.dotnet")
|
table.insert(M.adapters, require "build.adapters.dotnet")
|
||||||
|
|
||||||
M.list_projs = function ()
|
M.list_projs = async(function ()
|
||||||
local projs = {}
|
local projs = {}
|
||||||
|
|
||||||
for _, adapter in pairs(M.adapters) do
|
for _, adapter in pairs(M.adapters) do
|
||||||
for _, match in pairs(vim.fn.glob(adapter.pattern, false, true)) do
|
for _, match in pairs(vim.fn.glob(adapter.pattern, false, true)) do
|
||||||
for _, proj in pairs(adapter.list(match)) do
|
for _, proj in pairs(await(adapter.list(match))) do
|
||||||
proj.adapter = adapter
|
proj.adapter = adapter
|
||||||
proj.source = match
|
proj.source = match
|
||||||
proj.icon = proj.icon or has_icon and nwicon.get_icon(
|
proj.icon = proj.icon or has_icon and nwicon.get_icon(
|
||||||
@@ -28,10 +30,10 @@ M.list_projs = function ()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
return projs
|
return projs
|
||||||
end
|
end)
|
||||||
|
|
||||||
M.select_proj = function (on_select)
|
M.select_proj = async(function (on_select)
|
||||||
local projs = M.list_projs()
|
local projs = await(M.list_projs())
|
||||||
vim.ui.select(projs, {
|
vim.ui.select(projs, {
|
||||||
prompt = "Select a project",
|
prompt = "Select a project",
|
||||||
format_item = function (proj)
|
format_item = function (proj)
|
||||||
@@ -44,7 +46,7 @@ M.select_proj = function (on_select)
|
|||||||
on_select()
|
on_select()
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
end
|
end)
|
||||||
|
|
||||||
M.get_project = function ()
|
M.get_project = function ()
|
||||||
return M.projects[vim.fn.getcwd()]
|
return M.projects[vim.fn.getcwd()]
|
||||||
|
|||||||
Reference in New Issue
Block a user