diff --git a/.emmyrc.json b/.emmyrc.json new file mode 100644 index 0000000000..34d1e0b860 --- /dev/null +++ b/.emmyrc.json @@ -0,0 +1,25 @@ +{ + "$schema": "https://raw.githubusercontent.com/EmmyLuaLs/emmylua-analyzer-rust/refs/heads/main/crates/emmylua_code_analysis/resources/schema.json", + "format": { + "externalTool": { + "program": "stylua", + "args": [ + "-", + "--stdin-filepath", + "${file}" + ] + } + }, + "diagnostics": { + "disable": [ + "unnecessary-if" + ] + }, + "codeAction": { + "insertSpace": true + }, + "strict": { + "typeCall": true, + "arrayIndex": true + } +} diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index c27c4defe2..fea8db3277 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -23,10 +23,10 @@ jobs: sudo luarocks install luacheck - name: Lint - run: sudo make lint + run: make lint stylua: - name: stylua + name: Stylua runs-on: ubuntu-latest steps: - uses: actions/checkout@v5 @@ -35,4 +35,12 @@ jobs: token: ${{ secrets.GITHUB_TOKEN }} version: latest # CLI arguments - args: --color always --check lua/ + args: --color always --check . + + luals: + name: Luals + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v5 + - run: make checklua + diff --git a/.luarc.json b/.luarc.json new file mode 100644 index 0000000000..6e6d42b4ff --- /dev/null +++ b/.luarc.json @@ -0,0 +1,27 @@ +{ + "$schema": "https://raw.githubusercontent.com/LuaLS/vscode-lua/master/setting/schema.json", + "runtime": { + "version": "LuaJIT" + }, + "workspace": { + "library": [ + "$VIMRUNTIME" + ], + "ignoreDir": [ + ".test-deps", + "lua/tests" + ], + "checkThirdParty": "Disable" + }, + "diagnostics": { + "groupFileStatus": { + "strict": "Opened", + "strong": "Opened" + }, + "groupSeverity": { + "strong": "Warning", + "strict": "Warning" + }, + "unusedLocalExclude": [ "_*" ] + } +} diff --git a/Makefile b/Makefile index e520d60749..7083d1bf62 100644 --- a/Makefile +++ b/Makefile @@ -1,10 +1,83 @@ -.PHONY: test lint docgen +NVIM_VERSION ?= nightly +LUALS_VERSION := 3.15.0 +DEPDIR ?= .test-deps +CURL ?= curl -sL --create-dirs + +ifeq ($(shell uname -s),Darwin) + NVIM_ARCH ?= macos-arm64 + LUALS_ARCH ?= darwin-arm64 + STYLUA_ARCH ?= macos-aarch64 +else + NVIM_ARCH ?= linux-x86_64 + LUALS_ARCH ?= linux-x64 + STYLUA_ARCH ?= linux-x86_64 +endif + +# download test dependencies + +NVIM := $(DEPDIR)/nvim-$(NVIM_ARCH) +NVIM_TARBALL := $(NVIM).tar.gz +NVIM_URL := https://github.com/neovim/neovim/releases/download/$(NVIM_VERSION)/$(notdir $(NVIM_TARBALL)) +NVIM_BIN := $(NVIM)/nvim-$(NVIM_ARCH)/bin/nvim +NVIM_RUNTIME=$(NVIM)/nvim-$(NVIM_ARCH)/share/nvim/runtime + +.PHONY: nvim +nvim: $(NVIM) + +$(NVIM): + $(CURL) $(NVIM_URL) -o $(NVIM_TARBALL) + mkdir $@ + tar -xf $(NVIM_TARBALL) -C $@ + rm -rf $(NVIM_TARBALL) + +LUALS := $(DEPDIR)/lua-language-server-$(LUALS_VERSION)-$(LUALS_ARCH) +LUALS_TARBALL := $(LUALS).tar.gz +LUALS_URL := https://github.com/LuaLS/lua-language-server/releases/download/$(LUALS_VERSION)/$(notdir $(LUALS_TARBALL)) + +.PHONY: luals +luals: $(LUALS) + +$(LUALS): + $(CURL) $(LUALS_URL) -o $(LUALS_TARBALL) + mkdir $@ + tar -xf $(LUALS_TARBALL) -C $@ + rm -rf $(LUALS_TARBALL) + +STYLUA := $(DEPDIR)/stylua-$(STYLUA_ARCH) +STYLUA_TARBALL := $(STYLUA).zip +STYLUA_URL := https://github.com/JohnnyMorganz/StyLua/releases/latest/download/$(notdir $(STYLUA_TARBALL)) + +.PHONY: stylua +stylua: $(STYLUA) + +$(STYLUA): + $(CURL) $(STYLUA_URL) -o $(STYLUA_TARBALL) + unzip $(STYLUA_TARBALL) -d $(STYLUA) + rm -rf $(STYLUA_TARBALL) + +.PHONY: formatlua +formatlua: $(STYLUA) + $(STYLUA)/stylua . + +.PHONY: checklua +checklua: $(LUALS) $(NVIM) + VIMRUNTIME=$(NVIM_RUNTIME) $(LUALS)/bin/lua-language-server \ + --configpath=../.luarc.json \ + --check=./ + +.PHONY: test test: nvim --headless --noplugin -u scripts/minimal_init.vim -c "PlenaryBustedDirectory lua/tests/automated/ { minimal_init = './scripts/minimal_init.vim' }" -lint: +.PHONY: lint +luacheck: luacheck lua/telescope +.PHONY: docgen docgen: nvim --headless --noplugin -u scripts/minimal_init.vim -c "luafile ./scripts/gendocs.lua" -c 'qa' + +.PHONY: clean +clean: + rm -rf $(DEPDIR)