Skip to content

Commit

Permalink
chore(commons): upgrade 'commons' (#32)
Browse files Browse the repository at this point in the history
perf(disabled): allow disable specific filenames/filetypes/workspaces (#32)
  • Loading branch information
linrongbin16 committed Mar 6, 2024
1 parent c786cf1 commit e9b0096
Show file tree
Hide file tree
Showing 38 changed files with 3,033 additions and 776 deletions.
45 changes: 19 additions & 26 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,52 +10,46 @@ concurrency:
group: ${{ github.ref }}-ci
cancel-in-progress: true
jobs:
pr_conventional_commit:
name: PR Conventional Commit
commit:
name: Commit
if: ${{ github.ref != 'refs/heads/main' }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- uses: ytanikin/PRConventionalCommits@1.1.0
with:
task_types: '["feat","fix","docs","test","ci","refactor","perf","chore","revert","break"]'
luacheck:
name: Lua Check
- uses: actions/checkout@v4
- uses: amannn/action-semantic-pull-request@v5
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- uses: actions/checkout@v4
- name: Install commons.nvim
if: ${{ github.ref != 'refs/heads/main' }}
shell: bash
run: |
git clone --depth=1 https://github.com/linrongbin16/commons.nvim.git ~/.commons.nvim
rm -rf ./lua/gentags/commons
mkdir -p ./lua/gentags/commons
cp -rf ~/.commons.nvim/lua/commons/*.lua ./lua/gentags/commons
cp -rf ~/.commons.nvim/lua/commons ./lua/gentags/
cp ~/.commons.nvim/version.txt ./lua/gentags/commons/version.txt
cd ./lua/gentags/commons
find . -type f -name '*.lua' -exec sed -i 's/require("commons/require("gentags.commons/g' {} \;
- name: Luacheck
uses: lunarmodules/luacheck@v1
with:
args: lua --config .luacheckrc
- name: Stylua
uses: JohnnyMorganz/stylua-action@v3
find ./lua/gentags/commons -type f -name '*.lua' -exec sed -i 's/require("commons./require("gentags.commons./g' {} \;
- uses: cargo-bins/cargo-binstall@main
- name: Selene
run: |
cargo binstall --no-confirm selene
selene --config selene.toml ./lua
- uses: JohnnyMorganz/stylua-action@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
version: latest
args: --config-path .stylua.toml ./lua ./test
- name: Auto Commit
- uses: stefanzweifel/git-auto-commit-action@v4
if: ${{ github.ref != 'refs/heads/main' }}
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: "chore(pr): auto-commit"
unit_test:
name: Unit Test
needs:
- luacheck
- lint
strategy:
matrix:
nvim_version: [stable, nightly, v0.7.0]
Expand All @@ -78,7 +72,6 @@ jobs:
- name: Run test cases
shell: bash
run: |
luarocks install luacheck
luarocks install luacov
luarocks install cluacov
luarocks install vusted
Expand Down
4 changes: 0 additions & 4 deletions .luacheckrc

This file was deleted.

2 changes: 2 additions & 0 deletions .luacov
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ modules = {

exclude = {
"lua/gentags/commons/*.lua",
"lua/gentags/commons/*/*.lua",
"lua/gentags/commons/*/*/*.lua",
}
18 changes: 8 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,19 @@

# gentags.nvim

<p align="center">
<a href="https://github.com/neovim/neovim/releases/v0.7.0"><img alt="Neovim" src="https://img.shields.io/badge/Neovim-v0.7+-57A143?logo=neovim&logoColor=57A143" /></a>
<a href="https://github.com/linrongbin16/commons.nvim"><img alt="commons.nvim" src="https://custom-icon-badges.demolab.com/badge/Powered_by-commons.nvim-teal?logo=heart&logoColor=fff&labelColor=deeppink" /></a>
<a href="https://luarocks.org/modules/linrongbin16/gentags.nvim"><img alt="luarocks" src="https://custom-icon-badges.demolab.com/luarocks/v/linrongbin16/gentags.nvim?label=LuaRocks&labelColor=063B70&logo=tag&logoColor=fff&color=blue" /></a>
<a href="https://github.com/linrongbin16/gentags.nvim/actions/workflows/ci.yml"><img alt="ci.yml" src="https://img.shields.io/github/actions/workflow/status/linrongbin16/gentags.nvim/ci.yml?label=GitHub%20CI&labelColor=181717&logo=github&logoColor=fff" /></a>
<a href="https://app.codecov.io/github/linrongbin16/gentags.nvim"><img alt="codecov" src="https://img.shields.io/codecov/c/github/linrongbin16/gentags.nvim?logo=codecov&logoColor=F01F7A&label=Codecov" /></a>
<p align="left">
<a href="https://github.com/neovim/neovim/releases/v0.7.0"><img alt="require" src="https://img.shields.io/badge/require-0.7%2B-blue" /></a>
<a href="https://github.com/linrongbin16/commons.nvim"><img alt="commons.nvim" src="https://img.shields.io/badge/power_by-commons.nvim-pink" /></a>
<a href="https://luarocks.org/modules/linrongbin16/gentags.nvim"><img alt="luarocks" src="https://img.shields.io/luarocks/v/linrongbin16/gentags.nvim" /></a>
<a href="https://github.com/linrongbin16/gentags.nvim/actions/workflows/ci.yml"><img alt="ci.yml" src="https://img.shields.io/github/actions/workflow/status/linrongbin16/gentags.nvim/ci.yml?label=ci" /></a>
<a href="https://app.codecov.io/github/linrongbin16/gentags.nvim"><img alt="codecov" src="https://img.shields.io/codecov/c/github/linrongbin16/gentags.nvim/main?label=codecov" /></a>
</p>

<p align="center"><i>
Tags generator/management for old school vimers in Neovim.
</i></p>

To be honest, it seems that tags have become useless in Neovim today, LSP and treesitter replaced tags and make (Neo)vim a modern editor.

While there exists gap when LSP server or treesitter implementations are insufficient, which brings tags back to us as a supplement to fill the gap.
To be honest, it seems that tags have become useless in Neovim today, LSP and treesitter replaced tags and make (Neo)vim a modern editor. While there exists gap when LSP server or treesitter implementations are insufficient, which brings tags back to us as a supplement to fill the gap.

## Table of Contents

Expand All @@ -41,7 +39,7 @@ While there exists gap when LSP server or treesitter implementations are insuffi

## Requirements

- Neovim &ge; 0.7.0.
- Neovim &ge; 0.7.
- [universal-ctags](https://github.com/universal-ctags/ctags) (default backend).

PRs are welcome to add other backends.
Expand Down
2 changes: 2 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ coverage:
threshold: 90%
ignore:
- "lua/gentags/commons/*.lua"
- "lua/gentags/commons/*/*.lua"
- "lua/gentags/commons/*/*.lua"
14 changes: 10 additions & 4 deletions lua/gentags.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ M.setup = function(opts)
file_log = cfg.debug.file_log,
file_log_name = "gentags.log",
})
local logger = logging.get("gentags") --[[@as commons.logging.Logger]]
local logger = logging.get("gentags")

-- cache dir
logger:ensure(
Expand All @@ -36,8 +36,11 @@ M.setup = function(opts)
logging
.get("gentags")
:debug("|setup| enter buffer:%s", vim.inspect(event))
require("gentags.dispatcher").load()
require("gentags.dispatcher").init()
local dispatcher = require("gentags.dispatcher")
if dispatcher.enabled() then
dispatcher.load()
dispatcher.init()
end
end,
})

