Skip to content

Commit

Permalink
fix(nextls): force a download (#203)
Browse files Browse the repository at this point in the history
  • Loading branch information
mhanberg authored Mar 8, 2024
1 parent 0de83ff commit 123dbc2
Show file tree
Hide file tree
Showing 16 changed files with 385 additions and 43 deletions.
63 changes: 53 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,22 @@ concurrency:
cancel-in-progress: true

jobs:
unit_tests:
name: unit tests
stylua:
name: Stylua
runs-on: ubuntu-latest

if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.fork == true)

steps:
- uses: actions/checkout@v4
- uses: JohnnyMorganz/stylua-action@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
version: latest
args: --check .

legacy_tests:
name: legacy tests
runs-on: ${{ matrix.os }}

if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.fork == true)
Expand Down Expand Up @@ -41,20 +55,14 @@ jobs:
packages: fd elixir
steps:
- uses: actions/checkout@v4
- uses: JohnnyMorganz/stylua-action@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
version: latest
args: --check .

- run: date +%F > todays-date
- name: Restore from todays cache
uses: actions/cache@v4
with:
path: _neovim
key: ${{ runner.os }}-${{ matrix.url }}-${{ hashFiles('todays-date') }}

- name: Add Repositoy
- name: Add Repository
if: matrix.os == 'ubuntu-20.04'
run: wget https://packages.erlang-solutions.com/erlang-solutions_2.0_all.deb && sudo dpkg -i erlang-solutions_2.0_all.deb

Expand All @@ -67,11 +75,46 @@ jobs:
curl -sL ${{ matrix.url }} | tar xzf - --strip-components=1 -C "${PWD}/_neovim"
}
- name: Run tests
- name: Run legacy tests
env:
BUSTED_TIMEOUT: 600000
run: |
export PATH="${PWD}/_neovim/bin:${PATH}"
export VIM="${PWD}/_neovim/share/nvim/runtime"
nvim --version
bin/test
tests:
name: tests
runs-on: ${{ matrix.os }}

if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.fork == true)

strategy:
matrix:
include:
- os: ubuntu-20.04
manager: sudo apt-get
packages: -y fd-find esl-erlang elixir
nvim-version: 0.8.3
- os: ubuntu-20.04
manager: sudo apt-get
packages: -y fd-find esl-erlang elixir
nvim-version: 0.9.5
- os: macos-14
manager: brew
packages: fd elixir
nvim-version: 0.8.3
- os: macos-14
manager: brew
packages: fd elixir
nvim-version: 0.9.5
steps:
- uses: actions/checkout@v4
- uses: extractions/setup-just@v1
- uses: leafo/gh-actions-lua@v10
with:
luaVersion: "5.1.5"
- uses: leafo/gh-actions-luarocks@v4
- name: Run nvim-test tests
run: just test ${{ matrix.nvim-version }}
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
tmp
node_modules
nvim-test
deps
busted/fixtures/basic/bin
busted/fixtures/basic/data

