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,7 +1,7 @@
|
||||
local M = {}
|
||||
|
||||
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
|
||||
height = 10, -- height of window when position is top or bottom
|
||||
}
|
||||
@ -9,9 +9,9 @@ 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()
|
||||
|
||||
return M;
|
||||
return M
|
||||
|
||||
@ -1,11 +1,11 @@
|
||||
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 = {}
|
||||
|
||||
@ -15,7 +15,7 @@ M.shell_handler = function(command, editable)
|
||||
end
|
||||
return function(_)
|
||||
if editable then
|
||||
command = vim.fn.input('Command: ', command)
|
||||
command = vim.fn.input("Command: ", command)
|
||||
end
|
||||
|
||||
local output_buffer = utils.create_buffer()
|
||||
@ -24,7 +24,7 @@ M.shell_handler = function(command, editable)
|
||||
vim.api.nvim_win_set_buf(output_window, output_buffer)
|
||||
|
||||
vim.fn.termopen(command, {
|
||||
cwd = vim.fn.getcwd()
|
||||
cwd = vim.fn.getcwd(),
|
||||
})
|
||||
end
|
||||
end
|
||||
@ -39,18 +39,20 @@ end
|
||||
M.choice = function(handlers)
|
||||
local handlers_count = vim.tbl_count(handlers)
|
||||
if handlers_count == 0 then
|
||||
print('No handler available right now')
|
||||
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({}, themes.get_dropdown({
|
||||
local picker = pickers.new(
|
||||
{},
|
||||
themes.get_dropdown({
|
||||
prompt_title = "Runner",
|
||||
finder = finders.new_table {
|
||||
results = vim.tbl_keys(handlers)
|
||||
},
|
||||
finder = finders.new_table({
|
||||
results = vim.tbl_keys(handlers),
|
||||
}),
|
||||
sorter = sorters.get_generic_fuzzy_sorter(),
|
||||
attach_mappings = function(prompt_bufnr)
|
||||
actions.select_default:replace(function()
|
||||
@ -60,7 +62,8 @@ M.choice = function(handlers)
|
||||
end)
|
||||
return true
|
||||
end,
|
||||
}))
|
||||
})
|
||||
)
|
||||
picker:find()
|
||||
end
|
||||
end
|
||||
|
||||
@ -1,12 +1,12 @@
|
||||
local helpers = require('runner.handlers.helpers')
|
||||
local helpers = require("runner.handlers.helpers")
|
||||
|
||||
local handlers = {
|
||||
rust = require('runner.handlers.languages.rust'),
|
||||
python = require('runner.handlers.languages.python'),
|
||||
lua = helpers.command_handler('luafile %'),
|
||||
javascript = require('runner.handlers.languages.nodejs'),
|
||||
typescript = require('runner.handlers.languages.nodejs'),
|
||||
vue = require('runner.handlers.languages.nodejs')
|
||||
rust = require("runner.handlers.languages.rust"),
|
||||
python = require("runner.handlers.languages.python"),
|
||||
lua = helpers.command_handler("luafile %"),
|
||||
javascript = require("runner.handlers.languages.nodejs"),
|
||||
typescript = require("runner.handlers.languages.nodejs"),
|
||||
vue = require("runner.handlers.languages.nodejs"),
|
||||
}
|
||||
|
||||
return handlers
|
||||
|
||||
@ -1,24 +1,24 @@
|
||||
local helpers = require('runner.handlers.helpers')
|
||||
local utils = require('runner.handlers.utils')
|
||||
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)
|
||||
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
|
||||
if vim.trim(data) ~= "" then
|
||||
bins[#bins + 1] = data
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
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
|
||||
handlers['Run "' .. bin .. '"'] = helpers.shell_handler('npm run ' .. bin)
|
||||
handlers['Run "' .. bin .. '"'] = helpers.shell_handler("npm run " .. bin)
|
||||
end
|
||||
|
||||
helpers.choice(handlers)(buffer)
|
||||
|
||||
@ -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
|
||||
|
||||
@ -1,13 +1,13 @@
|
||||
local helpers = require('runner.handlers.helpers')
|
||||
local utils = require('runner.handlers.utils')
|
||||
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)
|
||||
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
|
||||
if vim.trim(data) ~= "" then
|
||||
bins[#bins + 1] = data
|
||||
end
|
||||
end
|
||||
@ -16,15 +16,15 @@ return function(buffer)
|
||||
local run_handlers = {}
|
||||
|
||||
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
|
||||
|
||||
utils.run_command(utils.script_path() .. 'get-tests.sh', function(output)
|
||||
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
|
||||
if vim.trim(data) ~= "" then
|
||||
bins[#bins + 1] = data
|
||||
end
|
||||
end
|
||||
@ -32,12 +32,12 @@ return function(buffer)
|
||||
|
||||
local handlers = {
|
||||
unpack(run_handlers),
|
||||
['Custom'] = helpers.shell_handler('cargo ', true),
|
||||
['Test all'] = helpers.shell_handler('cargo test'),
|
||||
["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)
|
||||
handlers['Test "' .. bin .. '"'] = helpers.shell_handler("cargo test --test " .. bin)
|
||||
end
|
||||
|
||||
helpers.choice(handlers)(buffer)
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
local M = {}
|
||||
|
||||
local config = require('runner.config')
|
||||
local config = require("runner.config")
|
||||
|
||||
M._buffer = nil
|
||||
M._window = nil
|
||||
@ -11,7 +11,7 @@ M.create_buffer = function()
|
||||
end
|
||||
|
||||
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
|
||||
return buffer
|
||||
@ -23,14 +23,14 @@ M.create_window = function()
|
||||
return M._window
|
||||
end
|
||||
|
||||
if (config.options.position == 'right') then
|
||||
vim.cmd('botright ' .. config.options.width .. ' vsplit')
|
||||
elseif (config.options.position == 'left') then
|
||||
vim.cmd('topleft ' .. config.options.width .. ' vsplit')
|
||||
elseif (config.options.position == 'bottom') then
|
||||
vim.cmd('botright ' .. config.options.height .. 'split')
|
||||
elseif (config.options.position == 'top') then
|
||||
vim.cmd('topleft ' .. config.options.height .. 'split')
|
||||
if config.options.position == "right" then
|
||||
vim.cmd("botright " .. config.options.width .. " vsplit")
|
||||
elseif config.options.position == "left" then
|
||||
vim.cmd("topleft " .. config.options.width .. " vsplit")
|
||||
elseif config.options.position == "bottom" then
|
||||
vim.cmd("botright " .. config.options.height .. "split")
|
||||
elseif config.options.position == "top" then
|
||||
vim.cmd("topleft " .. config.options.height .. "split")
|
||||
end
|
||||
|
||||
local window = vim.api.nvim_get_current_win()
|
||||
@ -66,28 +66,27 @@ M.run_command = function(command, callback)
|
||||
on_stdout = add_line,
|
||||
on_exit = function()
|
||||
callback(output)
|
||||
end
|
||||
end,
|
||||
})
|
||||
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 '\\'
|
||||
if package.config:sub(1, 1) == "\\" then
|
||||
return "\\"
|
||||
end
|
||||
return '/'
|
||||
return "/"
|
||||
end
|
||||
|
||||
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
|
||||
str = str:gsub('/', '\\')
|
||||
str = str:gsub("/", "\\")
|
||||
end
|
||||
return str:match('(.*' .. get_path_separator() .. ')')
|
||||
return str:match("(.*" .. get_path_separator() .. ")")
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
local handlers = require('runner.handlers')
|
||||
local config = require('runner.config')
|
||||
local handlers = require("runner.handlers")
|
||||
local config = require("runner.config")
|
||||
|
||||
local M = {}
|
||||
|
||||
@ -25,7 +25,7 @@ M.run = function(bufnr)
|
||||
local handler = M._handlers[filetype]
|
||||
|
||||
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
|
||||
end
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user