diff --git a/.emmyrc.json b/.emmyrc.json new file mode 100644 index 0000000..4825843 --- /dev/null +++ b/.emmyrc.json @@ -0,0 +1,22 @@ +{ + "$schema": "https://raw.githubusercontent.com/EmmyLuaLs/emmylua-analyzer-rust/refs/heads/main/crates/emmylua_code_analysis/resources/schema.json", + "diagnostics": { + "disable": [ + "access-invisible", + "redefined-local" + ] + }, + "runtime": { + "version": "LuaJIT" + }, + "workspace": { + "ignoreDir": [ + ".prefix" + ], + "library": [ + "$VIMRUNTIME", + "library/busted", + "library/luv" + ] + } +} diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 55d9ab4..1690690 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -1,29 +1,52 @@ # yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json -name: NeoVim tests -on: [push] +name: ci + +on: + workflow_dispatch: + pull_request: + push: + tags: ["*"] + branches: ["*"] + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +env: + MISE_EXPERIMENTAL: true + jobs: - code-quality: + ci: runs-on: ubuntu-latest - env: - XDG_CONFIG_HOME: ${{ github.workspace }}/.config/ + timeout-minutes: 10 steps: - uses: actions/checkout@v4 - - uses: cachix/install-nix-action@v31 - with: - nix_path: nixpkgs=channel:nixos-unstable - - name: Populate Nix store - run: - nix-shell --pure --run 'true' + - name: Setup environment + run: | + if [ -n "${{secrets.TOKEN}}" ]; then + export GITHUB_TOKEN="${{secrets.TOKEN}}" + fi + export MISE_GITHUB_TOKEN="$GITHUB_TOKEN" + echo "$GITHUB_TOKEN" >> $GITHUB_ENV + echo "$MISE_GITHUB_TOKEN" >> $GITHUB_ENV - - name: Type-check with lua-language-server - run: - nix-shell --pure --run 'make lint' + - name: Install mise + run: | + curl https://mise.run | sh + echo "$HOME/.local/bin" >> $GITHUB_PATH + echo "$HOME/.local/share/mise/bin" >> $GITHUB_PATH + echo "$HOME/.local/share/mise/shims" >> $GITHUB_PATH + mise use -g rust@1.92.0 - - name: Check formatting with stylua - run: - nix-shell --pure --run 'make fmt-check' + - name: Install mise dependencies + run: mise install - - name: Run busted tests - run: - nix-shell --pure --run 'make test' + - name: Check Lua formatting + run: mise run fmt:check + + - name: Lint with emmylua_check + run: mise run lint + + - name: Run tests + run: mise run test:all diff --git a/.gitignore b/.gitignore index 202f9f8..6eac4e6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +.prefix/ *.src.rock *.aider* luacov.*.out diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..072ad6f --- /dev/null +++ b/.gitmodules @@ -0,0 +1,12 @@ +[submodule "library/busted"] + path = library/busted + url = https://github.com/LuaCATS/busted + branch = main +[submodule "library/luv"] + path = library/luv + url = https://github.com/LuaCATS/luv + branch = main +[submodule "nvimv"] + path = nvimv + url = https://github.com/jrop/nvimv + branch = main diff --git a/.luarc.json b/.luarc.json new file mode 100644 index 0000000..a659baf --- /dev/null +++ b/.luarc.json @@ -0,0 +1,16 @@ +{ + "$schema": "https://raw.githubusercontent.com/LuaLS/vscode-lua/refs/heads/master/setting/schema.json", + "runtime": { + "version": "LuaJIT" + }, + "workspace": { + "ignoreDir": [ + ".prefix" + ], + "library": [ + "$VIMRUNTIME", + "library/busted", + "library/luv" + ] + } +} diff --git a/.styluaignore b/.styluaignore new file mode 100644 index 0000000..69fb129 --- /dev/null +++ b/.styluaignore @@ -0,0 +1 @@ +library/ diff --git a/Makefile b/Makefile deleted file mode 100644 index 4e5b84f..0000000 --- a/Makefile +++ /dev/null @@ -1,24 +0,0 @@ -all: lint fmt-check test - -lint: - @echo "## Typechecking" - @lua-language-server --check=lua/u/ --checklevel=Error - -fmt-check: - @echo "## Checking code format" - @stylua --check . - -fmt: - @echo "## Formatting code" - @stylua . - -test: - @rm -f luacov.*.out - @echo "## Running tests" - @busted --coverage --verbose - @echo "## Generating coverage report" - @luacov - @awk '/^Summary$$/{flag=1;next} flag{print}' luacov.report.out - -watch: - @watchexec -c -e lua make diff --git a/library/busted b/library/busted new file mode 160000 index 0000000..5ed85d0 --- /dev/null +++ b/library/busted @@ -0,0 +1 @@ +Subproject commit 5ed85d0e016a5eb5eca097aa52905eedf1b180f1 diff --git a/library/luv b/library/luv new file mode 160000 index 0000000..3615eb1 --- /dev/null +++ b/library/luv @@ -0,0 +1 @@ +Subproject commit 3615eb12c94a7cfa7184b8488cf908abb5e94c9c diff --git a/mise.toml b/mise.toml new file mode 100644 index 0000000..06c4aba --- /dev/null +++ b/mise.toml @@ -0,0 +1,112 @@ +################################################################################ +## Tool Alias +################################################################################ + +[tool_alias] +gh_emmylua_check = "github:EmmyLuaLs/emmylua-analyzer-rust" + +################################################################################ +## Tools +################################################################################ + +[tools] +jq = "1.8.1" +lua = "5.1.5" +neovim = "0.11.5" +stylua = "2.3.1" + +[tools.gh_emmylua_check] +version = "0.19.0" +[tools.gh_emmylua_check.platforms] +linux-x64 = { asset_pattern = "*_check-linux-x64*" } +macos-x64 = { asset_pattern = "*_check-darwin-x64*" } +macos-arm64 = { asset_pattern = "*_check-darwin-arm64*" } + +################################################################################ +# Env +################################################################################ + +[env] +ASDF_LUA_LUAROCKS_VERSION = "3.12.2" +_.source = { path = "./scripts/env.sh", tools = true } + +################################################################################ +# Tasks +################################################################################ + +[tasks] +lint = "emmylua_check --ignore '.prefix/**/*.*' ." +fmt = "stylua ." +"fmt:check" = "stylua --check ." + +[tasks.test] +run = 'mise test:version 0.11.5' + +[tasks."test:version:no-prep"] +hide = true +usage = ''' +arg "" help="The version of Neovim to test with" +''' +run = ''' +echo +echo ----------------------------- +echo ----------------------------- +echo Neovim version=$usage_version +echo ----------------------------- +echo ----------------------------- +echo +./nvimv/nvimv install $usage_version +eval $(./nvimv/nvimv env $usage_version) +busted --verbose +''' + +[tasks."test:version"] +depends = ["test:prepare"] +usage = ''' +arg "" help="The version of Neovim to test with" +''' +run = 'mise test:version:no-prep $usage_version' + +[tasks."test:prepare"] +run = ''' +# Install Lua test dependencies (busted, etc.): +luarocks test --prepare +echo + +# Check that the nightly version of Neovim is not more than a day old: +if find .prefix -path '**/nightly/**/nvim' -mtime -1 2>/dev/null | grep -q .; then + echo "Neovim Nightly is up-to-date" +else + if ./nvimv/nvimv ls | grep nightly >/dev/null; then + ./nvimv/nvimv upgrade nightly + else + ./nvimv/nvimv install nightly + fi +fi +echo +''' + +[tasks."test:all"] +depends = ["test:prepare"] +run = ''' +VERSIONS="0.11.5 nightly" +for v in $VERSIONS; do + mise test:version:no-prep $v +done +''' + +[tasks."test:coverage"] +depends = ["test:prepare"] +run = ''' +rm -f ./luacov.*.* +busted --coverage --verbose +luacov +awk '/^Summary$/{flag=1;next} flag{print}' luacov.report.out +''' + +[tasks.ci] +run = ''' +mise run fmt:check +mise run lint +mise run test:all +''' diff --git a/nvimv b/nvimv new file mode 160000 index 0000000..bd5c243 --- /dev/null +++ b/nvimv @@ -0,0 +1 @@ +Subproject commit bd5c243b9606a93ec7034a9a8cbd5671951b90ff diff --git a/scripts/env.sh b/scripts/env.sh new file mode 100644 index 0000000..85e0f19 --- /dev/null +++ b/scripts/env.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash + +export PREFIX="$(pwd)/.prefix" +export VIMRUNTIME="$(nvim -u NORC --headless +'echo $VIMRUNTIME' +'quitall' 2>&1)" + +eval $(luarocks path) diff --git a/spec/buffer_spec.lua b/spec/buffer_spec.lua index f54129e..e47bb45 100644 --- a/spec/buffer_spec.lua +++ b/spec/buffer_spec.lua @@ -1,3 +1,4 @@ +--- @diagnostic disable: undefined-field local Buffer = require 'u.buffer' local withbuf = loadfile './spec/withbuf.lua'() diff --git a/spec/codewriter_spec.lua b/spec/codewriter_spec.lua index c4596de..fb4ecbb 100644 --- a/spec/codewriter_spec.lua +++ b/spec/codewriter_spec.lua @@ -1,3 +1,4 @@ +--- @diagnostic disable: undefined-field local CodeWriter = require 'u.codewriter' describe('CodeWriter', function() diff --git a/spec/pos_spec.lua b/spec/pos_spec.lua index 8420311..e2ca561 100644 --- a/spec/pos_spec.lua +++ b/spec/pos_spec.lua @@ -1,3 +1,4 @@ +--- @diagnostic disable: undefined-field local Pos = require 'u.pos' local withbuf = loadfile './spec/withbuf.lua'() diff --git a/u-0.0.0-0.rockspec b/u-0.0.0-0.rockspec new file mode 100644 index 0000000..29f673b --- /dev/null +++ b/u-0.0.0-0.rockspec @@ -0,0 +1,16 @@ +rockspec_format = '3.0' +package = 'u' +version = '0.0.0-0' + +source = { + url = 'https://github.com/jrop/u.nvim', +} + +dependencies = { + 'lua = 5.1', +} + +test_dependencies = { + 'busted == 2.2.0-1', + 'luacov == 0.16.0-1', +}