8 changes: 5 additions & 3 deletions .luarc.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{
"$schema": "https://raw.githubusercontent.com/sumneko/vscode-lua/master/setting/schema.json",
"Lua.workspace.checkThirdParty": false
}
"$schema": "https://raw.githubusercontent.com/sumneko/vscode-lua/master/setting/schema.json",
"runtime": {
"version": "LuaJIT"
}
}
38 changes: 37 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ elixir.setup {
| Command | Subcommand | Description |
|---------|------------|------------------------------------------------------------------------------------------------------|
| nextls | uninstall | Removes the `nextls` executable from the default location: `~/.cache/elixir-tools/nextls/bin/nextls` |
| nextls | to-pipe | Extracts the first argument to a pipe call |
| nextls | to-pipe | Extracts the first argument to a pipe call |
| nextls | from-pipe | Inlines the pipe call to a function call the first argument to a pipe |

## Next LS
Expand Down Expand Up @@ -364,3 +364,39 @@ You can run any `mix` command in your project, complete with... autocomplete!
:Efeature {args}

: Create or edit a Wallaby test module.

## Contributing

### Setup

elixir-tools.nvim uses a combination of [Nix]() and [just]() to provide the development tooling, but you can also install all of this manually.

#### Nix + just

```bash
# enter a nix shell, provides language deps and just
$ nix develop

# install test runner and plugin dependencies
$ just init

# run tests, optionally include the Neovim version to test
$ just test
$ just test 0.8.3

# format the code
$ just format
```

#### Manually

Install the following software:

- [Neovim](https://neovim.io)
- [Lua 5.1](https://sourceforge.net/projects/luabinaries/files/5.1.5/)
- [Luarocks](https://github.com/luarocks/luarocks/wiki/Download)
- [nvim-test](https://github.com/lewis6991/nvim-test)
- [plenary.nvim](https://github.com/nvim-lua/plenary.nvim) (into the folder "deps")
- [stylua](https://github.com/JohnnyMorganz/StyLua)

To run the tests, you can reference the commands run in the justfile
5 changes: 5 additions & 0 deletions busted/fixtures/basic/lib/basic.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
defmodule Basic do
def run do
Enum.map([:one, :two], &Function.identity/1)
end
end
32 changes: 32 additions & 0 deletions busted/fixtures/basic/mix.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
defmodule Basic.MixProject do
use Mix.Project

@version "0.1.0"

def project do
[
app: :basic,
description: "Basic app",
version: @version,
elixir: "~> 1.13",
elixirc_paths: elixirc_paths(Mix.env()),
start_permanent: Mix.env() == :prod,
deps: deps()
]
end

# Run "mix help compile.app" to learn about applications.
def application do
[
extra_applications: [:logger, :crypto]
]
end

defp elixirc_paths(:test), do: ["lib", "test/support"]
defp elixirc_paths(_), do: ["lib"]

# Run "mix help deps" to learn about dependencies.
defp deps do
[]
end
end
88 changes: 88 additions & 0 deletions busted/nextls/install_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
local helpers = require("nvim-test.helpers")
local Screen = require("nvim-test.screen")
local exec_lua = helpers.exec_lua
local luv = vim.loop
local eq = assert.equal

describe("install", function()
before_each(function()
helpers.clear()
helpers.fn.delete("./busted/fixtures/basic/bin", "rf")
helpers.fn.delete("./busted/fixtures/basic/data", "rf")
helpers.fn.mkdir("./busted/fixtures/basic/data", "p")
helpers.fn.mkdir("./busted/fixtures/basic/bin", "p")
-- Make plugin available
exec_lua([[vim.opt.rtp:append'.']])
exec_lua([[vim.opt.rtp:append'./deps/plenary.nvim/']])
end)

it("installs nextls when you open an elixir file and nextls isn't downloaded", function()
helpers.fn.writefile({ "" }, "./busted/fixtures/basic/data/.next-ls-force-update-v1")
exec_lua([[
vim.g.next_ls_cache_dir = "./busted/fixtures/basic/bin"
vim.g.next_ls_data_dir = "./busted/fixtures/basic/data"
vim.g.next_ls_default_bin = "./busted/fixtures/basic/bin/nextls"
require("elixir.nextls").setup({auto_update = true, cmd = "./busted/fixtures/basic/bin/nextls" })
vim.cmd.edit("./busted/fixtures/basic/lib/basic.ex")
]])

eq(luv.fs_stat("./busted/fixtures/basic/bin/nextls").mode, 33523)
end)

it("forces an install if the flag is not set", function()
helpers.fn.mkdir("./busted/fixtures/basic/bin", "p")
helpers.fn.writefile({ "foobar" }, "./busted/fixtures/basic/bin/nextls")
exec_lua([[
vim.g.next_ls_cache_dir = "./busted/fixtures/basic/bin"
vim.g.next_ls_data_dir = "./busted/fixtures/basic/data"
vim.g.next_ls_default_bin = "./busted/fixtures/basic/bin/nextls"
require("elixir.nextls").setup({auto_update = true, cmd = "./busted/fixtures/basic/bin/nextls" })
vim.cmd.edit("./busted/fixtures/basic/lib/basic.ex")
]])

assert.error(function()
helpers.fn.readfile("./busted/fixtures/basic/bin/nextls", "b")
end)
eq(luv.fs_stat("./busted/fixtures/basic/bin/nextls").mode, 33523)
end)

it("doesnt force an install if the flag is set", function()
helpers.fn.writefile({ "" }, "./busted/fixtures/basic/data/.next-ls-force-update-v1")
helpers.fn.mkdir("./busted/fixtures/basic/bin", "p")
helpers.fn.writefile({ "foobar" }, "./busted/fixtures/basic/bin/nextls")
local screen = Screen.new()
screen:attach()
exec_lua([[
vim.g.next_ls_cache_dir = "./busted/fixtures/basic/bin"
vim.g.next_ls_data_dir = "./busted/fixtures/basic/data"
vim.g.next_ls_default_bin = "./busted/fixtures/basic/bin/nextls"
require("elixir.nextls").setup({auto_update = true, cmd = "./busted/fixtures/basic/bin/nextls" })
vim.cmd.edit("./busted/fixtures/basic/lib/basic.ex")
]])

helpers.feed("<cr>")
-- screen:snapshot_util()
eq(helpers.fn.readfile("./busted/fixtures/basic/bin/nextls", "b")[1], "foobar")
screen:expect {
grid = [[
^defmodule Basic do |
def run do |
Enum.map([:one, :two], &Function.identity/1) |
end |
end |
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
|
]],
attr_ids = {
[1] = { bold = true, foreground = Screen.colors.Blue1 },
},
}
end)
end)
64 changes: 64 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 43 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
description = "Description for the project";

inputs = {
flake-parts.url = "github:hercules-ci/flake-parts";
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
};

outputs = inputs@{ flake-parts, ... }:
flake-parts.lib.mkFlake { inherit inputs; } {
imports = [
# To import a flake module
# 1. Add foo to inputs
# 2. Add foo as a parameter to the outputs function
# 3. Add here: foo.flakeModule

];
systems = [ "x86_64-linux" "aarch64-linux" "aarch64-darwin" "x86_64-darwin" ];
perSystem = { config, self', inputs', pkgs, system, ... }: {
# Per-system attributes can be defined here. The self' and inputs'
# module parameters provide easy access to attributes of the same
# system.

# Equivalent to inputs'.nixpkgs.legacyPackages.hello;
packages.default = pkgs.hello;
devShells.default = pkgs.mkShell {
# The Nix packages provided in the environment
packages = [
pkgs.luarocks
pkgs.lua5_1
pkgs.just
pkgs.stylua
];
};
};
flake = {
# The usual flake attributes can be defined here, including system-
# agnostic ones like nixosModule and system-enumerating ones, although
# those are more easily expressed in perSystem.

};
};
}
Loading

0 comments on commit 123dbc2

Please sign in to comment.