Expand All @@ -51,7 +54,10 @@ M.setup = function(opts)
logging
.get("gentags")
:debug("|setup| write buffer:%s", vim.inspect(event))
require("gentags.dispatcher").update()
local dispatcher = require("gentags.dispatcher")
if dispatcher.enabled() then
dispatcher.update()
end
end,
})

Expand Down
12 changes: 6 additions & 6 deletions lua/gentags/commons/_system.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
local uv = vim.uv or vim.loop

--- @class SystemOpts
--- @class vim.SystemOpts
--- @field stdin? string|string[]|true
--- @field stdout? fun(err:string?, data: string?)|false
--- @field stderr? fun(err:string?, data: string?)|false
Expand Down Expand Up @@ -61,7 +61,7 @@ end
--- @field wait fun(self: vim.SystemObj, timeout?: integer): vim.SystemCompleted
--- @field kill fun(self: vim.SystemObj, signal: integer|string)
--- @field write fun(self: vim.SystemObj, data?: string|string[])
--- @field is_closing fun(self: vim.SystemObj): boolean?
--- @field is_closing fun(self: vim.SystemObj): boolean
local SystemObj = {}

--- @param state vim.SystemState
Expand Down Expand Up @@ -94,14 +94,14 @@ function SystemObj:wait(timeout)

local done = vim.wait(timeout or state.timeout or MAX_TIMEOUT, function()
return state.result ~= nil
end)
end, nil, true)

