Start run rework

This commit is contained in:
Zoe Roux
2022-04-27 17:45:18 +02:00
parent e829122b61
commit 767c4dc180
3 changed files with 54 additions and 27 deletions

View File

@@ -1,10 +1,10 @@
local Job = require'plenary.job'
local Job = require 'plenary.job'
local M = {}
M.pattern = "*.sln"
M.list = function ()
M.list = function()
local projs = io.popen("dotnet sln list | tail -n +3")
local ret = {}
for line in projs:lines() do
@@ -18,20 +18,36 @@ M.list = function ()
return ret
end
M.build = function (proj, opts)
M.build = function(proj, opts)
local function add_to_qf(err, data)
vim.fn.setqflist({}, "a", {
efm = [[%f(%l\,%c): %t%*[^ ] %m]],
lines = { err and err or data },
})
end
return Job:new(vim.tbl_deep_extend("force", opts, {
command = "dotnet",
args = {"build", proj},
on_stdout = function(error, data)
print(error, data)
end,
args = { "build", proj.csproj },
on_stdout = vim.schedule_wrap(add_to_qf),
on_stderr = vim.schedule_wrap(add_to_qf),
}))
end
M.errorformat = [[%f(%l\,%c): %t%*[^ ] %m]]
M.run = function (proj)
return "dotnet run --project " .. proj.csproj
M.run = function(proj)
local function add_to_out(err, line)
end
return Job:new({
command = "dotnet",
args = { "run", "--project", proj.csproj },
on_stdout = vim.schedule_wrap(add_to_out),
on_stderr = vim.schedule_wrap(add_to_out),
})
end
M.require_build = false
return M

View File

@@ -19,6 +19,11 @@ M.list_projs = function ()
for _, proj in pairs(adapter.list(match)) do
proj.adapter = adapter
proj.source = match
proj.icon = proj.icon or has_icon and nwicon.get_icon(
vim.fn.fnamemodify(proj.file, ':t'),
vim.fn.fnamemodify(proj.file, ':e'),
{ default = true }
) or " "
table.insert(projs, proj)
end
end
@@ -31,12 +36,7 @@ M.select_proj = function (on_select)
vim.ui.select(projs, {
prompt = "Select a project",
format_item = function (proj)
local icon = proj.icon or has_icon and nwicon.get_icon(
vim.fn.fnamemodify(proj.file, ':t'),
vim.fn.fnamemodify(proj.file, ':e'),
{ default = true }
) or " "
return icon .. " " .. proj.name, { {{0, 5}, "Comment"} }
return proj.icon .. " " .. proj.name
end
}, function (proj)
if not proj then return end
@@ -61,9 +61,16 @@ end
M.build = function (post)
local proj = M.get_project()
if not proj then
M.select_proj(M.build)
M.select_proj(function() M.build(post) end)
return
end
vim.fn.setqflist({}, "r", {
title = proj.icon .. " " .. proj.name,
})
vim.api.nvim_command('copen')
vim.api.nvim_command('wincmd p')
proj.adapter.build(proj, {
on_exit = post,
}):start()
@@ -75,15 +82,19 @@ M.run = function ()
M.select_proj(M.run)
return
end
M.build(function (status)
print(status)
if status == 0 then
vim.cmd(":cclose")
vim.cmd(":AsyncRun -mode=terminal -focus=0 -rows=" .. M.config.height .. " " .. proj.adapter.run(proj))
else
vim.notify("Build failed")
end
end)
if proj.adapter.require_build then
M.build(function (status)
if status == 0 then
M.run()
else
vim.notify("Build failed")
end
end)
return
end
vim.api.nvim_command(":cclose")
proj.adapter.run(proj):Start()
-- vim.cmd(":AsyncRun -mode=terminal -focus=0 -rows=" .. M.config.height .. " " .. proj.adapter.run(proj))
end
M.cancel = function ()

View File

@@ -4,7 +4,7 @@ vim.g["dispatch_no_maps"] = 1
local wk = require("which-key")
wk.register({
b = {
m = {
name = "Build",
b = { "<cmd>lua require('build').build()<cr>", "Build project" },
r = { "<cmd>lua require('build').run()<cr>", "Run project" },