nvimdots icon indicating copy to clipboard operation
nvimdots copied to clipboard

nvim-treesitter[latex]: Error during compilation

Open kevin1sMe opened this issue 1 year ago • 30 comments

Version confirmation

  • [X] Confirm

Following prerequisites

  • [X] Confirm

Not a user config issue

  • [X] Confirm

Neovim version

NVIM v0.10.0

Operating system/version

Linux VM-32-9-opencloudos 6.6.30-4.oc9.x86_64

Terminal name/version

iTerm2

$TERM environment variable

xterm-256color

Branch info

0.10 (Nightly)

Fetch Preferences

SSH (use_ssh = true)

How to reproduce the issue

  1. using flake.nix
  2. nvim

Expected behavior

No Error

Actual behavior

bottom line:

  1. nvim-treesitter[latex]
  2. [nvim-treesitter] [0/1] Generating source files from grammar.js...
nvim-treesitter[latex]: Error during compilation
cc1: fatal error: src/parser.c: No such file or directory
compilation terminated.
src/scanner.c:4:10: fatal error: tree_sitter/parser.h: No such file or directory
    4 | #include <tree_sitter/parser.h>
      |          ^~~~~~~~~~~~~~~~~~~~~~
compilation terminated.

Additional information

No response

kevin1sMe avatar Jun 29 '24 09:06 kevin1sMe

Have u installed the tree-sitter CLI tool as per Wiki:Prerequisites#optional-packages?

Jint-lzxy avatar Jun 29 '24 16:06 Jint-lzxy

Thank you for your reply. The issue persists even after I installed tree-sitter.

$ which tree-sitter
~/.nix-profile/bin/tree-sitter

kevin1sMe avatar Jun 30 '24 00:06 kevin1sMe

I switched to a brand new system, Ubuntu 24.04 TLS, and did a fresh installation. This time, I didn't interrupt nvim during its first startup, and it finally succeeded. [nvim-treesitter] [1/1] Treesitter parser for latex has been installed.

I suspect that interrupting nvim during its first startup previously may have caused some intermediate state issues?

kevin1sMe avatar Jun 30 '24 01:06 kevin1sMe

You can continue the installation process by :TSUpdate.

ayamir avatar Jun 30 '24 02:06 ayamir

You can continue the installation process by :TSUpdate.

I have used this method before, but it didn't work, the issue persists.

kevin1sMe avatar Jun 30 '24 14:06 kevin1sMe

in branch 0.10 should include https://github.com/ayamir/nvimdots/blob/07a165b3fe16494dbb6616c6c0d4dc247afb50dc/nixos/neovim/default.nix#L173 already.

it weird to see the error shows the parser is still missing. maybe @misumisumi can help?

charliie-dev avatar Jul 01 '24 01:07 charliie-dev

How do you run neovim on nix (home-manager or NixOS) Standalone neovim probably won't work well.

Try the following if you can use nix command. Clone this repo and enter to dev env with running nix develop and run nvim. Then check if tree-sitter compiles.

misumisumi avatar Jul 01 '24 01:07 misumisumi

How do you run neovim on nix (home-manager or NixOS) Standalone neovim probably won't work well.

Try the following if you can use nix command. Clone this repo and enter to dev env with running nix develop and run nvim. Then check if tree-sitter compiles.

Yes, I use home-manager install the pkg tree-sitter & neovim. I'll have a try

kevin1sMe avatar Jul 01 '24 02:07 kevin1sMe

just install tree-sitter and tree-sitter-cli

Cyberczy avatar Jul 01 '24 07:07 Cyberczy

just install tree-sitter and tree-sitter-cli

his using our nixpkgs config, so tree-sitter should be installed.

charliie-dev avatar Jul 01 '24 07:07 charliie-dev

his using our nixpkgs config, so tree-sitter should be installed.

During the morning, when I was installing the computer for my friend, I also encountered this issue.

just install tree-sitter and tree-sitter-cli

It is the solution I came up with at that time lol

Cyberczy avatar Jul 01 '24 07:07 Cyberczy

