From edf5110cc57c0c6e4d3435e340f465ab8d8bf1ee Mon Sep 17 00:00:00 2001 From: fidgetingbits Date: Tue, 30 Jul 2024 17:21:02 +0800 Subject: [PATCH 1/8] feat: Add lua-language-server to pre-commit hooks - Implement lua-language-server linter in pre-commit - Install via Nix due to lack of Ubuntu package - Apply patch for --check CLI bug using Nix overlay - Centralize linting config for VSCode, pre-commit, and CI Fixes #2576 --- .github/workflows/pre-commit.yml | 9 +++++++ .luarc.json | 6 +++++ .pre-commit-config.yaml | 8 ++++++ .vscode/settings.json | 4 --- flake.nix | 27 ++++++++++++++++++-- scripts/lint-lua.sh | 42 ++++++++++++++++++++++++++++++++ 6 files changed, 90 insertions(+), 6 deletions(-) create mode 100644 .luarc.json create mode 100755 scripts/lint-lua.sh diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index daa024e3ce..44e7ef9f0b 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -8,11 +8,14 @@ on: types: [opened, synchronize, reopened] merge_group: branches: [main] + workflow_dispatch: jobs: pre-commit: name: Pre-commit runs-on: ubuntu-latest + env: + CURSORLESS_REPO_ROOT: ${{ github.workspace }} steps: - uses: actions/checkout@v4 - uses: actions/setup-python@v5 @@ -26,6 +29,12 @@ jobs: - run: pnpm --color install - uses: leafo/gh-actions-lua@v9 - uses: leafo/gh-actions-luarocks@v4 + - uses: cachix/install-nix-action@v27 + with: + nix_path: nixpkgs=channel:nixos-unstable + - uses: DeterminateSystems/magic-nix-cache-action@v2 + - run: nix profile install --accept-flake-config .#lua-language-server + shell: bash - uses: pre-commit/action@v3.0.1 - uses: pre-commit-ci/lite-action@v1.0.2 if: always() diff --git a/.luarc.json b/.luarc.json new file mode 100644 index 0000000000..4565a7e0e4 --- /dev/null +++ b/.luarc.json @@ -0,0 +1,6 @@ +{ + "runtime.version": "Lua 5.1", + "diagnostics.ignoredFiles": "Disable", + "diagnostics.globals": ["vim", "talon", "it", "describe"], + "workspace.ignoreDir": ["data/playground/lua/", ".luarocks"] +} diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 429892ecdf..33c9638247 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -91,3 +91,11 @@ repos: hooks: - id: stylua exclude: ^data/playground/lua/.*\.lua$ + - repo: local + hooks: + - id: lua-language-server + name: lua-language-server + files: \.(lua|busted)$ + entry: scripts/lint-lua.sh + language: script + pass_filenames: false diff --git a/.vscode/settings.json b/.vscode/settings.json index 7922d2b067..c5ff74b927 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -26,10 +26,6 @@ "typescript.enablePromptUseWorkspaceTsdk": true, "typescript.tsdk": "node_modules/typescript/lib", "eslint.workingDirectories": [{ "pattern": "packages/*/" }], - "Lua.runtime.version": "Lua 5.1", - "Lua.diagnostics.globals": ["vim", "talon", "it", "describe"], - "Lua.diagnostics.ignoredFiles": "Disable", - "Lua.workspace.ignoreDir": ["data/playground/lua/"], "[lua]": { "editor.defaultFormatter": "JohnnyMorganz.stylua" }, diff --git a/flake.nix b/flake.nix index 0b53089e89..29fbef70c9 100644 --- a/flake.nix +++ b/flake.nix @@ -22,6 +22,7 @@ pkgs = import nixpkgs { inherit system; overlays = [ + # Updated neovim-node-client is pending merge: # https://github.com/NixOS/nixpkgs/pull/317333 (final: prev: { nodePackages = prev.nodePackages // { @@ -45,7 +46,21 @@ }; }; neovim = prev.neovim.override { withNodeJs = true; }; - + # There is a recent bug that prevents cli --check invocation: + # See: https://github.com/LuaLS/lua-language-server/pull/2775 + lua-language-server = prev.lua-language-server.overrideAttrs { + postPatch = + let + patch = prev.fetchurl { + url = "https://github.com/LuaLS/lua-language-server/pull/2775.patch"; + sha256 = "sha256-5hjuNzBHLp9kiD6O8jTL5YlvaqR8IuJPHchIZE2/p/Q="; + }; + in + '' + patch -p1 < ${patch} + '' + + prev.lua-language-server.postPatch; + }; }) ]; @@ -57,6 +72,12 @@ ] (nixpkgs.lib.importTOML ./pyproject.toml).tool.ruff.target-version; in { + packages = forEachSupportedSystem ( + { pkgs }: + { + lua-language-server = pkgs.lua-language-server; + } + ); devShells = forEachSupportedSystem ( { pkgs }: { @@ -69,6 +90,8 @@ [ pkgs.corepack pkgs.vsce + pkgs.nodejs + # https://github.com/NixOS/nixpkgs/pull/251418 (pkgs.pre-commit.overrideAttrs (previousAttrs: { makeWrapperArgs = '' @@ -76,12 +99,12 @@ ''; })) python + pkgs.lua-language-server # language server used by pre-commit hooks pkgs.neovim pkgs.luajitPackages.busted # for lua testing pkgs.luarocks # pre-commit doesn't auto-install luarocks pkgs.ps - pkgs.nodejs ]; # To prevent weird broken non-interactive bash terminal buildInputs = [ pkgs.bashInteractive ]; diff --git a/scripts/lint-lua.sh b/scripts/lint-lua.sh new file mode 100755 index 0000000000..68ca47da50 --- /dev/null +++ b/scripts/lint-lua.sh @@ -0,0 +1,42 @@ +#!/usr/bin/env bash +set -euo pipefail + +# lua-language-server should be installed automatically by the flake.nix dev shell +# or .github/workflows/pre-commit.yml +if ! type lua-language-server &>/dev/null; then + echo "ERROR: lua-language-server is not installed. Please run 'nix develop' or install it manually." + exit 1 +fi + +if [ ! -e "${CURSORLESS_REPO_ROOT-nonexistent}" ]; then + CURSORLESS_REPO_ROOT=$(git rev-parse --show-toplevel) +fi + +function check_file() { + local file="$1" + logpath="$(mktemp -d)" + rm -rf "$logpath/check.json" + result=$(lua-language-server --check "$file" \ + --checklevel="Warning" \ + --configpath="${CURSORLESS_REPO_ROOT}/.luarc.json" \ + --logpath="$logpath") + if [[ ! "$result" == *"no problems found"* ]]; then + if [ -e "$logpath/check.json" ]; then + cat "$logpath/check.json" + else + echo "ERROR: lua-language-server failed to run." + echo "$result" + fi + return 1 + + fi + return 0 +} + +# lua-language-server doesn't support single file parsing, so check entire folder +exit_code=0 +if ! check_file .; then + exit_code=1 +fi + +exit $exit_code From 52d143d1db1aad380023ca37e7789b9ef3004d91 Mon Sep 17 00:00:00 2001 From: fidgetingbits Date: Wed, 31 Jul 2024 20:52:22 +0800 Subject: [PATCH 2/8] Address feedback --- .github/actions/lint-lua-ls/action.yml | 13 +++++++++++++ .github/workflows/pre-commit.yml | 6 ------ .github/workflows/test.yml | 2 ++ .pre-commit-config.yaml | 8 -------- scripts/{lint-lua.sh => lint-lua-ls.sh} | 0 5 files changed, 15 insertions(+), 14 deletions(-) create mode 100644 .github/actions/lint-lua-ls/action.yml rename scripts/{lint-lua.sh => lint-lua-ls.sh} (100%) diff --git a/.github/actions/lint-lua-ls/action.yml b/.github/actions/lint-lua-ls/action.yml new file mode 100644 index 0000000000..58a98e16a6 --- /dev/null +++ b/.github/actions/lint-lua-ls/action.yml @@ -0,0 +1,13 @@ +name: "Lua Language Server Lint" +description: "Lints all lua files with lua-language-server" +runs: + using: "composite" + steps: + - uses: cachix/install-nix-action@v27 + with: + nix_path: nixpkgs=channel:nixos-unstable + - uses: DeterminateSystems/magic-nix-cache-action@v2 + - run: nix profile install --accept-flake-config .#lua-language-server + shell: bash + - run: scripts/lint-lua-ls.sh + shell: bash diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index 44e7ef9f0b..42e589bc2d 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -29,12 +29,6 @@ jobs: - run: pnpm --color install - uses: leafo/gh-actions-lua@v9 - uses: leafo/gh-actions-luarocks@v4 - - uses: cachix/install-nix-action@v27 - with: - nix_path: nixpkgs=channel:nixos-unstable - - uses: DeterminateSystems/magic-nix-cache-action@v2 - - run: nix profile install --accept-flake-config .#lua-language-server - shell: bash - uses: pre-commit/action@v3.0.1 - uses: pre-commit-ci/lite-action@v1.0.2 if: always() diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 2f3b14fbed..62c323d9e6 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -66,6 +66,8 @@ jobs: NEOVIM_PATH: ${{ steps.vim.outputs.executable }} - uses: ./.github/actions/test-neovim-lua/ if: runner.os == 'Linux' && matrix.app_version == 'stable' + - uses: ./.github/actions/lint-lua-ls/ + if: runner.os == 'Linux' && matrix.app_version == 'stable' - name: Create vscode dist that can be installed locally run: pnpm -F @cursorless/cursorless-vscode populate-dist --local-install if: runner.os == 'Linux' && matrix.app_version == 'stable' diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 33c9638247..429892ecdf 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -91,11 +91,3 @@ repos: hooks: - id: stylua exclude: ^data/playground/lua/.*\.lua$ - - repo: local - hooks: - - id: lua-language-server - name: lua-language-server - files: \.(lua|busted)$ - entry: scripts/lint-lua.sh - language: script - pass_filenames: false diff --git a/scripts/lint-lua.sh b/scripts/lint-lua-ls.sh similarity index 100% rename from scripts/lint-lua.sh rename to scripts/lint-lua-ls.sh From 65ce01cf5e25a798e2ae5d7e0a44eae579625124 Mon Sep 17 00:00:00 2001 From: fidgetingbits Date: Wed, 31 Jul 2024 22:13:51 +0800 Subject: [PATCH 3/8] address feedback --- scripts/lint-lua-ls.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/lint-lua-ls.sh b/scripts/lint-lua-ls.sh index 68ca47da50..7d8b5da137 100755 --- a/scripts/lint-lua-ls.sh +++ b/scripts/lint-lua-ls.sh @@ -35,7 +35,7 @@ function check_file() { # lua-language-server doesn't support single file parsing, so check entire folder exit_code=0 -if ! check_file .; then +if ! check_file "${CURSORLESS_REPO_ROOT}"; then exit_code=1 fi From 6557aa2a125b9b55f732683ddcd9be5a41cf72a4 Mon Sep 17 00:00:00 2001 From: fidgetingbits Date: Wed, 31 Jul 2024 22:19:27 +0800 Subject: [PATCH 4/8] ignore the .lua folder created by CI action --- .luarc.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.luarc.json b/.luarc.json index 4565a7e0e4..a58b4564ad 100644 --- a/.luarc.json +++ b/.luarc.json @@ -2,5 +2,5 @@ "runtime.version": "Lua 5.1", "diagnostics.ignoredFiles": "Disable", "diagnostics.globals": ["vim", "talon", "it", "describe"], - "workspace.ignoreDir": ["data/playground/lua/", ".luarocks"] + "workspace.ignoreDir": ["data/playground/lua/", ".luarocks", ".lua"] } From 63c5e1420ffba44834889c4dd1da3b8a3bb78310 Mon Sep 17 00:00:00 2001 From: Pokey Rule <755842+pokey@users.noreply.github.com> Date: Wed, 31 Jul 2024 15:23:39 +0100 Subject: [PATCH 5/8] Update flake.nix --- flake.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index 29fbef70c9..514d47cdef 100644 --- a/flake.nix +++ b/flake.nix @@ -47,7 +47,7 @@ }; neovim = prev.neovim.override { withNodeJs = true; }; # There is a recent bug that prevents cli --check invocation: - # See: https://github.com/LuaLS/lua-language-server/pull/2775 + # See #2613 lua-language-server = prev.lua-language-server.overrideAttrs { postPatch = let From 654dca7da3893b73183de4e845aca3ac564bc002 Mon Sep 17 00:00:00 2001 From: fidgetingbits Date: Thu, 1 Aug 2024 08:22:58 +0800 Subject: [PATCH 6/8] Trigger CI From aece96d68d8cdc41681641fc371110ddb5c649af Mon Sep 17 00:00:00 2001 From: fidgetingbits Date: Thu, 1 Aug 2024 08:46:52 +0800 Subject: [PATCH 7/8] test fixing mac tests --- .github/workflows/test.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 62c323d9e6..0fbb9fc3c4 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -29,6 +29,7 @@ jobs: VSCODE_LOGS_DIR: ${{ github.workspace }}/artifacts/logs CURSORLESS_REPO_ROOT: ${{ github.workspace }} TEMP_DIR: ${{ github.workspace }}/temp + NODE_OPTIONS: "--max_old_space_size=4096" steps: - uses: actions/checkout@v4 - run: corepack enable From 0fcac0ea296df499ad8f1273b6973034d9792f80 Mon Sep 17 00:00:00 2001 From: fidgetingbits Date: Thu, 1 Aug 2024 08:57:00 +0800 Subject: [PATCH 8/8] revert mac test --- .github/workflows/test.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 0fbb9fc3c4..62c323d9e6 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -29,7 +29,6 @@ jobs: VSCODE_LOGS_DIR: ${{ github.workspace }}/artifacts/logs CURSORLESS_REPO_ROOT: ${{ github.workspace }} TEMP_DIR: ${{ github.workspace }}/temp - NODE_OPTIONS: "--max_old_space_size=4096" steps: - uses: actions/checkout@v4 - run: corepack enable