Files
nuwiki/development/start-nvim.sh
T

97 lines
3.2 KiB
Bash
Raw Normal View History

#!/usr/bin/env bash
#
# start-nvim.sh — launch Neovim with a minimal config that loads nuwiki.
#
# Builds the language server (release mode), symlinks it into `bin/` so
# the plugin's default install path resolves, then spawns Neovim with
# `--clean` and a generated `init.lua` that:
# * adds this repo to `runtimepath`
# * configures wiki_root to a scratch directory under
# $XDG_CACHE_HOME/nuwiki-dev/wiki
# * calls `require('nuwiki').setup({...})`
#
# Usage: ./development/start-nvim.sh [extra args...]
# ./development/start-nvim.sh # open the scratch wiki's index
# ./development/start-nvim.sh path/to/note.wiki # open a specific file
# NUWIKI_DEV_WIKI=/tmp/foo ./development/start-nvim.sh
# NUWIKI_DEV_NO_SEED=1 ./development/start-nvim.sh # use WIKI_DIR as-is (no scratch seeding)
# NUWIKI_DEV_SKIP_BUILD=1 ./development/start-nvim.sh # reuse the cached binary
#
# The release binary is rebuilt on every launch so source changes
# always reach the running LSP. `cargo build --release` is incremental,
# so this is a fast no-op when nothing changed. Set
# NUWIKI_DEV_SKIP_BUILD=1 to skip the build step entirely.
#
# Each launch starts clean: the scratch wiki is reseeded from a pristine
# copy and the editor state (cache/data/config) is wiped, so stale edits
# never carry over. A wiki you point at with NUWIKI_DEV_WIKI is never wiped
# (seeded only if empty).
#
# Tested with Neovim 0.10+. State (cache/data/config) lives under
# $XDG_CACHE_HOME/nuwiki-dev/ so your real Neovim install stays
# untouched.
set -euo pipefail
# Shared paths + helpers (log, ensure_binary, write_sample_wiki, seed_wiki).
source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/_common.sh"
INIT_FILE="$DEV_DIR/init.lua"
STATE_DIR="$DEV_DIR/nvim-state"
DATA_DIR="$DEV_DIR/nvim-data"
CONFIG_DIR="$DEV_DIR/nvim-config"
write_init() {
mkdir -p "$DEV_DIR"
cat > "$INIT_FILE" <<EOF
-- start-nvim.sh: generated minimal config for nuwiki development.
-- Regenerated on every launch; edit start-nvim.sh, not this file.
-- Confine state to the dev cache so we never touch the user's real
-- Neovim install.
vim.env.XDG_STATE_HOME = '$STATE_DIR'
vim.env.XDG_DATA_HOME = '$DATA_DIR'
vim.env.XDG_CONFIG_HOME = '$CONFIG_DIR'
vim.opt.runtimepath:prepend('$REPO_ROOT')
vim.g.nuwiki_binary_path = '$REPO_ROOT/bin/nuwiki-ls'
-- Friendly defaults for an interactive smoke test.
vim.opt.number = true
vim.opt.signcolumn = 'yes'
vim.opt.termguicolors = true
vim.opt.swapfile = false
vim.opt.writebackup = false
vim.opt.undofile = false
vim.g.mapleader = ' '
require('nuwiki').setup({
wiki_root = '$WIKI_DIR',
})
-- Surface log lines (the LSP logs via window/logMessage). Without this
-- they're swallowed; with it they land in :messages.
vim.lsp.set_log_level('info')
print('[nuwiki-dev] ready — wiki root: $WIKI_DIR')
print('[nuwiki-dev] :LspInfo to inspect, :checkhealth nuwiki for diagnostics')
EOF
}
main() {
ensure_binary
seed_wiki
write_init
reset_dirs "$STATE_DIR" "$DATA_DIR" "$CONFIG_DIR"
log "launching: nvim --clean -u $INIT_FILE"
if [[ $# -gt 0 ]]; then
exec nvim --clean -u "$INIT_FILE" "$@"
else
exec nvim --clean -u "$INIT_FILE" "$WIKI_DIR/index.wiki"
fi
}
main "$@"