Skip to content

feat: Add lua-language-server to CI #2611

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .github/actions/lint-lua-ls/action.yml
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
6 changes: 6 additions & 0 deletions .luarc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"runtime.version": "Lua 5.1",
"diagnostics.ignoredFiles": "Disable",
"diagnostics.globals": ["vim", "talon", "it", "describe"],
"workspace.ignoreDir": ["data/playground/lua/", ".luarocks", ".lua"]
}
4 changes: 0 additions & 4 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
27 changes: 25 additions & 2 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 // {
Expand All @@ -45,7 +46,21 @@
};
};
neovim = prev.neovim.override { withNodeJs = true; };

# There is a recent bug that prevents cli --check invocation:
# See #2613
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;
};
})

];
Expand All @@ -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 }:
{
Expand All @@ -69,19 +90,21 @@
[
pkgs.corepack
pkgs.vsce
pkgs.nodejs

# https://github.com/NixOS/nixpkgs/pull/251418
(pkgs.pre-commit.overrideAttrs (previousAttrs: {
makeWrapperArgs = ''
--set PYTHONPATH $PYTHONPATH
'';
}))
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 ];
Expand Down
42 changes: 42 additions & 0 deletions scripts/lint-lua-ls.sh
Original file line number Diff line number Diff line change
@@ -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 "${CURSORLESS_REPO_ROOT}"; then
exit_code=1
fi

exit $exit_code
Loading