if not done then
-- Send sigkill since this cannot be caught
self:_timeout(SIG.KILL)
vim.wait(timeout or state.timeout or MAX_TIMEOUT, function()
return state.result ~= nil
end)
end, nil, true)
end

return state.result
Expand Down Expand Up @@ -140,7 +140,7 @@ end
--- @return boolean
function SystemObj:is_closing()
local handle = self._state.handle
return handle == nil or handle:is_closing()
return handle == nil or handle:is_closing() or false
end

---@param output fun(err:string?, data: string?)|false
Expand Down Expand Up @@ -302,7 +302,7 @@ end
--- Run a system command
---
--- @param cmd string[]
--- @param opts? SystemOpts
--- @param opts? vim.SystemOpts
--- @param on_exit? fun(out: vim.SystemCompleted)
--- @return vim.SystemObj
function M.run(cmd, opts, on_exit)
Expand Down
114 changes: 114 additions & 0 deletions lua/gentags/commons/api.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
local NVIM_VERSION_0_8 = false
local NVIM_VERSION_0_9 = false

do
NVIM_VERSION_0_8 = require("gentags.commons.version").ge({ 0, 8 })
NVIM_VERSION_0_9 = require("gentags.commons.version").ge({ 0, 9 })
end

local M = {}

-- buffer {

--- @param bufnr integer
--- @param name string
--- @return any
M.get_buf_option = function(bufnr, name)
if NVIM_VERSION_0_8 then
return vim.api.nvim_get_option_value(name, { buf = bufnr })
else
return vim.api.nvim_buf_get_option(bufnr, name)
end
end

--- @param bufnr integer
--- @param name string
--- @param value any
M.set_buf_option = function(bufnr, name, value)
if NVIM_VERSION_0_8 then
return vim.api.nvim_set_option_value(name, value, { buf = bufnr })
else
return vim.api.nvim_buf_set_option(bufnr, name, value)
end
end

-- buffer }

-- window {

--- @param winnr integer
--- @param name string
--- @return any
M.get_win_option = function(winnr, name)
if NVIM_VERSION_0_8 then
return vim.api.nvim_get_option_value(name, { win = winnr })
else
return vim.api.nvim_win_get_option(winnr, name)
end
end

--- @param winnr integer
--- @param name string
--- @param value any
--- @return any
M.set_win_option = function(winnr, name, value)
if NVIM_VERSION_0_8 then
return vim.api.nvim_set_option_value(name, value, { win = winnr })
else
return vim.api.nvim_win_set_option(winnr, name, value)
end
end

-- window }

-- highlight {

--- @param hl string
--- @return {fg:integer?,bg:integer?,[string]:any,ctermfg:integer?,ctermbg:integer?,cterm:{fg:integer?,bg:integer?,[string]:any}?}
M.get_hl = function(hl)
if NVIM_VERSION_0_9 then
return vim.api.nvim_get_hl(0, { name = hl, link = false })
else
---@diagnostic disable-next-line: undefined-field
local ok1, rgb_value = pcall(vim.api.nvim_get_hl_by_name, hl, true)
if not ok1 then
return vim.empty_dict()
end
---@diagnostic disable-next-line: undefined-field
local ok2, cterm_value = pcall(vim.api.nvim_get_hl_by_name, hl, false)
if not ok2 then
return vim.empty_dict()
end
local result = vim.tbl_deep_extend("force", rgb_value, {
ctermfg = cterm_value.foreground,
ctermbg = cterm_value.background,
cterm = cterm_value,
})
result.fg = result.foreground
result.bg = result.background
result.sp = result.special
result.cterm.fg = result.cterm.foreground
result.cterm.bg = result.cterm.background
result.cterm.sp = result.cterm.special
return result
end
end

--- @param ... string?
--- @return {fg:integer?,bg:integer?,[string]:any,ctermfg:integer?,ctermbg:integer?,cterm:{fg:integer?,bg:integer?,[string]:any}?}, integer, string?
M.get_hl_with_fallback = function(...)
for i, hl in ipairs({ ... }) do
if type(hl) == "string" then
local hl_value = M.get_hl(hl)
if type(hl_value) == "table" and not vim.tbl_isempty(hl_value) then
return hl_value, i, hl
end
end
end

return vim.empty_dict(), -1, nil
end

-- highlight }

return M
56 changes: 0 additions & 56 deletions lua/gentags/commons/apis.lua

This file was deleted.

Loading

0 comments on commit e9b0096

Please sign in to comment.