mirror of
https://github.com/kristoferssolo/runner.nvim.git
synced 2025-10-21 19:50:34 +00:00
Merge branch 'dev' into StyLua-workflow
This commit is contained in:
commit
92e206ae85
5
.pre-commit-config.yaml
Normal file
5
.pre-commit-config.yaml
Normal file
@ -0,0 +1,5 @@
|
||||
repos:
|
||||
- repo: https://github.com/JohnnyMorganz/StyLua
|
||||
rev: v0.17.1
|
||||
hooks:
|
||||
- id: stylua-github
|
||||
10
.stylua.toml
Normal file
10
.stylua.toml
Normal file
@ -0,0 +1,10 @@
|
||||
column_width = 120
|
||||
line_endings = "Unix"
|
||||
indent_type = "Spaces"
|
||||
indent_width = 2
|
||||
quote_style = "AutoPreferSingle"
|
||||
call_parentheses = "NoSingleTable"
|
||||
collapse_simple_statement = "Never"
|
||||
|
||||
[sort_requires]
|
||||
enabled = false
|
||||
@ -1,9 +1,9 @@
|
||||
local M = {}
|
||||
|
||||
local defaults = {
|
||||
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
|
||||
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
|
||||
}
|
||||
|
||||
M.options = {}
|
||||
|
||||
@ -23,10 +23,10 @@ M.shell_handler = function(command, editable)
|
||||
local output_window = utils.create_window()
|
||||
vim.api.nvim_win_set_buf(output_window, output_buffer)
|
||||
|
||||
vim.fn.termopen(command, {
|
||||
cwd = vim.fn.getcwd(),
|
||||
})
|
||||
end
|
||||
vim.fn.termopen(command, {
|
||||
cwd = vim.fn.getcwd(),
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
M.command_handler = function(command)
|
||||
@ -45,27 +45,27 @@ M.choice = function(handlers)
|
||||
return vim.tbl_values(handlers)[1]
|
||||
end
|
||||
|
||||
return function(buffer)
|
||||
local picker = pickers.new(
|
||||
{},
|
||||
themes.get_dropdown({
|
||||
prompt_title = "Runner",
|
||||
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()
|
||||
actions.close(prompt_bufnr)
|
||||
local handler_name = action_state.get_selected_entry()[1]
|
||||
handlers[handler_name](buffer)
|
||||
end)
|
||||
return true
|
||||
end,
|
||||
})
|
||||
)
|
||||
picker:find()
|
||||
end
|
||||
return function(buffer)
|
||||
local picker = pickers.new(
|
||||
{},
|
||||
themes.get_dropdown {
|
||||
prompt_title = 'Runner',
|
||||
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()
|
||||
actions.close(prompt_bufnr)
|
||||
local handler_name = action_state.get_selected_entry()[1]
|
||||
handlers[handler_name](buffer)
|
||||
end)
|
||||
return true
|
||||
end,
|
||||
}
|
||||
)
|
||||
picker:find()
|
||||
end
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
@ -1,12 +1,12 @@
|
||||
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,5 +1,5 @@
|
||||
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)
|
||||
@ -13,9 +13,9 @@ return function(buffer)
|
||||
end
|
||||
end
|
||||
|
||||
local handlers = {
|
||||
["Run current file"] = helpers.shell_handler("node " .. vim.fn.expand("%")),
|
||||
}
|
||||
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)
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
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)
|
||||
|
||||
@ -18,56 +18,56 @@ M.create_buffer = function()
|
||||
end
|
||||
|
||||
M.create_window = function()
|
||||
if M._window and vim.api.nvim_win_is_valid(M._window) then
|
||||
vim.api.nvim_set_current_win(M._window)
|
||||
return M._window
|
||||
end
|
||||
if M._window and vim.api.nvim_win_is_valid(M._window) then
|
||||
vim.api.nvim_set_current_win(M._window)
|
||||
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")
|
||||
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')
|
||||
end
|
||||
|
||||
local window = vim.api.nvim_get_current_win()
|
||||
local window = vim.api.nvim_get_current_win()
|
||||
|
||||
local window_opts = {
|
||||
number = false,
|
||||
relativenumber = false,
|
||||
wrap = true,
|
||||
spell = false,
|
||||
foldenable = false,
|
||||
signcolumn = "no",
|
||||
colorcolumn = "",
|
||||
cursorline = true,
|
||||
}
|
||||
local window_opts = {
|
||||
number = false,
|
||||
relativenumber = false,
|
||||
wrap = true,
|
||||
spell = false,
|
||||
foldenable = false,
|
||||
signcolumn = 'no',
|
||||
colorcolumn = '',
|
||||
cursorline = true,
|
||||
}
|
||||
|
||||
for key, value in pairs(window_opts) do
|
||||
vim.api.nvim_win_set_option(window, key, value)
|
||||
end
|
||||
for key, value in pairs(window_opts) do
|
||||
vim.api.nvim_win_set_option(window, key, value)
|
||||
end
|
||||
|
||||
M._window = window
|
||||
return window
|
||||
M._window = window
|
||||
return window
|
||||
end
|
||||
|
||||
M.run_command = function(command, callback)
|
||||
local output = {}
|
||||
local output = {}
|
||||
|
||||
local add_line = function(_, data)
|
||||
output[#output + 1] = data
|
||||
end
|
||||
local add_line = function(_, data)
|
||||
output[#output + 1] = data
|
||||
end
|
||||
|
||||
vim.fn.jobstart(command, {
|
||||
cwd = vim.fn.getcwd(),
|
||||
on_stdout = add_line,
|
||||
on_exit = function()
|
||||
callback(output)
|
||||
end,
|
||||
})
|
||||
vim.fn.jobstart(command, {
|
||||
cwd = vim.fn.getcwd(),
|
||||
on_stdout = add_line,
|
||||
on_exit = function()
|
||||
callback(output)
|
||||
end,
|
||||
})
|
||||
end
|
||||
|
||||
local is_win = function()
|
||||
|
||||
@ -14,22 +14,22 @@ M.set_handler = function(filetype, handler)
|
||||
end
|
||||
|
||||
M.run = function(bufnr)
|
||||
local buffer
|
||||
if bufnr == nil or bufnr == 0 then
|
||||
buffer = vim.api.nvim_get_current_buf()
|
||||
else
|
||||
buffer = bufnr
|
||||
end
|
||||
local filetype = vim.filetype.match({ buf = buffer })
|
||||
local buffer
|
||||
if bufnr == nil or bufnr == 0 then
|
||||
buffer = vim.api.nvim_get_current_buf()
|
||||
else
|
||||
buffer = bufnr
|
||||
end
|
||||
local filetype = vim.filetype.match { buf = buffer }
|
||||
|
||||
local handler = M._handlers[filetype]
|
||||
local handler = M._handlers[filetype]
|
||||
|
||||
if not handler then
|
||||
print(string.format("No handler defined for filetype '%s'", filetype))
|
||||
return
|
||||
end
|
||||
if not handler then
|
||||
print(string.format("No handler defined for filetype '%s'", filetype))
|
||||
return
|
||||
end
|
||||
|
||||
handler(buffer)
|
||||
handler(buffer)
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
Loading…
Reference in New Issue
Block a user