Files
nuwiki/scripts/download_bin.vim
gffranco ee61d40872
CI / cargo fmt --check (push) Successful in 30s
CI / cargo clippy (push) Successful in 1m23s
CI / cargo test (push) Successful in 1m29s
phase 9: editor glue — plugin, LSP wiring, install, health, docs
P5 + P6 resolved (SPEC §11): Neovim 0.11+ and Vim 9.1+.

Universal Vim entry:
- plugin/nuwiki.vim dispatches Vim vs Neovim. Neovim path waits for
  the user's `require('nuwiki').setup()` call; Vim path starts the
  LSP client on `FileType vimwiki` and exposes `:NuwikiInstall`.
- ftdetect/nuwiki.vim associates `*.wiki` with the `vimwiki` filetype.
- ftplugin/nuwiki.vim sets commentstring + comments + formatoptions +
  suffixesadd + iskeyword, with a clean `b:undo_ftplugin`.
- syntax/nuwiki.vim ships default `@vimwiki*` highlight links for the
  semantic-token legend (with `level1..6` + `centered` modifiers),
  plus a minimal regex fallback so static highlighting works before
  the LSP attaches.

Lua glue (Neovim 0.11+):
- init.lua exposes setup() / install() / health() — wiring only per
  SPEC §6.2.
- config.lua holds the §7.5 schema (wiki_root / file_extension /
  syntax / log_level) and a tbl_deep_extend apply().
- lsp.lua registers via `vim.lsp.config{} + vim.lsp.enable` on 0.11+;
  falls back to a FileType autocmd calling `vim.lsp.start` on older
  builds. Root dir walks up for `.git` / `.nuwiki`, then uses
  wiki_root.
- install.lua does target-triple detection (Linux gnu/musl x x86_64/
  aarch64, macOS arm/x86, Windows), curl+tar download from the
  release URL, cp/chmod into bin/, with a cargo fallback. Honours
  `g:nuwiki_build_from_source`.
- health.lua implements `:checkhealth nuwiki` per §7.6.

VimL glue (Vim 9.1+):
- autoload/nuwiki/lsp.vim follows §7.4 preference order:
  vim-lsp (calls `lsp#register_server`) → coc.nvim (prints the
  coc-settings.json snippet) → error.
- scripts/download_bin.vim mirrors the Lua installer for Dein /
  vim-plug build hooks — same target triples, same download →
  fallback → cargo build chain.

Help: doc/nuwiki.txt with tags for install (lazy.nvim / vim-plug /
Dein), config options, health, LSP feature list, `:NuwikiInstall`.

Rust workspace unchanged this phase; 172 tests still green locally.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-11 00:38:09 +00:00

89 lines
3.0 KiB
VimL

" scripts/download_bin.vim — install `nuwiki-ls` from a release tarball,
" falling back to `cargo build --release` on failure.
"
" Invoked by Dein / vim-plug build hooks:
" vim -e -s -c "source scripts/download_bin.vim" -c "q"
let s:plugin_dir = fnamemodify(resolve(expand('<sfile>:p')), ':h:h')
let s:bin_dir = s:plugin_dir . '/bin'
let s:suffix = has('win32') ? '.exe' : ''
let s:bin = s:bin_dir . '/nuwiki-ls' . s:suffix
call mkdir(s:bin_dir, 'p')
function! s:target() abort
if has('win32')
return 'x86_64-pc-windows-msvc'
elseif has('mac')
if has('arm64')
return 'aarch64-apple-darwin'
endif
return 'x86_64-apple-darwin'
elseif has('linux')
let l:ldd = system('ldd --version 2>&1')
let l:musl = stridx(l:ldd, 'musl') >= 0
let l:uname_m = trim(system('uname -m'))
if l:uname_m ==# 'aarch64' || l:uname_m ==# 'arm64'
return l:musl ? 'aarch64-unknown-linux-musl' : 'aarch64-unknown-linux-gnu'
endif
return l:musl ? 'x86_64-unknown-linux-musl' : 'x86_64-unknown-linux-gnu'
endif
return ''
endfunction
function! s:build_from_source() abort
if !executable('cargo')
echohl ErrorMsg | echom 'nuwiki: cargo not found, cannot build from source' | echohl None
return 0
endif
echom 'nuwiki: cargo build --release …'
call system('cargo build --release -p nuwiki-ls --manifest-path ' . shellescape(s:plugin_dir . '/Cargo.toml'))
if v:shell_error != 0
echohl ErrorMsg | echom 'nuwiki: cargo build failed' | echohl None
return 0
endif
let l:built = s:plugin_dir . '/target/release/nuwiki-ls' . s:suffix
call system('cp ' . shellescape(l:built) . ' ' . shellescape(s:bin))
call system('chmod +x ' . shellescape(s:bin))
return executable(s:bin)
endfunction
function! s:download_release() abort
let l:target = s:target()
if empty(l:target)
return 0
endif
if !executable('curl') || !executable('tar')
return 0
endif
let l:url = 'https://code.gfran.co/gffranco/nuwiki/releases/latest/download/nuwiki-ls-'
\ . l:target . '.tar.gz'
let l:archive = tempname() . '.tar.gz'
call system('curl -fsSL -o ' . shellescape(l:archive) . ' ' . shellescape(l:url))
if v:shell_error != 0
return 0
endif
let l:extract = tempname()
call mkdir(l:extract, 'p')
call system('tar -xzf ' . shellescape(l:archive) . ' -C ' . shellescape(l:extract))
if v:shell_error != 0
return 0
endif
call system('cp ' . shellescape(l:extract . '/nuwiki-ls' . s:suffix) . ' ' . shellescape(s:bin))
call system('chmod +x ' . shellescape(s:bin))
return executable(s:bin)
endfunction
if get(g:, 'nuwiki_build_from_source', 0)
if !s:build_from_source()
echohl ErrorMsg | echom 'nuwiki: source build failed' | echohl None
endif
elseif s:download_release()
echom 'nuwiki: installed ' . s:bin
else
echohl WarningMsg | echom 'nuwiki: download failed, falling back to source build' | echohl None
if !s:build_from_source()
echohl ErrorMsg | echom 'nuwiki: install failed' | echohl None
endif
endif