Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nvim-treesitter[latex]: Error during compilation #1314

Open
3 tasks done
kevin1sMe opened this issue Jun 29, 2024 · 30 comments
Open
3 tasks done

nvim-treesitter[latex]: Error during compilation #1314

kevin1sMe opened this issue Jun 29, 2024 · 30 comments
Labels
bug Something isn't working treesitter Treesitter related issues

Comments

@kevin1sMe
Copy link

Version confirmation

  • Confirm

Following prerequisites

  • Confirm

Not a user config issue

  • 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 kevin1sMe added the bug Something isn't working label Jun 29, 2024
@Jint-lzxy
Copy link
Collaborator

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

@Jint-lzxy Jint-lzxy added the treesitter Treesitter related issues label Jun 29, 2024
@kevin1sMe
Copy link
Author

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

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

@kevin1sMe
Copy link
Author

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?

@ayamir
Copy link
Owner

ayamir commented Jun 30, 2024

You can continue the installation process by :TSUpdate.

@kevin1sMe
Copy link
Author

You can continue the installation process by :TSUpdate.

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

@CharlesChiuGit
Copy link
Collaborator

CharlesChiuGit commented Jul 1, 2024

in branch 0.10 should include

pkgs.tree-sitter
already.

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

@misumisumi
Copy link
Collaborator

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.

@kevin1sMe
Copy link
Author

kevin1sMe commented Jul 1, 2024

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

@Cyberczy
Copy link
Contributor

Cyberczy commented Jul 1, 2024

just install tree-sitter and tree-sitter-cli

@CharlesChiuGit
Copy link
Collaborator

CharlesChiuGit commented Jul 1, 2024

just install tree-sitter and tree-sitter-cli

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

@Cyberczy
Copy link
Contributor

Cyberczy commented Jul 1, 2024

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

@CharlesChiuGit
Copy link
Collaborator

CharlesChiuGit commented Jul 1, 2024

r u also using nixpkgs/home-manager?

@Cyberczy
Copy link
Contributor

Cyberczy commented Jul 1, 2024

Sorry, I didn't realize using nix

@misumisumi
Copy link
Collaborator

misumisumi commented Jul 1, 2024

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.

@kevin1sMe
Copy link
Author

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.

@misumisumi
Copy link
Collaborator

it doesn't always reproduce.

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

@kevin1sMe
Copy link
Author

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.

@Jint-lzxy
Copy link
Collaborator

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
Copy link
Author

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.

@Jint-lzxy
Copy link
Collaborator

Jint-lzxy commented Jul 4, 2024

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.

@misumisumi
Copy link
Collaborator

misumisumi commented Jul 4, 2024

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.

@Jint-lzxy
Copy link
Collaborator

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
Copy link
Collaborator

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 #1314 (comment).

@Jint-lzxy
Copy link
Collaborator

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
Copy link
Collaborator

if treesitter-cli is solving it

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

@misumisumi
Copy link
Collaborator

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
Copy link
Collaborator

misumisumi commented Jul 5, 2024

@kevin1sMe
What version of home-manager are you using?.
Also, if possible, could you please share the settings for programs.neovim.nvimdots?
Also, does #1314 (comment) succeed when executed from neovim's terminal?
This part is especially important.
image

@Jint-lzxy
Copy link
Collaborator

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.

@kevin1sMe
Copy link
Author

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
  };
}

@misumisumi
Copy link
Collaborator

Thank you. I just wanted to check.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working treesitter Treesitter related issues
Projects
None yet
Development

No branches or pull requests

6 participants