diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..7dbe2b3 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,45 @@ +name: Tests + +on: [push, pull_request] + +jobs: + unit_tests: + name: unit tests + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + include: + - os: ubuntu-22.04 + rev: nightly/nvim-linux64.tar.gz + - os: ubuntu-22.04 + rev: v0.9.0/nvim-linux64.tar.gz + steps: + - uses: actions/checkout@v4 + - uses: extractions/setup-just@v2 + - run: date +%F > todays-date + - name: Restore from todays cache + uses: actions/cache@v3 + with: + path: _neovim + key: ${{ runner.os }}-${{ matrix.rev }}-${{ hashFiles('todays-date') }} + + - name: Prepare + run: | + test -d _neovim || { + mkdir -p _neovim + curl -sL "https://github.com/neovim/neovim/releases/download/${{ matrix.rev }}" | tar xzf - --strip-components=1 -C "${PWD}/_neovim" + } + - name: Dependencies + run: | + git clone --depth 1 https://github.com/nvim-lua/plenary.nvim ~/.local/share/nvim/site/pack/vendor/start/plenary.nvim + git clone --depth 1 https://github.com/nvim-treesitter/nvim-treesitter ~/.local/share/nvim/site/pack/vendor/start/nvim-treesitter + git clone --depth 1 https://github.com/hrsh7th/nvim-cmp ~/.local/share/nvim/site/pack/vendor/start/nvim-cmp + git clone --depth 1 https://github.com/L3MON4D3/LuaSnip ~/.local/share/nvim/site/pack/vendor/start/LuaSnip + + ln -s "$(pwd)" ~/.local/share/nvim/site/pack/vendor/start + - name: Run tests + run: | + export PATH="${PWD}/_neovim/bin:${PATH}" + nvim --version + just test diff --git a/.github/workflows/format.yml b/.github/workflows/format.yml new file mode 100644 index 0000000..3939457 --- /dev/null +++ b/.github/workflows/format.yml @@ -0,0 +1,26 @@ +name: Format + +on: [push, pull_request] + +jobs: + format: + name: Stylua + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - run: date +%W > weekly + + - name: Restore cache + id: cache + uses: actions/cache@v2 + with: + path: | + ~/.cargo/bin + key: ${{ runner.os }}-cargo-${{ hashFiles('weekly') }} + + - name: Install + if: steps.cache.outputs.cache-hit != 'true' + run: cargo install stylua + + - name: Format + run: stylua --check lua/ --config-path=stylua.toml diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..51fd4b6 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,17 @@ +name: Lint + +on: [push, pull_request] + +jobs: + lint: + name: Luacheck + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Setup + run: | + sudo apt-get update + sudo apt-get install luarocks -y + sudo luarocks install luacheck + - name: Lint + run: luacheck lua/ --globals vim diff --git a/lua/ledger/completion/cmp.lua b/lua/ledger/completion/cmp.lua index ea0b6aa..3739e71 100644 --- a/lua/ledger/completion/cmp.lua +++ b/lua/ledger/completion/cmp.lua @@ -24,7 +24,7 @@ function M.new() return setmetatable({}, LedgerCmp) end -function LedgerCmp:is_available() +function LedgerCmp.is_available() return common.is_available() end @@ -32,7 +32,7 @@ end --- specify --- ---@return string -function LedgerCmp:get_debug_name() +function LedgerCmp.get_debug_name() return "ledger.nvim" end diff --git a/lua/ledger/diagnostics.lua b/lua/ledger/diagnostics.lua index 8c75cae..40ac040 100644 --- a/lua/ledger/diagnostics.lua +++ b/lua/ledger/diagnostics.lua @@ -22,11 +22,9 @@ function M.get_missing_accounts() for filename, postings in pairs(context.postings) do for _, posting in pairs(postings) do local account_name = posting.account.text - local has_commodity = false for _, accounts in pairs(context.accounts) do - has_commodity = vim.tbl_contains(accounts, account_name) - if has_commodity then + if vim.tbl_contains(accounts, account_name) then goto continue end end @@ -63,11 +61,9 @@ function M.get_missing_commodities() end local commodity_name = posting.commodity.text - local has_commodity = false for _, commodities in pairs(context.commodities) do - has_commodity = vim.tbl_contains(commodities, commodity_name) - if has_commodity then + if vim.tbl_contains(commodities, commodity_name) then goto continue end end diff --git a/lua/ledger/logger.lua b/lua/ledger/logger.lua index 8f4303a..5abbcb1 100644 --- a/lua/ledger/logger.lua +++ b/lua/ledger/logger.lua @@ -43,26 +43,26 @@ end --- --- @param level string --- @return string -function LedgerLogger:get_prefix(level) +function LedgerLogger.get_prefix(level) local timestamp = os.date("%Y-%m-%d %H:%M:%S") return "[" .. timestamp .. "] " .. level .. " " end --- @param message string function LedgerLogger:info(message) - local prefix = self:get_prefix("[INFO]") + local prefix = self.get_prefix("[INFO]") self:log(prefix .. message .. "\n") end --- @param message string function LedgerLogger:error(message) - local prefix = self:get_prefix("[ERROR]") + local prefix = self.get_prefix("[ERROR]") self:log(prefix .. message .. "\n") end --- @param message string function LedgerLogger:warn(message) - local prefix = self:get_prefix("[WARN]") + local prefix = self.get_prefix("[WARN]") self:log(prefix .. message .. "\n") end diff --git a/lua/ledger/snippets/cmp.lua b/lua/ledger/snippets/cmp.lua index 20d5ebe..a50a393 100644 --- a/lua/ledger/snippets/cmp.lua +++ b/lua/ledger/snippets/cmp.lua @@ -3,9 +3,6 @@ local template_converter = require("ledger.snippets.template_converter") --- @class CmpSnippetCompletionSource local M = {} -local LedgerSnippetCmpSource = {} -LedgerSnippetCmpSource.__index = LedgerSnippetCmpSource - --- @param snippets ledger.SnippetList --- @return lsp.CompletionItem[] function M.new(snippets)