Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
root = true

[*]
indent_style = space
indent_size = 2
trim_trailing_whitespace = true
insert_final_newline = true

[Makefile]
indent_style = tab
25 changes: 25 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Tests

on:
push:
pull_request:

jobs:
test:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Install Neovim
run: |
sudo apt-get update
sudo apt-get install -y neovim

- name: Install test dependencies
run: |
make deps

- name: Run tests
run: |
make test
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
deps
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
deps:
git clone https://github.com/nvim-lua/plenary.nvim deps/plenary.nvim

test:
XDG_CONFIG_HOME=. \
nvim --headless --clean -u tests/minimal_init.lua \
-c "PlenaryBustedFile tests/test_*.lua" \
-c "qa"
22 changes: 11 additions & 11 deletions lua/argwrap/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,18 @@ function M.extract_container_arg_text(range, line_prefix)
local text = ''
for lineIndex = range.lineStart, range.lineEnd do
local lineText = fn.getline(lineIndex)
local extractStart = (lineIndex == range.lineStart) and range.colStart or 0
local extractEnd = (lineIndex == range.lineEnd) and (range.colEnd - 1) or #lineText

if extractStart < extractEnd then
local extract = string.sub(lineText, extractStart + 1, extractEnd)
local extractStart = (lineIndex == range.lineStart) and range.colStart or 1
local extractEnd = (lineIndex == range.lineEnd) and (range.colEnd - 1) or #lineText
if extractStart <= extractEnd then
local extract = string.sub(lineText, extractStart, extractEnd)
extract = extract:gsub('^%s*(.-)%s*$', '%1')
-- Remove opening brace if present
extract = extract:gsub('^[%(%[%{]', '')
-- Remove closing brace if present
extract = extract:gsub('[%)%]%}]$', '')
if vim.startswith(extract, line_prefix) then
extract = extract:sub(#line_prefix + 1)
end
extract = extract:gsub(',$', ', ')
text = text .. extract
end
end
Expand Down Expand Up @@ -134,6 +136,7 @@ function M.extract_container_args(text)
end

argument = M.trim_argument(argument)
argument = argument:gsub(',$', '')
if #argument > 0 then
table.insert(arguments, argument)
end
Expand All @@ -160,16 +163,13 @@ function M.wrap_container(range, container, arguments, wrap_brace, tail_comma, l
local text = container.indent .. line_prefix .. arg
if index < #arguments or tail_comma then
text = text .. ','
elseif not wrap_brace then
text = text .. container.suffix
end
fn.append(line, text)
line = line + 1
api.nvim_command(('%d>'):format(line))
end

if wrap_brace then
fn.append(line, container.indent .. line_prefix .. container.suffix)
fn.append(line, container.indent .. container.suffix)
end
end

Expand All @@ -187,7 +187,7 @@ function M.unwrap_container(range, container, arguments, padded)
container.suffix
)
fn.setline(range.lineStart, text)
api.nvim_command(('silent %d,%dd_'):format(range.lineStart + 1, range.lineEnd))
api.nvim_command(string.format('silent %d,%dd_', range.lineStart + 1, range.lineEnd))
end

-- Get buffer or global setting
Expand Down
11 changes: 11 additions & 0 deletions tests/minimal_init.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
vim.opt.rtp = {}

local cwd = vim.fn.getcwd()

vim.opt.rtp:append(cwd)

vim.opt.rtp:append(cwd .. "/deps/plenary.nvim")

vim.cmd("runtime! plugin/plenary.vim")
vim.cmd("filetype off")
vim.cmd("syntax off")
Loading