Skip to content

feat: support XDG_CACHE_HOME and XDG_DATA_HOME #236

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 6 commits into from
Jan 13, 2025
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
91 changes: 7 additions & 84 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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

4 changes: 2 additions & 2 deletions lua/elixir/nextls/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 10 additions & 2 deletions lua/elixir/utils.lua
Original file line number Diff line number Diff line change
@@ -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, "/", "_")
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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",
Expand Down
40 changes: 29 additions & 11 deletions spec/nextls/install_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,20 @@ 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()
helpers.fn.delete("./spec/fixtures/basic/bin", "rf")
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/']])
Expand All @@ -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")
Expand Down Expand Up @@ -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)
Loading