09b9bd98a3
Three reasons the plugin wasn't activating on `nvim --clean -u init.lua
foo.wiki`:
1. **File-name mismatch.** Vim's filetype-plugin runtime looks for
`ftplugin/<filetype>.vim` matching the *filetype name*. Our
filetype is `vimwiki` (per `ftdetect`) but the file was named
`ftplugin/nuwiki.vim` — so `:runtime! ftplugin/vimwiki.vim` from
the built-in FileType autocmd never found it, and none of the
`:Vimwiki*` / `:Nuwiki*` commands got defined. Same wart on the
syntax side. Renamed:
- `ftplugin/nuwiki.vim` → `ftplugin/vimwiki.vim`
- `syntax/nuwiki.vim` → `syntax/vimwiki.vim`
2. **`setfiletype` deferred to Neovim's bundled rule.** Neovim ships
a default `*.wiki → mediawiki` rule via `vim.filetype.add`, and
`:setfiletype vimwiki` is a no-op once a filetype has been set.
- `ftdetect/nuwiki.vim` now uses `set filetype=vimwiki` (force).
- `lua/nuwiki/init.lua`'s `setup()` also calls
`vim.filetype.add({ extension = { wiki = 'vimwiki', ... } })`
so the modern table-based detection picks us before the
bundled rule fires. Honours `config.options.file_extension`
so a user with a custom extension gets covered automatically.
3. **`foldmethod`/`foldexpr` are window-local options.**
`ftplugin.lua` was setting them with `nvim_set_option_value({ buf
= bufnr })`, which threw `'buf' cannot be passed for window-local
option 'foldmethod'` and aborted the rest of the per-buffer
attach. Switched to `vim.opt_local.*` (window-aware), applied on
the current window when the ftplugin fires, and re-applied via a
`BufWinEnter` autocmd so `:split` / `:vsplit` keep the fold mode.
Verified end-to-end with:
nvim --clean -u init.lua sample.wiki
→ filetype = vimwiki
→ :VimwikiTOC, :NuwikiIndex, … all defined
→ foldmethod = expr, foldexpr = v:lua.vim.lsp.foldexpr()
→ ftdetect, plugin, ftplugin, syntax all in :scriptnames
Total 377 tests still pass.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
44 lines
1.2 KiB
Lua
44 lines
1.2 KiB
Lua
-- lua/nuwiki/init.lua — Neovim entry point.
|
|
--
|
|
-- Public surface:
|
|
-- require('nuwiki').setup(opts) — apply user config + register LSP
|
|
-- require('nuwiki').install() — install / build the language server
|
|
-- require('nuwiki').health() — :checkhealth nuwiki target
|
|
--
|
|
-- Per SPEC §6.2/§6.3 this layer is wiring only. Everything substantive
|
|
-- happens in the Rust language server.
|
|
|
|
local M = {}
|
|
|
|
local config = require('nuwiki.config')
|
|
local lsp = require('nuwiki.lsp')
|
|
|
|
function M.setup(opts)
|
|
config.apply(opts or {})
|
|
|
|
-- Neovim 0.7+ resolves filetypes via `vim.filetype.match` before any
|
|
-- `ftdetect/*.vim` autocmd fires, and its bundled rule for `*.wiki`
|
|
-- returns `mediawiki`. Register an authoritative rule here so this
|
|
-- plugin's filetype (vimwiki) wins.
|
|
if vim.filetype and vim.filetype.add then
|
|
local extensions = { wiki = 'vimwiki' }
|
|
local ext = (config.options.file_extension or '.wiki'):gsub('^%.', '')
|
|
if ext ~= 'wiki' and ext ~= '' then
|
|
extensions[ext] = 'vimwiki'
|
|
end
|
|
vim.filetype.add({ extension = extensions })
|
|
end
|
|
|
|
lsp.register()
|
|
end
|
|
|
|
function M.install()
|
|
return require('nuwiki.install').install()
|
|
end
|
|
|
|
function M.health()
|
|
return require('nuwiki.health').check()
|
|
end
|
|
|
|
return M
|