Skip to content

Commit f4bd15f

Browse files
authored
feat: support XDG_CACHE_HOME and XDG_DATA_HOME (#236)
1 parent 2c8466c commit f4bd15f

File tree

5 files changed

+51
-101
lines changed

5 files changed

+51
-101
lines changed

.github/workflows/ci.yml

Lines changed: 7 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -20,101 +20,24 @@ jobs:
2020
version: latest
2121
args: --check .
2222

23-
legacy_tests:
24-
name: legacy tests
25-
runs-on: ${{ matrix.os }}
26-
27-
if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.fork == true)
28-
29-
strategy:
30-
matrix:
31-
include:
32-
- os: ubuntu-20.04
33-
url: https://github.com/neovim/neovim/releases/download/nightly/nvim-linux64.tar.gz
34-
manager: sudo apt-get
35-
packages: -y fd-find esl-erlang elixir
36-
- os: ubuntu-20.04
37-
url: https://github.com/neovim/neovim/releases/download/v0.9.5/nvim-linux64.tar.gz
38-
manager: sudo apt-get
39-
packages: -y fd-find esl-erlang elixir
40-
- os: ubuntu-20.04
41-
url: https://github.com/neovim/neovim/releases/download/v0.8.3/nvim-linux64.tar.gz
42-
manager: sudo apt-get
43-
packages: -y fd-find esl-erlang elixir
44-
- os: macos-14
45-
url: https://github.com/neovim/neovim/releases/download/nightly/nvim-macos-x86_64.tar.gz
46-
manager: brew
47-
packages: fd elixir
48-
- os: macos-14
49-
url: https://github.com/neovim/neovim/releases/download/v0.9.5/nvim-macos.tar.gz
50-
manager: brew
51-
packages: fd elixir
52-
- os: macos-14
53-
url: https://github.com/neovim/neovim/releases/download/v0.8.3/nvim-macos.tar.gz
54-
manager: brew
55-
packages: fd elixir
56-
steps:
57-
- uses: actions/checkout@v4
58-
- run: date +%F > todays-date
59-
- name: Restore from todays cache
60-
uses: actions/cache@v4
61-
with:
62-
path: _neovim
63-
key: ${{ runner.os }}-${{ matrix.url }}-${{ hashFiles('todays-date') }}
64-
65-
- name: Add Repository
66-
if: matrix.os == 'ubuntu-20.04'
67-
run: wget https://packages.erlang-solutions.com/erlang-solutions_2.0_all.deb && sudo dpkg -i erlang-solutions_2.0_all.deb
68-
69-
- name: Prepare
70-
run: |
71-
${{ matrix.manager }} update
72-
${{ matrix.manager }} install ${{ matrix.packages }}
73-
test -d _neovim || {
74-
mkdir -p _neovim
75-
curl -sL ${{ matrix.url }} | tar xzf - --strip-components=1 -C "${PWD}/_neovim"
76-
}
77-
78-
- name: Run legacy tests
79-
env:
80-
BUSTED_TIMEOUT: 600000
81-
run: |
82-
export PATH="${PWD}/_neovim/bin:${PATH}"
83-
export VIM="${PWD}/_neovim/share/nvim/runtime"
84-
nvim --version
85-
bin/test
86-
8723
tests:
88-
name: tests
24+
name: tests (${{ matrix.os }} - ${{ matrix.nvim-version }})
8925
runs-on: ${{ matrix.os }}
9026

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

9329
strategy:
9430
matrix:
95-
include:
96-
- os: ubuntu-20.04
97-
manager: sudo apt-get
98-
packages: -y fd-find esl-erlang elixir
99-
nvim-version: v0.8.3
100-
- os: ubuntu-20.04
101-
manager: sudo apt-get
102-
packages: -y fd-find esl-erlang elixir
103-
nvim-version: v0.9.5
104-
- os: macos-14
105-
manager: brew
106-
packages: fd elixir
107-
nvim-version: v0.8.3
108-
- os: macos-14
109-
manager: brew
110-
packages: fd elixir
111-
nvim-version: v0.9.5
31+
os: [ubuntu-latest, macos-14]
32+
nvim-version: [v0.8.3, v0.9.5, v0.10.3]
33+
11234
steps:
11335
- uses: actions/checkout@v4
114-
- uses: extractions/setup-just@v2
36+
- uses: DeterminateSystems/nix-installer-action@main
37+
- uses: DeterminateSystems/magic-nix-cache-action@main
11538
- uses: leafo/gh-actions-lua@v10
11639
with:
11740
luaVersion: "5.1.5"
11841
- uses: leafo/gh-actions-luarocks@v4
11942
- name: Run nvim-test tests
120-
run: just test ${{ matrix.nvim-version }}
43+
run: nix shell nixpkgs#bash nixpkgs#just -c just test ${{ matrix.nvim-version }}

.gitignore

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ tmp
22
node_modules
33
nvim-test
44
deps
5-
busted/fixtures/basic/bin
6-
busted/fixtures/basic/data
5+
spec/fixtures/basic/bin
6+
spec/fixtures/basic/cache
7+
spec/fixtures/basic/data
78

lua/elixir/nextls/init.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ if not vim.uv then
55
vim.uv = vim.loop
66
end
77

