Hi,

Last week I received an email from Thanos Tsouanas (in CC) pointing out
something fishy in the Neovim package we shipped with 7.6.

In summary, we were not installing the treesitter parsers in our neovim package
and this meant that (unless you install the treesitter plugin using a nvim
package manager), you'd get a big ol' Lua stacktrace about a missing parser
when you opened a file written in a language that ought to have a parser
bundled (e.g. Lua).

I never noticed this because my personal config uses the treesitter plugin,
which automagically installs the parsers if they are absent.

I discussed with upstream here:
https://github.com/neovim/neovim/issues/30761

The diff below is the minimal fix, adapted from FreeBSD ports. It should
probably be backported to -stable after a period of testing in -current.

Fixes one failing test too.

Please test. Comments, OK?

P.S. 

Applying this fix has forced me to revisit the neovim build system, and I think
it may actually be possible to simplify the port quite a bit, but that's a
larger change that should be handled separately.

P.P.S.:

Why does lld take so long to link nvim?


Index: Makefile
===================================================================
RCS file: /cvs/ports/editors/neovim/Makefile,v
diff -u -p -r1.48 Makefile
--- Makefile    10 Oct 2024 13:41:09 -0000      1.48
+++ Makefile    12 Oct 2024 12:28:04 -0000
@@ -12,6 +12,7 @@ EMBED_LUAJIT =        No
 COMMENT =      continuation and extension of Vim
 
 DIST_TUPLE =   github neovim neovim v0.10.2 .
+REVISION =     0
 
 # embedded luajit
 USE_NOBTCFI =  Yes
@@ -27,6 +28,18 @@ DIST_TUPLE +=        github LuaJIT LuaJIT 75e92
                ${STATIC_DEPS_WRKSRC}/luajit
 DIST_TUPLE +=  github keplerproject lua-compat-5.3 v0.13 \
                ${STATIC_DEPS_WRKSRC}/lua-compat-5.3
+DIST_TUPLE +=  github tree-sitter tree-sitter-c v0.21.3 \
+               ${STATIC_DEPS_WRKSRC}/parsers/treesitter_c
+DIST_TUPLE +=  github tree-sitter-grammars tree-sitter-lua v0.1.0 \
+               ${STATIC_DEPS_WRKSRC}/parsers/treesitter_lua
+DIST_TUPLE +=  github neovim tree-sitter-vim v0.4.0 \
+               ${STATIC_DEPS_WRKSRC}/parsers/treesitter_vim
+DIST_TUPLE +=  github neovim tree-sitter-vimdoc v3.0.0 \
+               ${STATIC_DEPS_WRKSRC}/parsers/treesitter_vimdoc
+DIST_TUPLE +=  github tree-sitter-grammars tree-sitter-query v0.4.0 \
+               ${STATIC_DEPS_WRKSRC}/parsers/treesitter_query
+DIST_TUPLE +=  github MDeiml tree-sitter-markdown v0.2.3 \
+               ${STATIC_DEPS_WRKSRC}/parsers/treesitter_markdown
 
 # Neovim: Apache 2.0 + Vim License
 # LuaJIT: MIT + public domain
@@ -113,6 +126,7 @@ TEST_DEPENDS =      shells/bash \
 # makes sense to embed it.
 STATIC_DEPS_WRKBUILD=${WRKBUILD}/static-deps-build
 STATIC_DEPS_INST=${WRKBUILD}/static-deps-inst
+PARSERS_WRKBUILD=${STATIC_DEPS_WRKBUILD}/parsers
 .include <bsd.port.arch.mk>
 .if ${PROPERTIES:Mclang}
 LUAJIT_TARGET_LIBS =   "-lc++abi -lpthread"
@@ -164,6 +178,24 @@ pre-configure:
        cd ${STATIC_DEPS_WRKBUILD}/luv && \
                ${SETENV} ${MAKE_ENV} VERBOSE=1 \
                ${MAKE_PROGRAM} install
