Better DX

This commit is contained in:
Marc 2023-04-05 13:54:04 +03:00 committed by GitHub
commit 42532e0b24
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 64 additions and 33 deletions

14
.github/workflows/main.yml vendored Normal file
View File

@ -0,0 +1,14 @@
name: Linting and style checking
on: [push, pull_request]
jobs:
stylua:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: JohnnyMorganz/stylua-action@v2
with:
token: ${{ secrets.GITHUB_TOKEN }}
version: latest
args: --check lua/

5
.pre-commit-config.yaml Normal file
View 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
View 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

View File

@ -2,8 +2,8 @@ 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
width = 80, -- width of window when position is left or right
height = 10, -- height of window when position is top or bottom
}
M.options = {}
@ -14,4 +14,4 @@ end
M.setup()
return M;
return M

View File

@ -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
@ -46,21 +46,24 @@ M.choice = function(handlers)
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,
}))
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

View File

@ -6,7 +6,7 @@ local handlers = {
lua = helpers.command_handler('luafile %'),
javascript = 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

View File

@ -1,5 +1,5 @@
local helpers = require('runner.handlers.helpers')
local utils = require('runner.handlers.utils')
local utils = require('runner.handlers.utils')
return function(buffer)
utils.run_command(utils.script_path() .. 'get-scripts.sh', function(output)
@ -14,7 +14,7 @@ return function(buffer)
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

View File

@ -1,5 +1,5 @@
local helpers = require('runner.handlers.helpers')
local utils = require('runner.handlers.utils')
local utils = require('runner.handlers.utils')
return function(buffer)
utils.run_command(utils.script_path() .. 'get-bins.sh', function(output)

View File

@ -23,13 +23,13 @@ M.create_window = function()
return M._window
end
if (config.options.position == 'right') then
if config.options.position == 'right' then
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')
elseif (config.options.position == 'bottom') then
elseif config.options.position == 'bottom' then
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')
end
@ -41,8 +41,8 @@ M.create_window = function()
wrap = true,
spell = false,
foldenable = false,
signcolumn = "no",
colorcolumn = "",
signcolumn = 'no',
colorcolumn = '',
cursorline = true,
}
@ -66,11 +66,10 @@ 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) == '\\'
end

View File

@ -20,12 +20,12 @@ M.run = function(bufnr)
else
buffer = bufnr
end
local filetype = vim.filetype.match({ buf = buffer })
local filetype = vim.filetype.match { buf = buffer }
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