This commit is contained in:
MarcHamamji 2023-04-05 13:45:49 +03:00
parent 92e206ae85
commit 67e9354280
8 changed files with 100 additions and 100 deletions

View File

@ -9,7 +9,7 @@ local defaults = {
M.options = {}
M.setup = function(options)
M.options = vim.tbl_deep_extend("force", {}, defaults, options or {})
M.options = vim.tbl_deep_extend('force', {}, defaults, options or {})
end
M.setup()

View File

@ -1,27 +1,27 @@
local pickers = require("telescope.pickers")
local finders = require("telescope.finders")
local actions = require("telescope.actions")
local action_state = require("telescope.actions.state")
local sorters = require("telescope.sorters")
local themes = require("telescope.themes")
local pickers = require('telescope.pickers')
local finders = require('telescope.finders')
local actions = require('telescope.actions')
local action_state = require('telescope.actions.state')
local sorters = require('telescope.sorters')
local themes = require('telescope.themes')
local utils = require("runner.handlers.utils")
local utils = require('runner.handlers.utils')
local M = {}
M.shell_handler = function(command, editable)
if editable == nil then
editable = false
end
return function(_)
if editable then
command = vim.fn.input("Command: ", command)
end
if editable == nil then
editable = false
end
return function(_)
if editable then
command = vim.fn.input('Command: ', command)
end
local output_buffer = utils.create_buffer()
local output_buffer = utils.create_buffer()
local output_window = utils.create_window()
vim.api.nvim_win_set_buf(output_window, output_buffer)
local output_window = utils.create_window()
vim.api.nvim_win_set_buf(output_window, output_buffer)
vim.fn.termopen(command, {
cwd = vim.fn.getcwd(),
@ -30,20 +30,20 @@ M.shell_handler = function(command, editable)
end
M.command_handler = function(command)
return function()
vim.cmd(command)
end
return function()
vim.cmd(command)
end
end
-- handlers = { 'Run Tests' = test_handler, 'Run Code' = code_handler }
M.choice = function(handlers)
local handlers_count = vim.tbl_count(handlers)
if handlers_count == 0 then
print("No handler available right now")
return function() end
elseif handlers_count == 1 then
return vim.tbl_values(handlers)[1]
end
local handlers_count = vim.tbl_count(handlers)
if handlers_count == 0 then
print('No handler available right now')
return function() end
elseif handlers_count == 1 then
return vim.tbl_values(handlers)[1]
end
return function(buffer)
local picker = pickers.new(

View File

@ -1,4 +1,4 @@
local helpers = require("runner.handlers.helpers")
local helpers = require('runner.handlers.helpers')
local handlers = {
rust = require('runner.handlers.languages.rust'),

View File

@ -2,25 +2,25 @@ local helpers = require('runner.handlers.helpers')
local utils = require('runner.handlers.utils')
return function(buffer)
utils.run_command(utils.script_path() .. "get-scripts.sh", function(output)
local bins = {}
utils.run_command(utils.script_path() .. 'get-scripts.sh', function(output)
local bins = {}
for _, line in pairs(output) do
for _, data in pairs(line) do
if vim.trim(data) ~= "" then
bins[#bins + 1] = data
end
end
end
for _, line in pairs(output) do
for _, data in pairs(line) do
if vim.trim(data) ~= '' then
bins[#bins + 1] = data
end
end
end
local handlers = {
['Run current file'] = helpers.shell_handler('node ' .. vim.fn.expand('%')),
}
for _, bin in pairs(bins) do
handlers['Run "' .. bin .. '"'] = helpers.shell_handler("npm run " .. bin)
end
for _, bin in pairs(bins) do
handlers['Run "' .. bin .. '"'] = helpers.shell_handler('npm run ' .. bin)
end
helpers.choice(handlers)(buffer)
end)
helpers.choice(handlers)(buffer)
end)
end

View File

@ -1,5 +1,5 @@
local helpers = require("runner.handlers.helpers")
local helpers = require('runner.handlers.helpers')
return function(buffer)
helpers.shell_handler("python " .. vim.fn.expand("%"))(buffer)
helpers.shell_handler('python ' .. vim.fn.expand('%'))(buffer)
end

View File

@ -2,45 +2,45 @@ local helpers = require('runner.handlers.helpers')
local utils = require('runner.handlers.utils')
return function(buffer)
utils.run_command(utils.script_path() .. "get-bins.sh", function(output)
local bins = {}
utils.run_command(utils.script_path() .. 'get-bins.sh', function(output)
local bins = {}
for _, line in pairs(output) do
for _, data in pairs(line) do
if vim.trim(data) ~= "" then
bins[#bins + 1] = data
end
end
end
for _, line in pairs(output) do
for _, data in pairs(line) do
if vim.trim(data) ~= '' then
bins[#bins + 1] = data
end
end
end
local run_handlers = {}
local run_handlers = {}
for _, bin in pairs(bins) do
run_handlers['Run "' .. bin .. '"'] = helpers.shell_handler("cargo run --bin " .. bin)
end
for _, bin in pairs(bins) do
run_handlers['Run "' .. bin .. '"'] = helpers.shell_handler('cargo run --bin ' .. bin)
end
utils.run_command(utils.script_path() .. "get-tests.sh", function(output)
local bins = {}
utils.run_command(utils.script_path() .. 'get-tests.sh', function(output)
local bins = {}
for _, line in pairs(output) do
for _, data in pairs(line) do
if vim.trim(data) ~= "" then
bins[#bins + 1] = data
end
end
end
for _, line in pairs(output) do
for _, data in pairs(line) do
if vim.trim(data) ~= '' then
bins[#bins + 1] = data
end
end
end
local handlers = {
unpack(run_handlers),
["Custom"] = helpers.shell_handler("cargo ", true),
["Test all"] = helpers.shell_handler("cargo test"),
}
local handlers = {
unpack(run_handlers),
['Custom'] = helpers.shell_handler('cargo ', true),
['Test all'] = helpers.shell_handler('cargo test'),
}
for _, bin in pairs(bins) do
handlers['Test "' .. bin .. '"'] = helpers.shell_handler("cargo test --test " .. bin)
end
for _, bin in pairs(bins) do
handlers['Test "' .. bin .. '"'] = helpers.shell_handler('cargo test --test ' .. bin)
end
helpers.choice(handlers)(buffer)
end)
end)
helpers.choice(handlers)(buffer)
end)
end)
end

View File

@ -1,20 +1,20 @@
local M = {}
local config = require("runner.config")
local config = require('runner.config')
M._buffer = nil
M._window = nil
M.create_buffer = function()
if M._buffer then
vim.api.nvim_buf_delete(M._buffer, {})
end
if M._buffer then
vim.api.nvim_buf_delete(M._buffer, {})
end
local buffer = vim.api.nvim_create_buf(true, true)
vim.api.nvim_buf_set_option(buffer, "modifiable", false)
local buffer = vim.api.nvim_create_buf(true, true)
vim.api.nvim_buf_set_option(buffer, 'modifiable', false)
M._buffer = buffer
return buffer
M._buffer = buffer
return buffer
end
M.create_window = function()
@ -71,22 +71,22 @@ M.run_command = function(command, callback)
end
local is_win = function()
return package.config:sub(1, 1) == "\\"
return package.config:sub(1, 1) == '\\'
end
local get_path_separator = function()
if package.config:sub(1, 1) == "\\" then
return "\\"
end
return "/"
if package.config:sub(1, 1) == '\\' then
return '\\'
end
return '/'
end
M.script_path = function()
local str = debug.getinfo(2, "S").source:sub(2)
if is_win() then
str = str:gsub("/", "\\")
end
return str:match("(.*" .. get_path_separator() .. ")")
local str = debug.getinfo(2, 'S').source:sub(2)
if is_win() then
str = str:gsub('/', '\\')
end
return str:match('(.*' .. get_path_separator() .. ')')
end
return M

View File

@ -1,16 +1,16 @@
local handlers = require("runner.handlers")
local config = require("runner.config")
local handlers = require('runner.handlers')
local config = require('runner.config')
local M = {}
M._handlers = handlers
M.setup = function(options)
config.setup(options)
config.setup(options)
end
M.set_handler = function(filetype, handler)
M._handlers[filetype] = handler
M._handlers[filetype] = handler
end
M.run = function(bufnr)