+
+       # Build the treesitter parsers.
+       #
+       # For this we borrow a trick from FreeBSD and re-use just the part of
+       # upstream's build system that builds the parsers.
+       mkdir -p ${PARSERS_WRKBUILD}/build/src
+       for i in ${STATIC_DEPS_WRKSRC}/parsers/*; do \
+               cp -r $${i} ${PARSERS_WRKBUILD}/build/src/$$(basename $$i); \
+               done
+       ${MAKE_ENV} ${LOCALBASE}/bin/cmake -S ${WRKSRC}/cmake.deps \
+               -B ${PARSERS_WRKBUILD} ${CONFIGURE_ARGS} \
+               -DUSE_BUNDLED_TS_PARSERS=ON \
+               -DUSE_EXISTING_SRC_DIR:BOOL=ON
+       # The following line both builds *and* installs the parsers.
+       ${MAKE_ENV} ${LOCALBASE}/bin/cmake --build ${PARSERS_WRKBUILD}
+       mkdir -p ${WRKBUILD}/lib/nvim/parser
+       cp -r ${PARSERS_WRKBUILD}/usr/lib/nvim/parser/*.so \
+               ${WRKBUILD}/lib/nvim/parser/
 
 # These are the "old tests". There is also a new suite, but we would need the
 # "busted" test suite for Lua, which is not yet ported.
Index: distinfo
===================================================================
RCS file: /cvs/ports/editors/neovim/distinfo,v
diff -u -p -r1.27 distinfo
--- distinfo    10 Oct 2024 13:41:09 -0000      1.27
+++ distinfo    11 Oct 2024 18:21:33 -0000
@@ -1,8 +1,20 @@
 SHA256 (LuaJIT-LuaJIT-75e92777988017fe47c5eb290998021bbf972d1f.tar.gz) = 
D2kogZACTXMsZ2ReQO1bE31nqpUP7fD0SprQ89um1dI=
+SHA256 (MDeiml-tree-sitter-markdown-v0.2.3.tar.gz) = 
SQnWAjZD8a/DqyGVhdQDW3QD86F4SXgquAPF9zyKMdU=
 SHA256 (keplerproject-lua-compat-5.3-v0.13.tar.gz) = 
9dww57H9qFbuTTkr5FdkLB8MJZJkqbm/vLaAMCzoj8I=
 SHA256 (luvit-luv-1.48.0-2.tar.gz) = 
5kzYoBl0SSiLN99soFgSDo0jCPwwX1QxYrW/PpInOgU=
 SHA256 (neovim-neovim-v0.10.2.tar.gz) = 
VGyy2p//u36RMmE0S79M8WInIfbFpnqndgnpdueLjok=
+SHA256 (neovim-tree-sitter-vim-v0.4.0.tar.gz) = 
n4Vvi0oQq0M0hVD6LTyyhGrj2OYPRYhyAFScBRxm+dU=
+SHA256 (neovim-tree-sitter-vimdoc-v3.0.0.tar.gz) = 
pjm/kr9Xv6HNyQyhavJ7+vJql3kGR3bdS+NMHvFFP2w=
+SHA256 (tree-sitter-grammars-tree-sitter-lua-v0.1.0.tar.gz) = 
Iwz8v6dO0fe4FJ6aHzTC78TFiacf4PXchWBiL4Ag1yI=
+SHA256 (tree-sitter-grammars-tree-sitter-query-v0.4.0.tar.gz) = 
06Qjq2bcYrKWliXigBFmeKiiJYK1/wh3lSIhCNsvam4=
+SHA256 (tree-sitter-tree-sitter-c-v0.21.3.tar.gz) = 
daN4DfYRTNN0lnYcSnyf2QDHi+46Jwf1kNeMDKOiQ2g=
 SIZE (LuaJIT-LuaJIT-75e92777988017fe47c5eb290998021bbf972d1f.tar.gz) = 1081633
+SIZE (MDeiml-tree-sitter-markdown-v0.2.3.tar.gz) = 418293
 SIZE (keplerproject-lua-compat-5.3-v0.13.tar.gz) = 60960
 SIZE (luvit-luv-1.48.0-2.tar.gz) = 134821
 SIZE (neovim-neovim-v0.10.2.tar.gz) = 12801272
+SIZE (neovim-tree-sitter-vim-v0.4.0.tar.gz) = 356704
+SIZE (neovim-tree-sitter-vimdoc-v3.0.0.tar.gz) = 58110
+SIZE (tree-sitter-grammars-tree-sitter-lua-v0.1.0.tar.gz) = 56812
+SIZE (tree-sitter-grammars-tree-sitter-query-v0.4.0.tar.gz) = 42944
+SIZE (tree-sitter-tree-sitter-c-v0.21.3.tar.gz) = 366957
Index: pkg/PLIST
===================================================================
RCS file: /cvs/ports/editors/neovim/pkg/PLIST,v
diff -u -p -r1.23 PLIST
--- pkg/PLIST   10 Oct 2024 13:41:09 -0000      1.23
+++ pkg/PLIST   12 Oct 2024 11:42:43 -0000
@@ -1,5 +1,13 @@
 @bin bin/nvim
 lib/nvim/
+lib/nvim/parser/
+@so lib/nvim/parser/c.so
+@so lib/nvim/parser/lua.so
+@so lib/nvim/parser/markdown.so
+@so lib/nvim/parser/markdown_inline.so
+@so lib/nvim/parser/query.so
+@so lib/nvim/parser/vim.so
+@so lib/nvim/parser/vimdoc.so
 @man man/man1/nvim.1
 share/applications/nvim.desktop
 share/doc/pkg-readmes/${PKGSTEM}

-- 
Best Regards
Edd Barrett

https://www.theunixzoo.co.uk

Reply via email to