r u also using nixpkgs/home-manager?

charliie-dev avatar Jul 01 '24 07:07 charliie-dev

Sorry, I didn't realize using nix

Cyberczy avatar Jul 01 '24 07:07 Cyberczy

tree-sitter is already installed. I don't think it's necessary to install anything additionally... tree-sitter is not needed globally, so it can only be run from within neovim.

misumisumi avatar Jul 01 '24 08:07 misumisumi

I've encountered a similar error regardless of whether tree-sitter is installed manually:

nvim-treesitter[latex]: Error during compilation
cc: error: src/parser.c: No such file or directory

Press ENTER or type command to continue

I'm still not sure about the specific cause, and it doesn't always reproduce. If there are no other reports for a while, I think it can be closed.

kevin1sMe avatar Jul 02 '24 05:07 kevin1sMe

it doesn't always reproduce.

What does this mean? Does this mean that the problem may also occur or not occur on home-manager?

misumisumi avatar Jul 02 '24 05:07 misumisumi

it doesn't always reproduce.

What does this mean? Does this mean that the problem may also occur or not occur on home-manager?

I've encountered this issue a few times, but sometimes I am unable to reproduce it, which does indeed conflict with the reproducibility aspect of Nix, but I'm not sure what the cause is.

kevin1sMe avatar Jul 02 '24 07:07 kevin1sMe

I've encountered a similar error regardless of whether tree-sitter is installed manually:

