Skip to content

ref!: major refactor #150

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 56 commits into from
Jul 21, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
4d39989
chore(doc): auto generate docs
github-actions[bot] Jun 6, 2024
40a5d00
chore: shuffle all autocmd functions into the event module
xiaoshihou514 Jun 6, 2024
f19c4fd
chore: remove deprecated methods
xiaoshihou514 Jun 6, 2024
7399998
doc: add example of how to write custom formatting logic
xiaoshihou514 Jun 6, 2024
c9b9488
doc: promote advanced.md in README
xiaoshihou514 Jun 6, 2024
1b0d339
fix: typo
xiaoshihou514 Jun 6, 2024
8ad2cd4
chore: less verbose alias
xiaoshihou514 Jun 7, 2024
e0b7039
wip: basic outlinen of do_fmt
xiaoshihou514 Jun 7, 2024
d373d6d
wip: formatting module
xiaoshihou514 Jun 8, 2024
3cf35c1
fix: "async" execution using coroutines
xiaoshihou514 Jun 10, 2024
547149c
chore: remove version checks
xiaoshihou514 Jun 10, 2024
c35b0e1
feat: formatting module working correctly
xiaoshihou514 Jun 11, 2024
5be58dd
fix: autocmd test
xiaoshihou514 Jun 11, 2024
df79ed6
wip: mess with changedtick
xiaoshihou514 Jun 11, 2024
c96d016
fix: incorrect changedtick
xiaoshihou514 Jun 11, 2024
651d53b
chore: more rigorous error handling
xiaoshihou514 Jun 11, 2024
0a8e6b2
wip: lsp formatting
xiaoshihou514 Jun 12, 2024
ab5b673
fix: potential race condition
xiaoshihou514 Jun 12, 2024
4ec630e
fix: lint module
xiaoshihou514 Jun 12, 2024
248e533
feat: enhancements for linter module
xiaoshihou514 Jun 13, 2024
7950c42
doc: add nice looking demos :)
xiaoshihou514 Jun 13, 2024
434dc80
doc: formatting
xiaoshihou514 Jun 13, 2024
341b579
fix: save view
xiaoshihou514 Jun 13, 2024
b149d11
fix: remove deepcopies
xiaoshihou514 Jun 13, 2024
639ef8e
fix: tbl_filter and exepath
xiaoshihou514 Jun 13, 2024
527696e
chore: use custom table copy
xiaoshihou514 Jun 16, 2024
19a96d7
fix: existing tests
xiaoshihou514 Jun 17, 2024
3c1caff
test: toolcopy
xiaoshihou514 Jun 17, 2024
59c4527
chore: apply changes
xiaoshihou514 Jun 17, 2024
b3e42b0
doc: advanced linter customization
xiaoshihou514 Jun 17, 2024
6f6fe0f
Merge branch 'ref-api' of github.com:xiaoshihou514/guard.nvim into re…
xiaoshihou514 Jun 17, 2024
79bd3fa
fix: link
xiaoshihou514 Jun 17, 2024
8b496bf
fix: emoji
xiaoshihou514 Jun 17, 2024
e41c0e2
doc: fix missing line
xiaoshihou514 Jun 18, 2024
59c3977
chore: add types
xiaoshihou514 Jun 19, 2024
d425c0a
fix: types
xiaoshihou514 Jun 19, 2024
4e8f7d6
fix: use fnamemodify
xiaoshihou514 Jun 19, 2024
b3fa4c7
chore: refine code
xiaoshihou514 Jun 26, 2024
fb98efd
fix: lsp warning
xiaoshihou514 Jul 1, 2024
2fde1a6
chore: add executable check for linters
xiaoshihou514 Jul 2, 2024
7e2b579
chore: check executable in setup instead
xiaoshihou514 Jul 2, 2024
3bb6227
chore: remove redundant bufid check
xiaoshihou514 Jul 2, 2024
5f01630
fix: typo
xiaoshihou514 Jul 3, 2024
b322cfc
feat: more elegant checking and corresponding tests
xiaoshihou514 Jul 3, 2024
b2b900d
chore: rename due to namespace conflict
xiaoshihou514 Jul 3, 2024
eec417e
chore: ensure non nil
xiaoshihou514 Jul 3, 2024
475d970
chore: consistent executable checks
xiaoshihou514 Jul 3, 2024
3b79f3a
fix: incorrect copy and paste
xiaoshihou514 Jul 3, 2024
da9d6e2
chore: use vim.iter more
xiaoshihou514 Jul 3, 2024
9ae2f34
test: test for multiple formatters
xiaoshihou514 Jul 3, 2024
1835101
chore: ignore patterns should support single string
xiaoshihou514 Jul 3, 2024
939f6f4
feat: exepath patch for windows
xiaoshihou514 Jul 7, 2024
b051387
fix: exe check warning msg
xiaoshihou514 Jul 7, 2024
e377b9a
fix: update plugin/guard.lua
xiaoshihou514 Jul 10, 2024
787dac2
feat: tests for commands
xiaoshihou514 Jul 12, 2024
d31e457
fix: lsp attach autocmd
xiaoshihou514 Jul 15, 2024
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
Prev Previous commit
Next Next commit
chore: refine code
  • Loading branch information
