From 8360e17ceca39cf74534542211f914423f029973 Mon Sep 17 00:00:00 2001 From: Mitchell Hanberg Date: Sun, 12 Jan 2025 12:17:46 -0500 Subject: [PATCH 1/6] feat: support XDG_CACHE_HOME and XDG_DATA_HOME --- .gitignore | 5 +++-- lua/elixir/nextls/init.lua | 4 ++-- lua/elixir/utils.lua | 12 ++++++++++-- spec/nextls/install_spec.lua | 21 +++++++++++++++++++++ 4 files changed, 36 insertions(+), 6 deletions(-) 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..c23ed6c0 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") From 6e0dff38f5b4f430f761947b5386641bbf8c0062 Mon Sep 17 00:00:00 2001 From: Mitchell Hanberg Date: Sun, 12 Jan 2025 14:32:48 -0500 Subject: [PATCH 2/6] fixup! feat: support XDG_CACHE_HOME and XDG_DATA_HOME --- spec/nextls/install_spec.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/spec/nextls/install_spec.lua b/spec/nextls/install_spec.lua index c23ed6c0..08f2151f 100644 --- a/spec/nextls/install_spec.lua +++ b/spec/nextls/install_spec.lua @@ -74,6 +74,7 @@ describe("install", function() local screen = Screen.new() screen:attach() exec_lua([[ + vim.cmd.colorscheme("vim") vim.g.next_ls_cache_dir = "./spec/fixtures/basic/bin" vim.g.next_ls_data_dir = "./spec/fixtures/basic/data" vim.g.next_ls_default_bin = "./spec/fixtures/basic/bin/nextls" @@ -102,7 +103,7 @@ describe("install", function() | ]], attr_ids = { - [1] = { foreground = Screen.colors.NvimLightGrey4 }, + [1] = { bold = true, foreground = Screen.colors.Blue1 }, }, } end) From 3df2ad18fe83ff2da0115ce46c95021bf95e63e3 Mon Sep 17 00:00:00 2001 From: Mitchell Hanberg Date: Sun, 12 Jan 2025 14:35:36 -0500 Subject: [PATCH 3/6] fixup! feat: support XDG_CACHE_HOME and XDG_DATA_HOME --- spec/nextls/install_spec.lua | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/spec/nextls/install_spec.lua b/spec/nextls/install_spec.lua index 08f2151f..d757ce27 100644 --- a/spec/nextls/install_spec.lua +++ b/spec/nextls/install_spec.lua @@ -74,7 +74,6 @@ describe("install", function() local screen = Screen.new() screen:attach() exec_lua([[ - vim.cmd.colorscheme("vim") vim.g.next_ls_cache_dir = "./spec/fixtures/basic/bin" vim.g.next_ls_data_dir = "./spec/fixtures/basic/data" vim.g.next_ls_default_bin = "./spec/fixtures/basic/bin/nextls" @@ -92,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] = { bold = true, foreground = Screen.colors.Blue1 }, - }, } end) end) From e5e3e9c3b860a01fbde52f2814f9443163c50b47 Mon Sep 17 00:00:00 2001 From: Mitchell Hanberg Date: Sun, 12 Jan 2025 14:37:06 -0500 Subject: [PATCH 4/6] fixup! feat: support XDG_CACHE_HOME and XDG_DATA_HOME --- .github/workflows/ci.yml | 64 ---------------------------------------- 1 file changed, 64 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b4483d5e..1385a61d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,70 +20,6 @@ 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 runs-on: ${{ matrix.os }} From 947e3eb85690bf6459c6314d3da6740eb4d5715c Mon Sep 17 00:00:00 2001 From: Mitchell Hanberg Date: Sun, 12 Jan 2025 14:41:53 -0500 Subject: [PATCH 5/6] fixup! feat: support XDG_CACHE_HOME and XDG_DATA_HOME --- .github/workflows/ci.yml | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1385a61d..733d5284 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -28,29 +28,16 @@ jobs: 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 ${{ nvim-version }} From 8770c0e04bec69524ab6b55bea63af3deedacff1 Mon Sep 17 00:00:00 2001 From: Mitchell Hanberg Date: Sun, 12 Jan 2025 14:44:18 -0500 Subject: [PATCH 6/6] fixup! feat: support XDG_CACHE_HOME and XDG_DATA_HOME --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 733d5284..a11de1c7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,7 +21,7 @@ jobs: args: --check . 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) @@ -40,4 +40,4 @@ jobs: luaVersion: "5.1.5" - uses: leafo/gh-actions-luarocks@v4 - name: Run nvim-test tests - run: nix shell nixpkgs#bash nixpkgs#just -c just test ${{ nvim-version }} + run: nix shell nixpkgs#bash nixpkgs#just -c just test ${{ matrix.nvim-version }}