Skip to content

Commit

Permalink
Merge pull request #19 from QuantumVim/5-feat-move-qvim-to-the-state-…
Browse files Browse the repository at this point in the history
…directory

rework(#5): move qvim to rtp directory
  • Loading branch information
quantumfate authored Aug 20, 2023
2 parents 5dc38bd + dbe0496 commit ef81b62
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 85 deletions.
4 changes: 2 additions & 2 deletions .luacheckrc
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ stds.nvim = {
"get_qvim_cache_dir",
"get_qvim_config_dir",
"get_qvim_data_dir",
"get_qvim_state_dir",
"get_qvim_rtp_dir",
"get_qvim_base_dir",
"get_lazy_rtp_dir",
"require_clean",
Expand All @@ -44,6 +44,6 @@ self = false
cache = true

ignore = {
"631", -- max_line_length
"631", -- max_line_length
"212/_.*", -- unused argument, for vars with "_" prefix
}
6 changes: 3 additions & 3 deletions lua/qvim/bootstrap.lua
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ end

---Get the full path to `$QUANTUMVIM_STATE_DIR`
---@return string
function _G.get_qvim_state_dir()
local qvim_state_dir = os.getenv("QUANTUMVIM_STATE_DIR")
function _G.get_qvim_rtp_dir()
local qvim_state_dir = os.getenv("QUANTUMVIM_RTP_DIR")
if not qvim_state_dir then
return vim.call("stdpath", "state")
end
Expand Down Expand Up @@ -94,7 +94,7 @@ function M:init()
if what == "cache" then
return get_qvim_cache_dir()
elseif what == "state" then
return get_qvim_state_dir()
return get_qvim_rtp_dir()
elseif what == "data" then
return get_qvim_data_dir()
elseif what == "config" then
Expand Down
75 changes: 41 additions & 34 deletions tests/specs/bootstrap_spec.lua
Original file line number Diff line number Diff line change
@@ -1,45 +1,52 @@
local a = require "plenary.async_lib.tests"
local a = require("plenary.async_lib.tests")
local uv = vim.loop
local home_dir = uv.os_homedir()

a.describe("initial start", function()
local qvim_config_path = get_qvim_config_dir()
local qvim_data_path = get_qvim_data_dir()
local qvim_cache_path = get_qvim_cache_dir()
local qvim_state_path = get_qvim_state_dir()
local qvim_config_path = get_qvim_config_dir()
local qvim_data_path = get_qvim_data_dir()
local qvim_cache_path = get_qvim_cache_dir()
local qvim_state_path = get_qvim_rtp_dir()

a.it("NVIM_APPNAME variable should be set", function()
assert.truthy(os.getenv("NVIM_APPNAME") ~= nil)
end)
a.it("NVIM_APPNAME variable should be set", function()
assert.truthy(os.getenv("NVIM_APPNAME") ~= nil)
end)

a.it("should be able to use QuantumVim directories using vim.fn", function()
assert.equal(qvim_config_path, vim.fn.stdpath("config"))
assert.equal(qvim_data_path, vim.fn.stdpath("data"))
assert.equal(qvim_cache_path, vim.fn.stdpath("cache"))
assert.equal(qvim_state_path, vim.fn.stdpath("state"))
end)
a.it("should be able to use QuantumVim directories using vim.fn", function()
assert.equal(qvim_config_path, vim.fn.stdpath("config"))
assert.equal(qvim_data_path, vim.fn.stdpath("data"))
assert.equal(qvim_cache_path, vim.fn.stdpath("cache"))
assert.equal(qvim_state_path, vim.fn.stdpath("state"))
end)

a.it("should NOT be able to retrieve default neovim directories", function()
local xdg_config = os.getenv "XDG_CONFIG_HOME" or join_paths(home_dir, ".config")
assert.truthy(join_paths(xdg_config, "nvim") ~= vim.call("stdpath", "config"))
end)
a.it("should NOT be able to retrieve default neovim directories", function()
local xdg_config = os.getenv("XDG_CONFIG_HOME")
or join_paths(home_dir, ".config")
assert.truthy(
join_paths(xdg_config, "nvim") ~= vim.call("stdpath", "config")
)
end)

a.it("should be able to read lazy directories from rtp", function()
local rtp_list = vim.opt.rtp:get()
assert.truthy(vim.tbl_contains(rtp_list, join_paths(get_lazy_rtp_dir(), "*")))
assert.truthy(vim.tbl_contains(rtp_list, get_lazy_rtp_dir() .. "/lazy.nvim"))
end)
a.it("should be able to read lazy directories from rtp", function()
local rtp_list = vim.opt.rtp:get()
assert.truthy(
vim.tbl_contains(rtp_list, join_paths(get_lazy_rtp_dir(), "*"))
)
assert.truthy(
vim.tbl_contains(rtp_list, get_lazy_rtp_dir() .. "/lazy.nvim")
)
end)

a.it("should be able to run treesitter without errors", function()
assert.truthy(vim.treesitter.highlighter.active)
end)
a.it("should be able to run treesitter without errors", function()
assert.truthy(vim.treesitter.highlighter.active)
end)

a.it("should be able to pass basic checkhealth without errors", function()
vim.cmd "set cmdheight&"
vim.cmd "checkhealth nvim"
local errmsg = vim.fn.eval "v:errmsg"
local exception = vim.fn.eval "v:exception"
assert.equal("", errmsg) -- v:errmsg was not updated.
assert.equal("", exception)
end)
a.it("should be able to pass basic checkhealth without errors", function()
vim.cmd("set cmdheight&")
vim.cmd("checkhealth nvim")
local errmsg = vim.fn.eval("v:errmsg")
local exception = vim.fn.eval("v:exception")
assert.equal("", errmsg) -- v:errmsg was not updated.
assert.equal("", exception)
end)
end)
6 changes: 3 additions & 3 deletions utils/bin/qvim.template
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/usr/bin/env bash

export QUANTUMVIM_RTP_DIR="${QUANTUMVIM_RTP_DIR:-RTP_DIR_VAR}"
export QUANTUMVIM_CONFIG_DIR="${QUANTUMVIM_CONFIG_DIR:-CONFIG_DIR_VAR}"
export QUANTUMVIM_STATE_DIR="${QUANTUMVIM_CACHE_DIR:-DATA_DIR_VAR}"
export QUANTUMVIM_DATA_DIR="${QUANTUMVIM_DATA_DIR:-STATE_DIR_VAR}"
export QUANTUMVIM_DATA_DIR="${QUANTUMVIM_DATA_DIR:-DATA_DIR_VAR}"
export QUANTUMVIM_CACHE_DIR="${QUANTUMVIM_CACHE_DIR:-CACHE_DIR_VAR}"
export NVIM_APPNAME="${NVIM_APPNAME:-APPNAME_VAR}"

exec -a qvim nvim -u "$QUANTUMVIM_CONFIG_DIR/init.lua" "$@"
exec -a qvim nvim -u "$QUANTUMVIM_RTP_DIR/init.lua" "$@"
25 changes: 14 additions & 11 deletions utils/ci/run_test.sh
Original file line number Diff line number Diff line change
@@ -1,33 +1,36 @@
#!/usr/bin/env bash
set -e

export XDG_STATE_HOME="$HOME/.local/state"

export QV_FIRST_TIME_SETUP=1
export QUANTUMVIM_CONFIG_DIR="${QUANTUMVIM_CONFIG_DIR:-"$HOME/.config/qvim"}"
export NVIM_APPNAME="${NVIM_APPNAME:-"qvim"}"
export QUANTUMVIM_RTP_DIR="${QUANTUMVIM_RTP_DIR:-"$XDG_STATE_HOME/$NVIM_APPNAME"}"

QUANTUMVIM_CACHE_DIR="$(mktemp -d)"
QUANTUMVIM_STATE_DIR="$(mktemp -d)"
QUANTUMVIM_DATA_DIR="$(mktemp -d)"
QUANTUMVIM_CONFIG_DIR="$(mktemp -d)"

export QUANTUMVIM_CACHE_DIR QUANTUMVIM_STATE_DIR QUANTUMVIM_DATA_DIR
export QUANTUMVIM_CACHE_DIR QUANTUMVIM_STATE_DIR QUANTUMVIM_DATA_DIR QUANTUMVIM_CONFIG_DIR

echo "rtp: $QUANTUMVIM_RTP_DIR"
echo "cache: $QUANTUMVIM_CACHE_DIR"
echo "state: $QUANTUMVIM_STATE_DIR"
echo "data: $QUANTUMVIM_DATA_DIR"
echo "config: $QUANTUMVIM_CONFIG_DIR"

# TODO log dir

mkdir -p "$QUANTUMVIM_STATE_DIR/after/pack/lazy/opt"
git clone https://github.com/nvim-lua/plenary.nvim.git "$QUANTUMVIM_STATE_DIR/after/pack/lazy/opt/plenary"
mkdir -p "$QUANTUMVIM_RTP_DIR/after/pack/lazy/opt"
git clone https://github.com/nvim-lua/plenary.nvim.git "$QUANTUMVIM_RTP_DIR/after/pack/lazy/opt/plenary"

qvim() {
exec -a qvim nvim -u "$QUANTUMVIM_CONFIG_DIR/tests/minimal_init.lua" \
--cmd "set runtimepath+=$QUANTUMVIM_STATE_DIR/after/pack/lazy/opt/plenary" \
"$@"
exec -a qvim nvim -u "$QUANTUMVIM_RTP_DIR/tests/minimal_init.lua" \
--cmd "set runtimepath+=$QUANTUMVIM_RTP_DIR/after/pack/lazy/opt/plenary" \
"$@"
}

if [ -n "$1" ]; then
qvim --headless -c "lua require('plenary.busted').run('$1')"
qvim --headless -c "lua require('plenary.busted').run('$1')"
else
qvim --headless -c "PlenaryBustedDirectory tests/specs { minimal_init = './tests/minimal_init.lua' }"
qvim --headless -c "PlenaryBustedDirectory tests/specs { minimal_init = './tests/minimal_init.lua' }"
fi
File renamed without changes.
40 changes: 22 additions & 18 deletions utils/installer/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ declare -xr INSTALL_PREFIX="${INSTALL_PREFIX:-"$HOME/.local"}"
declare -xr XDG_DATA_HOME="${XDG_DATA_HOME:-"$HOME/.local/share"}"
declare -xr XDG_CACHE_HOME="${XDG_CACHE_HOME:-"$HOME/.cache"}"
declare -xr XDG_CONFIG_HOME="${XDG_CONFIG_HOME:-"$HOME/.config"}"
declare -xr XDG_STATE_HOME="${XDG_STATE_HOME:-"$HOME/.local/state"}"

declare -xr QUANTUMVIM_RTP_DIR="${QUANTUMVIM_RTP_DIR:-"$XDG_STATE_HOME/$NVIM_APPNAME"}"
declare -xr QUANTUMVIM_CACHE_DIR="${QUANTUMVIM_CACHE_DIR:-"$XDG_CACHE_HOME/$NVIM_APPNAME"}"
declare -xr QUANTUMVIM_CONFIG_DIR="${QUANTUMVIM_CONFIG_DIR:-"$XDG_CONFIG_HOME/$NVIM_APPNAME"}"
declare -xr QUANTUMVIM_LOG_LEVEL="${QUANTUMVIM_LOG_LEVEL:-warn}"
Expand All @@ -31,8 +33,10 @@ declare ADDITIONAL_WARNINGS=""
declare USE_SSH=0

declare -a __qvim_dirs=(
"$QUANTUMVIM_RTP_DIR"
"$QUANTUMVIM_CACHE_DIR"
"$QUANTUMVIM_CONFIG_DIR"
# TODO log dir
)

function usage() {
Expand All @@ -51,9 +55,9 @@ function parse_arguments() {
--overwrite)
ARGS_OVERWRITE=1
;;
--ssh)
USE_SSH=1
;;
--ssh)
USE_SSH=1
;;
# Currently no supported dependencies
#-y | --yes)
# INTERACTIVE_MODE=0
Expand Down Expand Up @@ -225,22 +229,22 @@ function clone_qvim() {

if [ "$USE_SSH" -eq 0 ]; then

if ! git clone --branch "$QV_BRANCH" \
"https://github.com/${QV_REMOTE}" "$QUANTUMVIM_CONFIG_DIR"; then
echo "Failed to clone repository. Installation failed."
exit 1
fi
else
if ! git clone --branch "$QV_BRANCH" \
"[email protected]:${QV_REMOTE}" "$QUANTUMVIM_CONFIG_DIR"; then
echo "Failed to clone repository. Installation failed."
exit 1
fi
if ! git clone --branch "$QV_BRANCH" \
"https://github.com/${QV_REMOTE}" "$QUANTUMVIM_RTP_DIR"; then
echo "Failed to clone repository. Installation failed."
exit 1
fi
else
if ! git clone --branch "$QV_BRANCH" \
"[email protected]:${QV_REMOTE}" "$QUANTUMVIM_RTP_DIR"; then
echo "Failed to clone repository. Installation failed."
exit 1
fi
fi
}

function setup_exec() {
make -C "$QUANTUMVIM_CONFIG_DIR" install-bin
make -C "$QUANTUMVIM_RTP_DIR" install-bin
}

function remove_old_cache_files() {
Expand Down Expand Up @@ -271,13 +275,13 @@ function create_desktop_file() {
([ "$OS" != "Linux" ] || ! command -v xdg-desktop-menu &>/dev/null) && return
echo "Creating desktop file"

for d in "$QUANTUMVIM_CONFIG_DIR"/utils/desktop/*/; do
for d in "$QUANTUMVIM_RTP_DIR"/utils/desktop/*/; do
size_folder=$(basename "$d")
mkdir -p "$XDG_DATA_HOME/icons/hicolor/$size_folder/apps/"
cp "$QUANTUMVIM_CONFIG_DIR/utils/desktop/$size_folder/$NVIM_APPNAME.svg" "$XDG_DATA_HOME/icons/hicolor/$size_folder/apps"
cp "$QUANTUMVIM_RTP_DIR/utils/desktop/$size_folder/$NVIM_APPNAME.svg" "$XDG_DATA_HOME/icons/hicolor/$size_folder/apps"
done

xdg-desktop-menu install --novendor "$QUANTUMVIM_CONFIG_DIR/utils/desktop/$NVIM_APPNAME.desktop" || true
xdg-desktop-menu install --novendor "$QUANTUMVIM_RTP_DIR/utils/desktop/$NVIM_APPNAME.desktop" || true
}

function print_logo() {
Expand Down
28 changes: 14 additions & 14 deletions utils/installer/install_bin.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,28 @@ XDG_CACHE_HOME="${XDG_CACHE_HOME:-"$HOME/.cache"}"

QUANTUMVIM_CONFIG_DIR="${QUANTUMVIM_CONFIG_DIR:-"$XDG_CONFIG_HOME/$NVIM_APPNAME"}"
QUANTUMVIM_DATA_DIR="${QUANTUMVIM_DATA_DIR:-"$XDG_DATA_HOME/$NVIM_APPNAME"}"
QUANTUMVIM_STATE_DIR="${QUANTUMVIM_STATE_DIR:-"$XDG_STATE_HOME/$NVIM_APPNAME"}"
QUANTUMVIM_RTP_DIR="${QUANTUMVIM_RTP_DIR:-"$XDG_STATE_HOME/$NVIM_APPNAME"}"
QUANTUMVIM_CACHE_DIR="${QUANTUMVIM_CACHE_DIR:-"$XDG_CACHE_HOME/$NVIM_APPNAME"}"

function setup_qvim() {
local src="$QUANTUMVIM_CONFIG_DIR/utils/bin/${NVIM_APPNAME}.template"
local dst="$INSTALL_PREFIX/bin/${NVIM_APPNAME}"
local src="$QUANTUMVIM_RTP_DIR/utils/bin/${NVIM_APPNAME}.template"
local dst="$INSTALL_PREFIX/bin/${NVIM_APPNAME}"

[ ! -d "$INSTALL_PREFIX/bin" ] && mkdir -p "$INSTALL_PREFIX/bin"
[ ! -d "$INSTALL_PREFIX/bin" ] && mkdir -p "$INSTALL_PREFIX/bin"

# remove outdated installation so that `cp` doesn't complain
rm -f "$dst"
# remove outdated installation so that `cp` doesn't complain
rm -f "$dst"

cp "$src" "$dst"
cp "$src" "$dst"

sed -e s"#CONFIG_DIR_VAR#\"${QUANTUMVIM_CONFIG_DIR}\"#"g \
-e s"#DATA_DIR_VAR#\"${QUANTUMVIM_DATA_DIR}\"#"g \
-e s"#STATE_DIR_VAR#\"${QUANTUMVIM_STATE_DIR}\"#"g \
-e s"#CACHE_DIR_VAR#\"${QUANTUMVIM_CACHE_DIR}\"#"g \
-e s"#APPNAME_VAR#\"${NVIM_APPNAME}\"#"g "$src" \
| tee "$dst" >/dev/null
sed -e s"#CONFIG_DIR_VAR#\"${QUANTUMVIM_CONFIG_DIR}\"#"g \
-e s"#DATA_DIR_VAR#\"${QUANTUMVIM_DATA_DIR}\"#"g \
-e s"#STATE_DIR_VAR#\"${QUANTUMVIM_STATE_DIR}\"#"g \
-e s"#CACHE_DIR_VAR#\"${QUANTUMVIM_CACHE_DIR}\"#"g \
-e s"#APPNAME_VAR#\"${NVIM_APPNAME}\"#"g "$src" \
| tee "$dst" >/dev/null

chmod u+x "$dst"
chmod u+x "$dst"
}

setup_qvim "$@"
Expand Down

0 comments on commit ef81b62

Please sign in to comment.