8-
M.default_bin = vim.g.next_ls_default_bin or (vim.env.HOME .. "/.cache/elixir-tools/nextls/bin/nextls")
9-
M.default_data = vim.g.next_ls_data_dir or (vim.env.HOME .. "/.data/elixir-tools/nextls")
8+
M.default_bin = vim.g.next_ls_default_bin or (utils.cache_dir() .. "/elixir-tools/nextls/bin/nextls")
9+
M.default_data = vim.g.next_ls_data_dir or (utils.data_dir() .. "/elixir-tools/nextls")
1010

1111
local function bufname_valid(bufname)
1212
if

lua/elixir/utils.lua

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
local Path = require("plenary.path")
22
local M = {}
33

4+
function M.cache_dir()
5+
return vim.env.XDG_CACHE_HOME or vim.env.HOME .. "/.cache"
6+
end
7+
8+
function M.data_dir()
9+
return vim.env.XDG_DATA_HOME or vim.env.HOME .. "/.data"
10+
end
11+
412
---@param path string
513
function M.safe_path(path)
614
return string.gsub(path, "/", "_")
@@ -37,7 +45,7 @@ local arch = {
3745

3846
function M.download_nextls(opts)
3947
vim.notify("[elixir-tools] Downloading latest version of Next LS")
40-
local default_cache_dir = vim.g.next_ls_cache_dir or vim.env.HOME .. "/.cache/elixir-tools/nextls/bin"
48+
local default_cache_dir = vim.g.next_ls_cache_dir or M.cache_dir() .. "/elixir-tools/nextls/bin"
4149
opts = opts or {}
4250
local cache_dir = opts.cache_dir or default_cache_dir
4351
local os_name = string.lower(vim.uv.os_uname().sysname)
@@ -77,7 +85,7 @@ end
7785
function M.latest_release(owner, repo, opts)
7886
opts = opts or {}
7987
local github_host = opts.github_host or "api.github.com"
80-
local cache_dir = opts.cache_dir or "~/.cache/nvim/elixir-tools.nvim/"
88+
local cache_dir = opts.cache_dir or M.cache_dir() .. "/nvim/elixir-tools.nvim/"
8189
local curl_response = vim.fn.system {
8290
"curl",
8391
"--fail",

spec/nextls/install_spec.lua

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,20 @@ local exec_lua = helpers.exec_lua
44
local luv = vim.loop
55
local eq = assert.equal
66

7+
helpers.options = { verbose = true }
8+
79
describe("install", function()
810
before_each(function()
911
helpers.clear()
1012
helpers.fn.delete("./spec/fixtures/basic/bin", "rf")
1113
helpers.fn.delete("./spec/fixtures/basic/data", "rf")
1214
helpers.fn.mkdir("./spec/fixtures/basic/data", "p")
1315
helpers.fn.mkdir("./spec/fixtures/basic/bin", "p")
16+
exec_lua([[
17+
vim.g.next_ls_cache_dir = nil
18+
vim.g.next_ls_data_dir = nil
19+
vim.g.next_ls_default_bin = nil
20+
]])
1421
-- Make plugin available
1522
exec_lua([[vim.opt.rtp:append'.']])
1623
exec_lua([[vim.opt.rtp:append'./deps/plenary.nvim/']])
@@ -29,6 +36,20 @@ describe("install", function()
2936
eq(luv.fs_stat("./spec/fixtures/basic/bin/nextls").mode, 33523)
3037
end)
3138

39+
it("installs nextls into the xdg dirs when set", function()
40+
helpers.fn.writefile({ "" }, "./spec/fixtures/basic/data/.next-ls-force-update-v1")
41+
exec_lua([[
42+
vim.env.XDG_CACHE_HOME = "./spec/fixtures/basic/cache"
43+
vim.env.XDG_DATA_HOME = "./spec/fixtures/basic/data"
44+
require("elixir.nextls").setup({auto_update = true, cmd = "./spec/fixtures/basic/cache/elixir-tools/nextls/bin/nextls" })
45+
vim.cmd.edit("./spec/fixtures/basic/lib/basic.ex")
46+
]])
47+
48+
local file = luv.fs_stat("./spec/fixtures/basic/cache/elixir-tools/nextls/bin/nextls")
49+
assert.Table(file)
50+
eq(file.mode, 33523)
51+
end)
52+
3253
it("forces an install if the flag is not set", function()
3354
helpers.fn.mkdir("./spec/fixtures/basic/bin", "p")
3455
helpers.fn.writefile({ "foobar" }, "./spec/fixtures/basic/bin/nextls")
@@ -70,19 +91,16 @@ describe("install", function()
7091
Enum.map([:one, :two], &Function.identity/1) |
7192
end |
7293
end |
73-
{1:~ }|
74-
{1:~ }|
75-
{1:~ }|
76-
{1:~ }|
77-
{1:~ }|
78-
{1:~ }|
79-
{1:~ }|
80-
{1:~ }|
94+
~ |
95+
~ |
96+
~ |
97+
~ |
98+
~ |
99+
~ |
100+
~ |
101+
~ |
81102
|
82103
]],
83-
attr_ids = {
84-
[1] = { foreground = Screen.colors.NvimLightGrey4 },
85-
},
86104
}
87105
end)
88106
end)

0 commit comments

Comments
 (0)