diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b4483d5e..a11de1c7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,101 +20,24 @@ jobs: 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) - - strategy: - matrix: - include: - - os: ubuntu-20.04 - url: https://github.com/neovim/neovim/releases/download/nightly/nvim-linux64.tar.gz - manager: sudo apt-get - packages: -y fd-find esl-erlang elixir - - os: ubuntu-20.04 - url: https://github.com/neovim/neovim/releases/download/v0.9.5/nvim-linux64.tar.gz - manager: sudo apt-get - packages: -y fd-find esl-erlang elixir - - os: ubuntu-20.04 - url: https://github.com/neovim/neovim/releases/download/v0.8.3/nvim-linux64.tar.gz - manager: sudo apt-get - packages: -y fd-find esl-erlang elixir - - os: macos-14 - url: https://github.com/neovim/neovim/releases/download/nightly/nvim-macos-x86_64.tar.gz - manager: brew - packages: fd elixir - - os: macos-14 - url: https://github.com/neovim/neovim/releases/download/v0.9.5/nvim-macos.tar.gz - manager: brew - packages: fd elixir - - os: macos-14 - url: https://github.com/neovim/neovim/releases/download/v0.8.3/nvim-macos.tar.gz - manager: brew - packages: fd elixir - steps: - - uses: actions/checkout@v4 - - 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 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 - - - name: Prepare - run: | - ${{ matrix.manager }} update - ${{ matrix.manager }} install ${{ matrix.packages }} - test -d _neovim || { - mkdir -p _neovim - curl -sL ${{ matrix.url }} | tar xzf - --strip-components=1 -C "${PWD}/_neovim" - } - - - 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 + name: tests (${{ matrix.os }} - ${{ matrix.nvim-version }}) 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: v0.8.3 - - os: ubuntu-20.04 - manager: sudo apt-get - packages: -y fd-find esl-erlang elixir - nvim-version: v0.9.5 - - os: macos-14 - manager: brew - packages: fd elixir - nvim-version: v0.8.3 - - os: macos-14 - manager: brew - packages: fd elixir - nvim-version: v0.9.5 + os: [ubuntu-latest, macos-14] + nvim-version: [v0.8.3, v0.9.5, v0.10.3] + steps: - uses: actions/checkout@v4 - - uses: extractions/setup-just@v2 + - uses: DeterminateSystems/nix-installer-action@main + - uses: DeterminateSystems/magic-nix-cache-action@main - 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 }} + run: nix shell nixpkgs#bash nixpkgs#just -c just test ${{ matrix.nvim-version }} diff --git a/.gitignore b/.gitignore index c3121bab..194fed01 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ tmp node_modules nvim-test deps -busted/fixtures/basic/bin -busted/fixtures/basic/data +spec/fixtures/basic/bin +spec/fixtures/basic/cache +spec/fixtures/basic/data diff --git a/lua/elixir/nextls/init.lua b/lua/elixir/nextls/init.lua index d048f614..053a475c 100644 --- a/lua/elixir/nextls/init.lua +++ b/lua/elixir/nextls/init.lua @@ -5,8 +5,8 @@ if not vim.uv then vim.uv = vim.loop end -M.default_bin = vim.g.next_ls_default_bin or (vim.env.HOME .. "/.cache/elixir-tools/nextls/bin/nextls") -M.default_data = vim.g.next_ls_data_dir or (vim.env.HOME .. "/.data/elixir-tools/nextls") +M.default_bin = vim.g.next_ls_default_bin or (utils.cache_dir() .. "/elixir-tools/nextls/bin/nextls") +M.default_data = vim.g.next_ls_data_dir or (utils.data_dir() .. "/elixir-tools/nextls") local function bufname_valid(bufname) if diff --git a/lua/elixir/utils.lua b/lua/elixir/utils.lua index 5338a547..9fddc4fa 100644 --- a/lua/elixir/utils.lua +++ b/lua/elixir/utils.lua @@ -1,6 +1,14 @@ local Path = require("plenary.path") local M = {} +function M.cache_dir() + return vim.env.XDG_CACHE_HOME or vim.env.HOME .. "/.cache" +end + +function M.data_dir() + return vim.env.XDG_DATA_HOME or vim.env.HOME .. "/.data" +end + ---@param path string function M.safe_path(path) return string.gsub(path, "/", "_") @@ -37,7 +45,7 @@ local arch = { function M.download_nextls(opts) vim.notify("[elixir-tools] Downloading latest version of Next LS") - local default_cache_dir = vim.g.next_ls_cache_dir or vim.env.HOME .. "/.cache/elixir-tools/nextls/bin" + local default_cache_dir = vim.g.next_ls_cache_dir or M.cache_dir() .. "/elixir-tools/nextls/bin" opts = opts or {} local cache_dir = opts.cache_dir or default_cache_dir local os_name = string.lower(vim.uv.os_uname().sysname) @@ -77,7 +85,7 @@ end function M.latest_release(owner, repo, opts) opts = opts or {} local github_host = opts.github_host or "api.github.com" - local cache_dir = opts.cache_dir or "~/.cache/nvim/elixir-tools.nvim/" + local cache_dir = opts.cache_dir or M.cache_dir() .. "/nvim/elixir-tools.nvim/" local curl_response = vim.fn.system { "curl", "--fail", diff --git a/spec/nextls/install_spec.lua b/spec/nextls/install_spec.lua index 51a27914..d757ce27 100644 --- a/spec/nextls/install_spec.lua +++ b/spec/nextls/install_spec.lua @@ -4,6 +4,8 @@ local exec_lua = helpers.exec_lua local luv = vim.loop local eq = assert.equal +helpers.options = { verbose = true } + describe("install", function() before_each(function() helpers.clear() @@ -11,6 +13,11 @@ describe("install", function() helpers.fn.delete("./spec/fixtures/basic/data", "rf") helpers.fn.mkdir("./spec/fixtures/basic/data", "p") helpers.fn.mkdir("./spec/fixtures/basic/bin", "p") + exec_lua([[ + vim.g.next_ls_cache_dir = nil + vim.g.next_ls_data_dir = nil + vim.g.next_ls_default_bin = nil + ]]) -- Make plugin available exec_lua([[vim.opt.rtp:append'.']]) exec_lua([[vim.opt.rtp:append'./deps/plenary.nvim/']]) @@ -29,6 +36,20 @@ describe("install", function() eq(luv.fs_stat("./spec/fixtures/basic/bin/nextls").mode, 33523) end) + it("installs nextls into the xdg dirs when set", function() + helpers.fn.writefile({ "" }, "./spec/fixtures/basic/data/.next-ls-force-update-v1") + exec_lua([[ + vim.env.XDG_CACHE_HOME = "./spec/fixtures/basic/cache" + vim.env.XDG_DATA_HOME = "./spec/fixtures/basic/data" + require("elixir.nextls").setup({auto_update = true, cmd = "./spec/fixtures/basic/cache/elixir-tools/nextls/bin/nextls" }) + vim.cmd.edit("./spec/fixtures/basic/lib/basic.ex") + ]]) + + local file = luv.fs_stat("./spec/fixtures/basic/cache/elixir-tools/nextls/bin/nextls") + assert.Table(file) + eq(file.mode, 33523) + end) + it("forces an install if the flag is not set", function() helpers.fn.mkdir("./spec/fixtures/basic/bin", "p") helpers.fn.writefile({ "foobar" }, "./spec/fixtures/basic/bin/nextls") @@ -70,19 +91,16 @@ describe("install", function() Enum.map([:one, :two], &Function.identity/1) | end | end | - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| + ~ | + ~ | + ~ | + ~ | + ~ | + ~ | + ~ | + ~ | | ]], - attr_ids = { - [1] = { foreground = Screen.colors.NvimLightGrey4 }, - }, } end) end)