xiaoshihou514 committed Jun 26, 2024
commit b3fa4c7318b9491dd9d6b37e8df5248e8a0ab0c1
3 changes: 1 addition & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ jobs:
version: latest
args: --check .


docs:
runs-on: ubuntu-latest
name: pandoc to vimdoc
Expand All @@ -28,7 +27,7 @@ jobs:
treesitter: true
- uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: 'chore(doc): auto generate docs'
commit_message: "chore(doc): auto generate docs"
commit_user_name: "github-actions[bot]"
commit_user_email: "github-actions[bot]@users.noreply.github.com"
commit_author: "github-actions[bot] <github-actions[bot]@users.noreply.github.com>"
Expand Down
13 changes: 7 additions & 6 deletions lua/guard/events.lua
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
local api, uv = vim.api, vim.uv
local group = api.nvim_create_augroup('Guard', { clear = true })
local au = api.nvim_create_autocmd
local M = {}

function M.attach_to_buf(buf)
api.nvim_create_autocmd('BufWritePre', {
au('BufWritePre', {
group = group,
buffer = buf,
callback = function(opt)
Expand All @@ -16,7 +17,7 @@ function M.attach_to_buf(buf)
end

function M.watch_ft(ft)
api.nvim_create_autocmd('FileType', {
au('FileType', {
group = group,
pattern = ft,
callback = function(args)
Expand All @@ -35,7 +36,7 @@ function M.watch_ft(ft)
end

function M.create_lspattach_autocmd(fmt_on_save)
api.nvim_create_autocmd('LspAttach', {
au('LspAttach', {
group = group,
callback = function(args)
local client = vim.lsp.get_client_by_id(args.data.client_id)
Expand Down Expand Up @@ -65,7 +66,7 @@ end

local debounce_timer = nil
function M.register_lint(ft, events)
api.nvim_create_autocmd('FileType', {
au('FileType', {
pattern = ft,
group = group,
callback = function(args)
Expand All @@ -87,7 +88,7 @@ function M.register_lint(ft, events)
end
for _, ev in ipairs(events) do
if ev == 'User GuardFmt' then
api.nvim_create_autocmd('User', {
au('User', {
group = group,
pattern = 'GuardFmt',
callback = function(opt)
Expand All @@ -97,7 +98,7 @@ function M.register_lint(ft, events)
end,
})
else
api.nvim_create_autocmd(ev, {
au(ev, {
group = group,
buffer = args.buf,
callback = cb,
Expand Down
13 changes: 7 additions & 6 deletions lua/guard/format.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ local api = vim.api
local spawn = require('guard.spawn')
local util = require('guard.util')
local filetype = require('guard.filetype')
local iter, filter = vim.iter, vim.tbl_filter

local function save_views(bufnr)
local views = {}
Expand Down Expand Up @@ -87,29 +88,29 @@ local function do_fmt(buf)
local fname, startpath, root_dir, cwd = util.buf_get_info(buf)

-- handle execution condition
fmt_configs = vim.tbl_filter(function(config)
fmt_configs = filter(function(config)
return util.should_run(config, buf, startpath, root_dir)
end, fmt_configs)

-- check if all cmds executable
local non_excutable = vim.tbl_filter(function(config)
local non_excutable = filter(function(config)
return config.cmd and vim.fn.executable(config.cmd) ~= 1
end, fmt_configs)

if #non_excutable > 0 then
error(table.concat(
error(('%s not executable'):format(table.concat(
vim.tbl_map(function(config)
return config.cmd
end, non_excutable),
', '
) .. ' not executable')
)))
end

-- filter out "pure" and "impure" formatters
local pure = vim.iter(vim.tbl_filter(function(config)
local pure = iter(filter(function(config)
return config.fn or (config.cmd and config.stdin)
end, fmt_configs))
local impure = vim.iter(vim.tbl_filter(function(config)
local impure = iter(filter(function(config)
return config.cmd and not config.stdin
end, fmt_configs))

Expand Down
14 changes: 14 additions & 0 deletions test/spawn_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---@diagnostic disable: undefined-field, undefined-global
local spawn = require('guard.spawn')
local same = assert.are.same

describe('spawn module', function()
it('can spawn executables with stdin access', function()
coroutine.resume(coroutine.create(function()
local result = spawn.transform({ 'tac', '-s', ' ' }, {
stdin = true,
}, 'test1 test2 test3 ')
same(result, 'test3 test2 test1 ')
end))
end)
end)