mirror of
https://github.com/kristoferssolo/runner.nvim.git
synced 2025-10-21 19:50:34 +00:00
Lint
This commit is contained in:
parent
ce9ccbb77d
commit
8c1ed78cbf
@ -1,17 +1,17 @@
|
|||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
local defaults = {
|
local defaults = {
|
||||||
position = 'right', -- options: top, left, right, bottom
|
position = "right", -- options: top, left, right, bottom
|
||||||
width = 80, -- width of window when position is left or right
|
width = 80, -- width of window when position is left or right
|
||||||
height = 10, -- height of window when position is top or bottom
|
height = 10, -- height of window when position is top or bottom
|
||||||
}
|
}
|
||||||
|
|
||||||
M.options = {}
|
M.options = {}
|
||||||
|
|
||||||
M.setup = function(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
|
end
|
||||||
|
|
||||||
M.setup()
|
M.setup()
|
||||||
|
|
||||||
return M;
|
return M
|
||||||
|
|||||||
@ -1,68 +1,71 @@
|
|||||||
local pickers = require('telescope.pickers')
|
local pickers = require("telescope.pickers")
|
||||||
local finders = require('telescope.finders')
|
local finders = require("telescope.finders")
|
||||||
local actions = require('telescope.actions')
|
local actions = require("telescope.actions")
|
||||||
local action_state = require('telescope.actions.state')
|
local action_state = require("telescope.actions.state")
|
||||||
local sorters = require('telescope.sorters')
|
local sorters = require("telescope.sorters")
|
||||||
local themes = require('telescope.themes')
|
local themes = require("telescope.themes")
|
||||||
|
|
||||||
local utils = require('runner.handlers.utils')
|
local utils = require("runner.handlers.utils")
|
||||||
|
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
M.shell_handler = function(command, editable)
|
M.shell_handler = function(command, editable)
|
||||||
if editable == nil then
|
if editable == nil then
|
||||||
editable = false
|
editable = false
|
||||||
end
|
end
|
||||||
return function(_)
|
return function(_)
|
||||||
if editable then
|
if editable then
|
||||||
command = vim.fn.input('Command: ', command)
|
command = vim.fn.input("Command: ", command)
|
||||||
end
|
end
|
||||||
|
|
||||||
local output_buffer = utils.create_buffer()
|
local output_buffer = utils.create_buffer()
|
||||||
|
|
||||||
local output_window = utils.create_window()
|
local output_window = utils.create_window()
|
||||||
vim.api.nvim_win_set_buf(output_window, output_buffer)
|
vim.api.nvim_win_set_buf(output_window, output_buffer)
|
||||||
|
|
||||||
vim.fn.termopen(command, {
|
vim.fn.termopen(command, {
|
||||||
cwd = vim.fn.getcwd()
|
cwd = vim.fn.getcwd(),
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
M.command_handler = function(command)
|
M.command_handler = function(command)
|
||||||
return function()
|
return function()
|
||||||
vim.cmd(command)
|
vim.cmd(command)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- handlers = { 'Run Tests' = test_handler, 'Run Code' = code_handler }
|
-- handlers = { 'Run Tests' = test_handler, 'Run Code' = code_handler }
|
||||||
M.choice = function(handlers)
|
M.choice = function(handlers)
|
||||||
local handlers_count = vim.tbl_count(handlers)
|
local handlers_count = vim.tbl_count(handlers)
|
||||||
if handlers_count == 0 then
|
if handlers_count == 0 then
|
||||||
print('No handler available right now')
|
print("No handler available right now")
|
||||||
return function() end
|
return function() end
|
||||||
elseif handlers_count == 1 then
|
elseif handlers_count == 1 then
|
||||||
return vim.tbl_values(handlers)[1]
|
return vim.tbl_values(handlers)[1]
|
||||||
end
|
end
|
||||||
|
|
||||||
return function(buffer)
|
return function(buffer)
|
||||||
local picker = pickers.new({}, themes.get_dropdown({
|
local picker = pickers.new(
|
||||||
prompt_title = "Runner",
|
{},
|
||||||
finder = finders.new_table {
|
themes.get_dropdown({
|
||||||
results = vim.tbl_keys(handlers)
|
prompt_title = "Runner",
|
||||||
},
|
finder = finders.new_table({
|
||||||
sorter = sorters.get_generic_fuzzy_sorter(),
|
results = vim.tbl_keys(handlers),
|
||||||
attach_mappings = function(prompt_bufnr)
|
}),
|
||||||
actions.select_default:replace(function()
|
sorter = sorters.get_generic_fuzzy_sorter(),
|
||||||
actions.close(prompt_bufnr)
|
attach_mappings = function(prompt_bufnr)
|
||||||
local handler_name = action_state.get_selected_entry()[1]
|
actions.select_default:replace(function()
|
||||||
handlers[handler_name](buffer)
|
actions.close(prompt_bufnr)
|
||||||
end)
|
local handler_name = action_state.get_selected_entry()[1]
|
||||||
return true
|
handlers[handler_name](buffer)
|
||||||
end,
|
end)
|
||||||
}))
|
return true
|
||||||
picker:find()
|
end,
|
||||||
end
|
})
|
||||||
|
)
|
||||||
|
picker:find()
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|||||||
@ -1,12 +1,12 @@
|
|||||||
local helpers = require('runner.handlers.helpers')
|
local helpers = require("runner.handlers.helpers")
|
||||||
|
|
||||||
local handlers = {
|
local handlers = {
|
||||||
rust = require('runner.handlers.languages.rust'),
|
rust = require("runner.handlers.languages.rust"),
|
||||||
python = require('runner.handlers.languages.python'),
|
python = require("runner.handlers.languages.python"),
|
||||||
lua = helpers.command_handler('luafile %'),
|
lua = helpers.command_handler("luafile %"),
|
||||||
javascript = require('runner.handlers.languages.nodejs'),
|
javascript = require("runner.handlers.languages.nodejs"),
|
||||||
typescript = require('runner.handlers.languages.nodejs'),
|
typescript = require("runner.handlers.languages.nodejs"),
|
||||||
vue = require('runner.handlers.languages.nodejs')
|
vue = require("runner.handlers.languages.nodejs"),
|
||||||
}
|
}
|
||||||
|
|
||||||
return handlers
|
return handlers
|
||||||
|
|||||||
@ -1,26 +1,26 @@
|
|||||||
local helpers = require('runner.handlers.helpers')
|
local helpers = require("runner.handlers.helpers")
|
||||||
local utils = require('runner.handlers.utils')
|
local utils = require("runner.handlers.utils")
|
||||||
|
|
||||||
return function(buffer)
|
return function(buffer)
|
||||||
utils.run_command(utils.script_path() .. 'get-scripts.sh', function(output)
|
utils.run_command(utils.script_path() .. "get-scripts.sh", function(output)
|
||||||
local bins = {}
|
local bins = {}
|
||||||
|
|
||||||
for _, line in pairs(output) do
|
for _, line in pairs(output) do
|
||||||
for _, data in pairs(line) do
|
for _, data in pairs(line) do
|
||||||
if vim.trim(data) ~= '' then
|
if vim.trim(data) ~= "" then
|
||||||
bins[#bins + 1] = data
|
bins[#bins + 1] = data
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local handlers = {
|
local handlers = {
|
||||||
['Run current file'] = helpers.shell_handler('node ' .. vim.fn.expand('%'))
|
["Run current file"] = helpers.shell_handler("node " .. vim.fn.expand("%")),
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, bin in pairs(bins) do
|
for _, bin in pairs(bins) do
|
||||||
handlers['Run "' .. bin .. '"'] = helpers.shell_handler('npm run ' .. bin)
|
handlers['Run "' .. bin .. '"'] = helpers.shell_handler("npm run " .. bin)
|
||||||
end
|
end
|
||||||
|
|
||||||
helpers.choice(handlers)(buffer)
|
helpers.choice(handlers)(buffer)
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
local helpers = require('runner.handlers.helpers')
|
local helpers = require("runner.handlers.helpers")
|
||||||
|
|
||||||
return function(buffer)
|
return function(buffer)
|
||||||
helpers.shell_handler('python ' .. vim.fn.expand('%'))(buffer)
|
helpers.shell_handler("python " .. vim.fn.expand("%"))(buffer)
|
||||||
end
|
end
|
||||||
|
|||||||
@ -1,46 +1,46 @@
|
|||||||
local helpers = require('runner.handlers.helpers')
|
local helpers = require("runner.handlers.helpers")
|
||||||
local utils = require('runner.handlers.utils')
|
local utils = require("runner.handlers.utils")
|
||||||
|
|
||||||
return function(buffer)
|
return function(buffer)
|
||||||
utils.run_command(utils.script_path() .. 'get-bins.sh', function(output)
|
utils.run_command(utils.script_path() .. "get-bins.sh", function(output)
|
||||||
local bins = {}
|
local bins = {}
|
||||||
|
|
||||||
for _, line in pairs(output) do
|
for _, line in pairs(output) do
|
||||||
for _, data in pairs(line) do
|
for _, data in pairs(line) do
|
||||||
if vim.trim(data) ~= '' then
|
if vim.trim(data) ~= "" then
|
||||||
bins[#bins + 1] = data
|
bins[#bins + 1] = data
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local run_handlers = {}
|
local run_handlers = {}
|
||||||
|
|
||||||
for _, bin in pairs(bins) do
|
for _, bin in pairs(bins) do
|
||||||
run_handlers['Run "' .. bin .. '"'] = helpers.shell_handler('cargo run --bin ' .. bin)
|
run_handlers['Run "' .. bin .. '"'] = helpers.shell_handler("cargo run --bin " .. bin)
|
||||||
end
|
end
|
||||||
|
|
||||||
utils.run_command(utils.script_path() .. 'get-tests.sh', function(output)
|
utils.run_command(utils.script_path() .. "get-tests.sh", function(output)
|
||||||
local bins = {}
|
local bins = {}
|
||||||
|
|
||||||
for _, line in pairs(output) do
|
for _, line in pairs(output) do
|
||||||
for _, data in pairs(line) do
|
for _, data in pairs(line) do
|
||||||
if vim.trim(data) ~= '' then
|
if vim.trim(data) ~= "" then
|
||||||
bins[#bins + 1] = data
|
bins[#bins + 1] = data
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local handlers = {
|
local handlers = {
|
||||||
unpack(run_handlers),
|
unpack(run_handlers),
|
||||||
['Custom'] = helpers.shell_handler('cargo ', true),
|
["Custom"] = helpers.shell_handler("cargo ", true),
|
||||||
['Test all'] = helpers.shell_handler('cargo test'),
|
["Test all"] = helpers.shell_handler("cargo test"),
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, bin in pairs(bins) do
|
for _, bin in pairs(bins) do
|
||||||
handlers['Test "' .. bin .. '"'] = helpers.shell_handler('cargo test --test ' .. bin)
|
handlers['Test "' .. bin .. '"'] = helpers.shell_handler("cargo test --test " .. bin)
|
||||||
end
|
end
|
||||||
|
|
||||||
helpers.choice(handlers)(buffer)
|
helpers.choice(handlers)(buffer)
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|||||||
@ -1,93 +1,92 @@
|
|||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
local config = require('runner.config')
|
local config = require("runner.config")
|
||||||
|
|
||||||
M._buffer = nil
|
M._buffer = nil
|
||||||
M._window = nil
|
M._window = nil
|
||||||
|
|
||||||
M.create_buffer = function()
|
M.create_buffer = function()
|
||||||
if M._buffer then
|
if M._buffer then
|
||||||
vim.api.nvim_buf_delete(M._buffer, {})
|
vim.api.nvim_buf_delete(M._buffer, {})
|
||||||
end
|
end
|
||||||
|
|
||||||
local buffer = vim.api.nvim_create_buf(true, true)
|
local buffer = vim.api.nvim_create_buf(true, true)
|
||||||
vim.api.nvim_buf_set_option(buffer, 'modifiable', false)
|
vim.api.nvim_buf_set_option(buffer, "modifiable", false)
|
||||||
|
|
||||||
M._buffer = buffer
|
M._buffer = buffer
|
||||||
return buffer
|
return buffer
|
||||||
end
|
end
|
||||||
|
|
||||||
M.create_window = function()
|
M.create_window = function()
|
||||||
if M._window and vim.api.nvim_win_is_valid(M._window) then
|
if M._window and vim.api.nvim_win_is_valid(M._window) then
|
||||||
vim.api.nvim_set_current_win(M._window)
|
vim.api.nvim_set_current_win(M._window)
|
||||||
return M._window
|
return M._window
|
||||||
end
|
end
|
||||||
|
|
||||||
if (config.options.position == 'right') then
|
if config.options.position == "right" then
|
||||||
vim.cmd('botright ' .. config.options.width .. ' vsplit')
|
vim.cmd("botright " .. config.options.width .. " vsplit")
|
||||||
elseif (config.options.position == 'left') then
|
elseif config.options.position == "left" then
|
||||||
vim.cmd('topleft ' .. config.options.width .. ' vsplit')
|
vim.cmd("topleft " .. config.options.width .. " vsplit")
|
||||||
elseif (config.options.position == 'bottom') then
|
elseif config.options.position == "bottom" then
|
||||||
vim.cmd('botright ' .. config.options.height .. 'split')
|
vim.cmd("botright " .. config.options.height .. "split")
|
||||||
elseif (config.options.position == 'top') then
|
elseif config.options.position == "top" then
|
||||||
vim.cmd('topleft ' .. config.options.height .. 'split')
|
vim.cmd("topleft " .. config.options.height .. "split")
|
||||||
end
|
end
|
||||||
|
|
||||||
local window = vim.api.nvim_get_current_win()
|
local window = vim.api.nvim_get_current_win()
|
||||||
|
|
||||||
local window_opts = {
|
local window_opts = {
|
||||||
number = false,
|
number = false,
|
||||||
relativenumber = false,
|
relativenumber = false,
|
||||||
wrap = true,
|
wrap = true,
|
||||||
spell = false,
|
spell = false,
|
||||||
foldenable = false,
|
foldenable = false,
|
||||||
signcolumn = "no",
|
signcolumn = "no",
|
||||||
colorcolumn = "",
|
colorcolumn = "",
|
||||||
cursorline = true,
|
cursorline = true,
|
||||||
}
|
}
|
||||||
|
|
||||||
for key, value in pairs(window_opts) do
|
for key, value in pairs(window_opts) do
|
||||||
vim.api.nvim_win_set_option(window, key, value)
|
vim.api.nvim_win_set_option(window, key, value)
|
||||||
end
|
end
|
||||||
|
|
||||||
M._window = window
|
M._window = window
|
||||||
return window
|
return window
|
||||||
end
|
end
|
||||||
|
|
||||||
M.run_command = function(command, callback)
|
M.run_command = function(command, callback)
|
||||||
local output = {}
|
local output = {}
|
||||||
|
|
||||||
local add_line = function(_, data)
|
local add_line = function(_, data)
|
||||||
output[#output + 1] = data
|
output[#output + 1] = data
|
||||||
end
|
end
|
||||||
|
|
||||||
vim.fn.jobstart(command, {
|
vim.fn.jobstart(command, {
|
||||||
cwd = vim.fn.getcwd(),
|
cwd = vim.fn.getcwd(),
|
||||||
on_stdout = add_line,
|
on_stdout = add_line,
|
||||||
on_exit = function()
|
on_exit = function()
|
||||||
callback(output)
|
callback(output)
|
||||||
end
|
end,
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
local is_win = function()
|
local is_win = function()
|
||||||
return package.config:sub(1, 1) == '\\'
|
return package.config:sub(1, 1) == "\\"
|
||||||
end
|
end
|
||||||
|
|
||||||
local get_path_separator = function()
|
local get_path_separator = function()
|
||||||
if package.config:sub(1, 1) == '\\' then
|
if package.config:sub(1, 1) == "\\" then
|
||||||
return '\\'
|
return "\\"
|
||||||
end
|
end
|
||||||
return '/'
|
return "/"
|
||||||
end
|
end
|
||||||
|
|
||||||
M.script_path = function()
|
M.script_path = function()
|
||||||
local str = debug.getinfo(2, 'S').source:sub(2)
|
local str = debug.getinfo(2, "S").source:sub(2)
|
||||||
if is_win() then
|
if is_win() then
|
||||||
str = str:gsub('/', '\\')
|
str = str:gsub("/", "\\")
|
||||||
end
|
end
|
||||||
return str:match('(.*' .. get_path_separator() .. ')')
|
return str:match("(.*" .. get_path_separator() .. ")")
|
||||||
end
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|||||||
@ -1,35 +1,35 @@
|
|||||||
local handlers = require('runner.handlers')
|
local handlers = require("runner.handlers")
|
||||||
local config = require('runner.config')
|
local config = require("runner.config")
|
||||||
|
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
M._handlers = handlers
|
M._handlers = handlers
|
||||||
|
|
||||||
M.setup = function(options)
|
M.setup = function(options)
|
||||||
config.setup(options)
|
config.setup(options)
|
||||||
end
|
end
|
||||||
|
|
||||||
M.set_handler = function(filetype, handler)
|
M.set_handler = function(filetype, handler)
|
||||||
M._handlers[filetype] = handler
|
M._handlers[filetype] = handler
|
||||||
end
|
end
|
||||||
|
|
||||||
M.run = function(bufnr)
|
M.run = function(bufnr)
|
||||||
local buffer
|
local buffer
|
||||||
if bufnr == nil or bufnr == 0 then
|
if bufnr == nil or bufnr == 0 then
|
||||||
buffer = vim.api.nvim_get_current_buf()
|
buffer = vim.api.nvim_get_current_buf()
|
||||||
else
|
else
|
||||||
buffer = bufnr
|
buffer = bufnr
|
||||||
end
|
end
|
||||||
local filetype = vim.filetype.match({ buf = buffer })
|
local filetype = vim.filetype.match({ buf = buffer })
|
||||||
|
|
||||||
local handler = M._handlers[filetype]
|
local handler = M._handlers[filetype]
|
||||||
|
|
||||||
if not handler then
|
if not handler then
|
||||||
print(string.format('No handler defined for filetype \'%s\'', filetype))
|
print(string.format("No handler defined for filetype '%s'", filetype))
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
handler(buffer)
|
handler(buffer)
|
||||||
end
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user