Skip to content

Commit

Permalink
ci: lint with stylua
Browse files Browse the repository at this point in the history
  • Loading branch information
lewis6991 committed Dec 11, 2024
1 parent 3288c5a commit 9634e57
Show file tree
Hide file tree
Showing 8 changed files with 264 additions and 158 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,18 @@ jobs:
# Check commit messages
- uses: webiny/[email protected]

stylua:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Download stylua
run: make stylua

- name: Lint
run: make stylua-check

test:
runs-on: ubuntu-latest

Expand Down
31 changes: 31 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,34 @@ parsers: nvim-test nvim-treesitter

lint:
luacheck lua

# ------------------------------------------------------------------------------
# Stylua
# ------------------------------------------------------------------------------
ifeq ($(shell uname -s),Darwin)
STYLUA_PLATFORM := macos-aarch64
else
STYLUA_PLATFORM := linux-x86_64
endif

STYLUA_VERSION := v2.0.2
STYLUA_ZIP := stylua-$(STYLUA_PLATFORM).zip
STYLUA_URL := https://github.com/JohnnyMorganz/StyLua/releases/download/$(STYLUA_VERSION)/$(STYLUA_ZIP)

.INTERMEDIATE: $(STYLUA_ZIP)
$(STYLUA_ZIP):
wget $(STYLUA_URL)

stylua: $(STYLUA_ZIP)
unzip $<

.PHONY: stylua-check
stylua-check: stylua
./stylua --check lua/**/*.lua

.PHONY: stylua-run
stylua-run: stylua
./stylua \
lua/**/*.lua \
lua/*.lua \
test/*.lua
30 changes: 18 additions & 12 deletions lua/treesitter-context.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ local function throttle_by_id(f, ms)
local waiting = {} --- @type table<any,boolean>

local schedule = function(id, wrapper)
state[id] = "scheduled"
state[id] = 'scheduled'
vim.schedule_wrap(wrapper)(id, wrapper)
end

local on_throttle_finish = function(id, wrapper)
assert(state[id] == "throttled")
assert(state[id] == 'throttled')
if waiting[id] == nil then
timers[id] = nil
state[id] = nil
Expand All @@ -38,16 +38,18 @@ local function throttle_by_id(f, ms)
end

local wrapper = function(id, wrapper)
assert(state[id] == "scheduled")
state[id] = "running"
assert(state[id] == 'scheduled')
state[id] = 'running'
f(id)
assert(state[id] == "running")
state[id] = "throttled"
assert(state[id] == 'running')
state[id] = 'throttled'

if timers[id] == nil then
timers[id] = assert(vim.loop.new_timer())
end
timers[id]:start(ms, 0, function() on_throttle_finish(id, wrapper) end)
timers[id]:start(ms, 0, function()
on_throttle_finish(id, wrapper)
end)
end

return function(id)
Expand All @@ -57,7 +59,7 @@ local function throttle_by_id(f, ms)
end
-- Don't set 'waiting' for 'scheduled' state since the callback is about to start.
-- Consequently, there is no need to run it again after throttling is completed.
if state[id] ~= "scheduled" then
if state[id] ~= 'scheduled' then
waiting[id] = true
end
end
Expand All @@ -67,7 +69,7 @@ local attached = {} --- @type table<integer,true>

local function close(args)
local render = require('treesitter-context.render')
if args.event == "WinClosed" then
if args.event == 'WinClosed' then
-- Closing current window instead of intended window may lead to context window flickering.
render.close(tonumber(args.match))
else
Expand Down Expand Up @@ -131,11 +133,11 @@ end)

---@param args table
local function update(args)
if args.event == "OptionSet" and args.match ~= 'number' and args.match ~= 'relativenumber' then
if args.event == 'OptionSet' and args.match ~= 'number' and args.match ~= 'relativenumber' then
return
end

local multiwindow_events = { "WinResized", "User" }
local multiwindow_events = { 'WinResized', 'User' }

if config.multiwindow and vim.tbl_contains(multiwindow_events, args.event) then
-- Resizing a single window may cause many resizes in different windows,
Expand Down Expand Up @@ -258,7 +260,11 @@ local function init()
api.nvim_set_hl(0, 'TreesitterContext', { link = 'NormalFloat', default = true })
api.nvim_set_hl(0, 'TreesitterContextLineNumber', { link = 'LineNr', default = true })
api.nvim_set_hl(0, 'TreesitterContextBottom', { link = 'NONE', default = true })
api.nvim_set_hl(0, 'TreesitterContextLineNumberBottom', { link = 'TreesitterContextBottom', default = true })
api.nvim_set_hl(
0,
'TreesitterContextLineNumberBottom',
{ link = 'TreesitterContextBottom', default = true }
)
api.nvim_set_hl(0, 'TreesitterContextSeparator', { link = 'FloatBorder', default = true })
end

Expand Down
3 changes: 1 addition & 2 deletions lua/treesitter-context/config.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

--- @class (exact) TSContext.Config
--- @field enable boolean
--- @field multiwindow boolean
Expand Down Expand Up @@ -72,7 +71,7 @@ end
setmetatable(M, {
__index = function(_, k)
return config[k]
end
end,
})

return M
10 changes: 8 additions & 2 deletions lua/treesitter-context/render.lua
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ local function build_lno_str(win, lnum, width)
winid = win,
use_statuscol_lnum = lnum,
highlights = true,
fillchar = ' ', -- Fixed in Neovim 0.10 (#396)
fillchar = ' ', -- Fixed in Neovim 0.10 (#396)
})
if ok then
return data.str, data.highlights
Expand Down Expand Up @@ -357,7 +357,13 @@ local function copy_extmarks(bufnr, ctx_bufnr, contexts)
local offset = 0
for _, context in ipairs(contexts) do
local ctx_srow, ctx_scol, ctx_erow, ctx_ecol = context[1], context[2], context[3], context[4]
local extmarks = api.nvim_buf_get_extmarks(bufnr, -1, {ctx_srow, ctx_scol}, {ctx_erow, ctx_ecol}, { details = true })
local extmarks = api.nvim_buf_get_extmarks(
bufnr,
-1,
{ ctx_srow, ctx_scol },
{ ctx_erow, ctx_ecol },
{ details = true }
)

for _, m in ipairs(extmarks) do
--- @type integer, integer, integer, vim.api.keyset.extmark_details
Expand Down
1 change: 0 additions & 1 deletion lua/treesitter-context/util.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

local M = {}

--- @param r Range4
Expand Down
14 changes: 2 additions & 12 deletions test/test_file.lua
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
local function foo()
local function bar() end

local function bar()



end

local function baz()



end

local function baz() end
end
Loading

0 comments on commit 9634e57

Please sign in to comment.