@kevin1sMe No, these are separate issues. This issue (https://github.com/ayamir/nvimdots/issues/1314#issuecomment-2201953801) happens bc there's a problem downloading the parser's source code[^1] (i.e., the C compiler couldn't locate parser.c). On the user side, Treesitter needs to compile parser.c into a shared library. This is where https://github.com/ayamir/nvimdots/issues/1314#issue-2381616549 occurred, as the C compiler couldn't find the required header(s).

[^1]: To be precise, the source is in JavaScript, and it's up to the plugin author to compile it into parser.c and include it with other assets.

Jint-lzxy avatar Jul 03 '24 06:07 Jint-lzxy

Why wouldn't it recover during the next execution? Or why doesn't it redownload? Other parsers download normally; this one frequently has issues.

I've encountered a similar error regardless of whether tree-sitter is installed manually:

@kevin1sMe No, these are separate issues. This issue (#1314 (comment)) happens bc there's a problem downloading the parser's source code1 (i.e., the C compiler couldn't locate parser.c). On the user side, Treesitter needs to compile parser.c into a shared library. This is where #1314 (comment) occurred, as the C compiler couldn't find the required header(s).

Footnotes

  1. To be precise, the source is in JavaScript, and it's up to the plugin author to compile it into parser.c and include it with other assets.

kevin1sMe avatar Jul 04 '24 04:07 kevin1sMe

Why wouldn't it recover during the next execution? Or why doesn't it redownload?

If u meant to install that automatically, the best way is to add it to the ensure_installed list. However, if Treesitter isn't reinstalling parsers after a failed download, it's usually because a corrupted Git repo is still technically a repo (simply checking if the folder exists doesn't reveal if it's broken). The only way to reinstall is to delete the specific parser's source code folder and then restart Neovim.

Other parsers download normally; this one frequently has issues.

afaik latex is the only commonly-used parser that needs to be compiled from its grammar. This involves more than just compiling from a single C source code; u need the entire Treesitter library. If u don't need this parser, just leave it out of the ensure_installed list. Otherwise, u can try executing the following:

git clone --depth 1 https://github.com/latex-lsp/tree-sitter-latex.git \
&& cd tree-sitter-latex \
&& tree-sitter generate \
&& make CFLAGS='-v'

Upon successful compilation, u should see something like this:

/usr/bin/clang -v -Isrc -std=c11 -fPIC   -c -o src/scanner.o src/scanner.c
ar rcs libtree-sitter-latex.a src/scanner.o
/usr/bin/clang  -dynamiclib -Wl,-install_name,/usr/local/lib/libtree-sitter-latex.0.dylib,-rpath,@executable_path/../Frameworks src/scanner.o  -o libtree-sitter-latex.dylib
sed  -e 's|@URL@|https://github.com/latex-lsp/tree-sitter-latex|' \
	-e 's|@VERSION@|0.3.0|' \
	-e 's|@LIBDIR@|/usr/local/lib|' \
	-e 's|@INCLUDEDIR@|/usr/local/include|' \
	-e 's|@REQUIRES@||' \
	-e 's|@ADDITIONAL_LIBS@||' \
	-e 's|=/usr/local|=${prefix}|' \
	-e 's|@PREFIX@|/usr/local|' bindings/c/tree-sitter-latex.pc.in > tree-sitter-latex.pc

Exactly one static and one dynamic library will be generated in the current working directory, named libtree-sitter-latex.[a/so/dylib]. If the build process somehow fails, u'll need to debug it urself, as there must be something wrong with ur build system.

Jint-lzxy avatar Jul 04 '24 06:07 Jint-lzxy

In my environment, the above command will result in an error as reported. However when building from nvim-treesitter (i.e. mentioned in ensure_installed) it builds successfully. I don't know if nvim-treesitter is running a different command or building with different logic. I don't know if parser.c exists somewhere in the nix environment or if treesitter-cli is solving it.

misumisumi avatar Jul 04 '24 09:07 misumisumi

In my environment, the above command will result in an error as reported.

Oops, sorry it looks like I accidentally removed one command. Here's the correct version:

git clone --depth 1 https://github.com/latex-lsp/tree-sitter-latex.git \
&& cd tree-sitter-latex \
&& tree-sitter generate \
&& make CFLAGS='-v'

Jint-lzxy avatar Jul 04 '24 09:07 Jint-lzxy

I don't know if nvim-treesitter is running a different command or building with different logic.

Yes, internally nvim-treesitter calls the actual Treesitter API (libtree-sitter.so) to generate the necessary include files, similar to the tree-sitter generate command mentioned in https://github.com/ayamir/nvimdots/issues/1314#issuecomment-2208551619.

Jint-lzxy avatar Jul 04 '24 09:07 Jint-lzxy

I don't know if parser.c exists somewhere in the nix environment or if treesitter-cli is solving it.

This shouldn't be a problem on our end since parser.c is supposed to be generated by the parser author and included in the repo. Check out https://tree-sitter.github.io/tree-sitter/creating-parsers#dependencies lol

Jint-lzxy avatar Jul 04 '24 09:07 Jint-lzxy

if treesitter-cli is solving it

treesitter-cli simply copies the necessary headers and configurations to the build directory, nothing more.

Jint-lzxy avatar Jul 04 '24 09:07 Jint-lzxy

treesitter-cli simply copies the necessary headers and configurations to the build directory, nothing more.

I confirmed that it was indeed copied under tree-sitter-latex/src. Hmm. Looking at what has been said so far, I am a little wondering if this is a problem in the NIX environment.

misumisumi avatar Jul 05 '24 01:07 misumisumi

@kevin1sMe What version of home-manager are you using?. Also, if possible, could you please share the settings for programs.neovim.nvimdots? Also, does https://github.com/ayamir/nvimdots/issues/1314#issuecomment-2208551619 succeed when executed from neovim's terminal? This part is especially important. image

misumisumi avatar Jul 05 '24 01:07 misumisumi

Hmm. Looking at what has been said so far, I am a little wondering if this is a problem in the NIX environment.

Same here, it really looks like an issue with the author's build system.

Jint-lzxy avatar Jul 05 '24 06:07 Jint-lzxy

programs.neovim.nvimdots

Do you mean this setting?

{pkgs, ...}:
{
  programs.neovim.nvimdots = {
    enable = true;
    setBuildEnv = true;  # Only needed for NixOS
    withBuildTools = true; # Only needed for NixOS
  };
}

kevin1sMe avatar Jul 06 '24 14:07 kevin1sMe

Thank you. I just wanted to check.

misumisumi avatar Jul 06 '24 15:07 misumisumi