mirror of
https://github.com/zoriya/dotfiles.git
synced 2026-06-04 03:26:38 +00:00
Remove async target list
This commit is contained in:
@@ -1,12 +1,10 @@
|
|||||||
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 = async(function()
|
M.list = function()
|
||||||
local ignore = 3
|
local ignore = 3
|
||||||
local ret = {}
|
local ret = {}
|
||||||
|
|
||||||
@@ -25,7 +23,7 @@ M.list = async(function()
|
|||||||
end,
|
end,
|
||||||
}):sync()
|
}):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,6 +1,4 @@
|
|||||||
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 = {},
|
||||||
@@ -12,12 +10,14 @@ local M = {
|
|||||||
|
|
||||||
table.insert(M.adapters, require "build.adapters.dotnet")
|
table.insert(M.adapters, require "build.adapters.dotnet")
|
||||||
|
|
||||||
M.list_projs = async(function ()
|
M.list_projs = function()
|
||||||
local projs = {}
|
local projs = {}
|
||||||
|
|
||||||
|
-- TODO: Use async methods here. (currently waiting for plenary async jobs)
|
||||||
|
|
||||||
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(await(adapter.list(match))) do
|
for _, proj in pairs(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(
|
||||||
@@ -30,29 +30,29 @@ M.list_projs = async(function ()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
return projs
|
return projs
|
||||||
end)
|
end
|
||||||
|
|
||||||
M.select_proj = async(function (on_select)
|
M.select_proj = function(on_select)
|
||||||
local projs = await(M.list_projs())
|
local projs = 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)
|
||||||
return proj.icon .. " " .. proj.name
|
return proj.icon .. " " .. proj.name
|
||||||
end
|
end
|
||||||
}, function (proj)
|
}, function(proj)
|
||||||
if not proj then return end
|
if not proj then return end
|
||||||
M.projects[vim.fn.getcwd()] = proj
|
M.projects[vim.fn.getcwd()] = proj
|
||||||
if on_select then
|
if on_select then
|
||||||
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()]
|
||||||
end
|
end
|
||||||
|
|
||||||
M.build = function (post)
|
M.build = function(post)
|
||||||
local proj = M.get_project()
|
local proj = M.get_project()
|
||||||
if not proj then
|
if not proj then
|
||||||
M.select_proj(function() M.build(post) end)
|
M.select_proj(function() M.build(post) end)
|
||||||
@@ -70,14 +70,14 @@ M.build = function (post)
|
|||||||
:start()
|
:start()
|
||||||
end
|
end
|
||||||
|
|
||||||
M.run = function ()
|
M.run = function()
|
||||||
local proj = M.get_project()
|
local proj = M.get_project()
|
||||||
if not proj then
|
if not proj then
|
||||||
M.select_proj(M.run)
|
M.select_proj(M.run)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
if proj.adapter.require_build then
|
if proj.adapter.require_build then
|
||||||
M.build(function (status)
|
M.build(function(status)
|
||||||
if status == 0 then
|
if status == 0 then
|
||||||
M.run()
|
M.run()
|
||||||
else
|
else
|
||||||
@@ -86,7 +86,7 @@ M.run = function ()
|
|||||||
end)
|
end)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
vim.cmd("cclose")
|
vim.cmd("cclose")
|
||||||
local oldwin = vim.api.nvim_get_current_win()
|
local oldwin = vim.api.nvim_get_current_win()
|
||||||
vim.cmd(M.config.height .. "split")
|
vim.cmd(M.config.height .. "split")
|
||||||
@@ -100,8 +100,4 @@ M.run = function ()
|
|||||||
vim.api.nvim_set_current_win(oldwin)
|
vim.api.nvim_set_current_win(oldwin)
|
||||||
end
|
end
|
||||||
|
|
||||||
M.cancel = function ()
|
|
||||||
vim.cmd(":AsyncStop")
|
|
||||||
end
|
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|||||||
Reference in New Issue
Block a user