#!/usr/bin/env bash # # start-vim-coc.sh — launch Vim with a minimal config that loads nuwiki # through coc.nvim (instead of vim-lsp). # # The plugin's Vim path (autoload/nuwiki/lsp.vim) prefers `vim-lsp` and falls # back to `coc.nvim`. start-vim.sh exercises the vim-lsp path; this script # exercises the coc.nvim path. vim-lsp is deliberately kept OFF the runtimepath # so `:LspDefinition` doesn't exist and nuwiki's coc branch is the one that runs # (s:jump_definition() → CocActionAsync('jumpDefinition', 'edit')). # # This doubles as a reproducer for the " opens a new tab" regression: # coc-settings.json sets coc.preferences.jumpCommand to `tabe`, so without the # fix `` on a link opens a new tab. With the fix nuwiki passes 'edit' # explicitly and the target opens in the *current* window regardless. # # It clones coc.nvim's prebuilt `release` branch into the dev cache on first # run (no yarn/build needed — it just needs Node.js at runtime). # # Usage: ./development/start-vim-coc.sh [extra args...] # ./development/start-vim-coc.sh # open the scratch wiki's index # ./development/start-vim-coc.sh path/to/note.wiki # open a specific file # NUWIKI_DEV_WIKI=/tmp/foo ./development/start-vim-coc.sh # NUWIKI_DEV_NO_SEED=1 ./development/start-vim-coc.sh # use WIKI_DIR as-is (no scratch seeding) # NUWIKI_DEV_SKIP_BUILD=1 ./development/start-vim-coc.sh # reuse the cached binary # NUWIKI_DEV_COC_JUMP=edit ./development/start-vim-coc.sh # change coc.preferences.jumpCommand # # 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. # # Each launch starts clean: the scratch wiki is reseeded from a pristine # copy and the editor state (viminfo/swap/undo, coc data) is wiped, so stale # edits never carry over. The cached coc.nvim clone is kept. A wiki you point # at with NUWIKI_DEV_WIKI is never wiped (seeded only if empty). # # Tested with Vim 9.1+ and Node 18+. State (viminfo/sessions, coc data) lives # under $XDG_CACHE_HOME/nuwiki-dev/ so your real Vim 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" VIMRC="$DEV_DIR/vimrc-coc" VIM_STATE="$DEV_DIR/vim-coc-state" COC_DIR="$DEV_DIR/coc.nvim" COC_DATA="$DEV_DIR/coc-data" COC_SETTINGS="$DEV_DIR/coc-settings.json" COC_JUMP="${NUWIKI_DEV_COC_JUMP:-tabe}" ensure_node() { if ! command -v node >/dev/null 2>&1; then log 'node not found — coc.nvim needs Node.js at runtime; skipping' exit 0 fi } ensure_coc() { mkdir -p "$DEV_DIR" if [[ -d "$COC_DIR/.git" ]]; then return fi if ! command -v git >/dev/null 2>&1; then log 'git not found — cannot clone coc.nvim; skipping' exit 0 fi log "cloning coc.nvim (release branch) → $COC_DIR" git clone --depth 1 --branch release \ https://github.com/neoclide/coc.nvim.git "$COC_DIR" >/dev/null 2>&1 } write_coc_settings() { mkdir -p "$DEV_DIR" # Mirror what the vim-lsp client sends (autoload/nuwiki/lsp.vim s:settings()): # both `initializationOptions` (sent on initialize) and `settings.nuwiki` # (served via workspace/configuration). Without these the server falls back # to its own default wiki_root (~/vimwiki) instead of $WIKI_DIR, so it can't # resolve links (e.g. Notes shows as broken) or create-on-follow correctly. # toc_header_level / html_header_numbering are set to non-defaults so the # dev wiki exercises them: :NuwikiTOC writes `== Contents ==` (level 2) and # HTML export numbers headings. coc reads this file verbatim, so these are # the values the server actually receives. cat > "$COC_SETTINGS" < "$VIMRC" <