nvim-treesitter / nvim-treesitter

Nvim Treesitter configurations and abstraction layer
Apache License 2.0
10.49k stars 881 forks source link

Treesitter failing to compile after being installed #1515

Open ujwal-jain opened 3 years ago

ujwal-jain commented 3 years ago

Describe the bug

I installed neovim on Mac through homebrew and after doing PlugInstall, nvim-treesitter is not compiling the languages.

To Reproduce

Steps to reproduce the behavior:

Install neovim through homebrew Install Plug package manager for neovim Add Plug 'nvim-treesitter/nvim-treesitter' to the init.vim Type nvim in the command line At the bottom, the status for treesitter will be downloading, then compiling, then will result in errors.

Expected behavior

Should just compile and do syntax highlighting...

Output of :checkhealth nvim_treesitter

health#nvim_treesitter#check
========================================================================
## Installation
  - OK: `tree-sitter` found  0.20.0 (parser generator, only needed for :TSInstallFromGrammar)
  - WARNING: `node` executable not found (only needed for :TSInstallFromGrammar, not required for :TSInstall)
  - OK: `git` executable found.
  - OK: `gcc` executable found. Selected from { "gcc" }
  - OK: Neovim was compiled with tree-sitter runtime ABI version 13 (required >=13). Parsers must be compatible with runtime ABI.

## Parser/Features H L F I J
  - rust           ✓ ✓ ✓ ✓ ✓ 
  - ledger         ✓ . ✓ ✓ ✓ 
  - bibtex         ✓ . ✓ ✓ . 
  - zig            ✓ ✓ ✓ ✓ ✓ 
  - fortran        ✓ . ✓ ✓ . 
  - graphql        ✓ . . ✓ ✓ 
  - cmake          ✓ . ✓ . . 
  - ruby           ✓ ✓ ✓ ✓ ✓ 
  - bash           ✓ ✓ ✓ . ✓ 
  - fish           ✓ ✓ ✓ ✓ ✓ 
  - php            ✓ ✓ ✓ ✓ ✓ 
  - kotlin         ✓ . . . ✓ 
  - html           ✓ ✓ ✓ ✓ ✓ 
  - julia          ✓ ✓ ✓ . ✓ 
  - lua            ✓ ✓ ✓ ✓ ✓ 
  - r              ✓ ✓ . . . 
  - cpp            ✓ ✓ ✓ ✓ ✓ 
  - scala          . . . . . 
  - supercollider  ✓ ✓ ✓ ✓ ✓ 
  - python         ✓ ✓ ✓ ✓ ✓ 
  - hcl            ✓ . ✓ . ✓ 
  - css            ✓ . ✓ ✓ ✓ 
  - scss           ✓ . . ✓ . 
  - toml           ✓ ✓ ✓ ✓ ✓ 
  - erlang         . . . . . 
  - ocaml          ✓ ✓ ✓ . ✓ 
  - go             ✓ ✓ ✓ ✓ ✓ 
  - jsonc          ✓ ✓ ✓ ✓ ✓ 
  - ocaml_interface✓ ✓ ✓ . ✓ 
  - elm            . . . . . 
  - yaml           ✓ ✓ ✓ ✓ ✓ 
  - nix            ✓ ✓ ✓ . ✓ 
  - c_sharp        ✓ . ✓ . ✓ 
  - c              ✓ ✓ ✓ ✓ ✓ 
  - dart           ✓ ✓ . ✓ ✓ 
  - ql             ✓ ✓ . ✓ ✓ 
  - typescript     ✓ ✓ ✓ ✓ ✓ 
  - rst            ✓ ✓ . . ✓ 
  - verilog        ✓ ✓ ✓ . ✓ 
  - tsx            ✓ ✓ ✓ ✓ ✓ 
  - comment        ✓ . . . . 
  - jsdoc          ✓ . . . . 
  - java           ✓ ✓ . ✓ ✓ 
  - javascript     ✓ ✓ ✓ ✓ ✓ 
  - sparql         ✓ ✓ ✓ ✓ ✓ 
  - turtle         ✓ ✓ ✓ ✓ ✓ 
  - json           ✓ ✓ ✓ ✓ . 
  - regex          ✓ . . . . 
  - fennel         ✓ ✓ . . ✓ 
  - commonlisp     ✓ ✓ ✓ . . 
  - svelte         ✓ . ✓ ✓ ✓ 
  - clojure        ✓ ✓ ✓ . ✓ 
  - gomod          ✓ . . . . 
  - glimmer        ✓ . . . . 
  - cuda           ✓ ✓ ✓ ✓ . 
  - beancount      ✓ . ✓ . . 
  - dockerfile     ✓ . . . ✓ 
  - query          ✓ ✓ ✓ ✓ ✓ 
  - latex          ✓ . ✓ . ✓ 
  - vue            ✓ . ✓ . ✓ 

 Legend: H[ighlight], L[ocals], F[olds], I[ndents], In[j]ections
         +) multiple parsers found, only one will be used
         x) errors found in the query, try to run :TSUpdate {lang}

Paste the output here

nvim-treesitter[haskell]: Error during compilation  
src/scanner.cc:79:10: error: expected expression
  return [=](A a) { return f(g(a)); };
         ^
src/scanner.cc:83:10: error: expected expression
  return [=](A a) { return f(g(a)); };
         ^
src/scanner.cc:87:10: error: expected expression
  return [=](A a) { return f(g(a)); };
         ^
src/scanner.cc:90:64: error: expected expression
template<class A, class B> function<B(A)> const_(B b) { return [=](auto _) { return b; }; }
                                                               ^
src/scanner.cc:155:16: error: non-aggregate type 'vector<std::__1::string>' (aka 'vector<basic_string<char> >') cannot be initialized with an in
itializer list
vector<string> names = {
               ^       ~
src/scanner.cc:183:69: error: expected expression
bool all(const bool *syms) { return std::all_of(syms, syms + empty, [](bool a) { return a; }); }
                                                                    ^
src/scanner.cc:240:8: warning: 'auto' type specifier is a C++11 extension [-Wc++11-extensions]
  for (auto i : state.indents) {
       ^
src/scanner.cc:240:15: warning: range-based for loop is a C++11 extension [-Wc++11-extensions]
  for (auto i : state.indents) {
              ^
src/scanner.cc:284:1: warning: 'function<void (State &)>' is deprecated: Using std::function in C++03 is not supported anymore. Please upgrade t
o C++11 or later, or use a different type [-Wdeprecated-declarations]
function<void(State&)> mark(string marked_by) {
^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/functional:1444:27: note: 'function<void (State &)>' has been explicitly 
marked deprecated here
template<class _Fp> class _LIBCPP_DEPRECATED_CXX03_FUNCTION _LIBCPP_TEMPLATE_VIS function; // undefined
                          ^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/functional:1439:24: note: expanded from macro '_LIBCPP_DEPRECATED_CXX03_F
UNCTION'
        __attribute__((deprecated("Using std::function in C++03 is not supported anymore. Please upgrade to C++11 or later, or use a different t
ype")))
                       ^
src/scanner.cc:285:10: error: expected expression
  return [=](State & state) {
         ^
src/scanner.cc:306:9: warning: 'function<bool (unsigned int)>' is deprecated: Using std::function in C++03 is not supported anymore. Please upgr
ade to C++11 or later, or use a different type [-Wdeprecated-declarations]
typedef function<bool(uint32_t)> Peek;
        ^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/functional:1444:27: note: 'function<bool (unsigned int)>' has been explic
itly marked deprecated here
template<class _Fp> class _LIBCPP_DEPRECATED_CXX03_FUNCTION _LIBCPP_TEMPLATE_VIS function; // undefined
                          ^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/functional:1439:24: note: expanded from macro '_LIBCPP_DEPRECATED_CXX03_F
UNCTION'
        __attribute__((deprecated("Using std::function in C++03 is not supported anymore. Please upgrade to C++11 or later, or use a different t

This is the start of the errors, there's more things like this.

Output of nvim --version

NVIM v0.5.0
Build type: Release
LuaJIT 2.1.0-beta3
Compilation: clang -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -DNVIM_TS_HAS_SET_MATCH_LIMIT -O2 -DNDEBUG -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wshadow -Wconversion -Wmissing-prototypes -Wimplicit-fallthrough -Wvla -fstack-protector-strong -fno-common -fdiagnostics-color=auto -DINCLUDE_GENERATED_DECLARATIONS -D_GNU_SOURCE -DNVIM_MSGPACK_HAS_FLOAT32 -DNVIM_UNIBI_HAS_VAR_FROM -DMIN_LOG_LEVEL=3 -I/tmp/neovim-20210702-14987-rep9di/neovim-0.5.0/build/config -I/tmp/neovim-20210702-14987-rep9di/neovim-0.5.0/src -I/usr/local/include -I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include -I/usr/local/opt/gettext/include -I/tmp/neovim-20210702-14987-rep9di/neovim-0.5.0/build/src/nvim/auto -I/tmp/neovim-20210702-14987-rep9di/neovim-0.5.0/build/include
Compiled by brew@BigSur

Features: +acl +iconv +tui
See ":help feature-compile"

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/usr/local/Cellar/neovim/0.5.0/share/nvim"

Run :checkhealth for more info

Additional context

I feel like its a problem with my GCC version, so I looked online and found that some people fixed this issue by adding CC="gcc-11" in their .zshrc. Sadly, this didn't work for me.

vigoux commented 3 years ago

Looks like you ran into error while compiling the Haskell grammar, I am not an expert on that but I remember there was issues.

@theHamsta you followed that better, could you help us a bit here?

theHamsta commented 3 years ago

It works on our CI with gcc-10 https://github.com/nvim-treesitter/nvim-treesitter/runs/3013299834. Maybe you can borrow that setup? Could it be related that your GCC tries to use libcpp instead of it's libstdc++

You need a compiler that uses C++-14 as a default language or download the parser from CI or compile the parser manually compiling C++ and C separately to be able to specify the language options.If it's possible we would like to avoid our 1-command compilation by three invocations because only one language failing with Apple clang.

Do you need haskell? You could also specify ignore_install = {"haskell"} in your setup call.

ujwal-jain commented 3 years ago

Not really sure what the problem is, but certainly I don’t need Haskell, so I’m just going to ignore it lol. I tried following that setup you linked but to no success…

theHamsta commented 3 years ago

So this setup should just skip Haskell in maintained. You can also remove ensure_install and just install all parsers you need manually or just run :TSInstall all once where Haskell will but it will not annoy you the next start-up

lua <<EOF
require'nvim-treesitter.configs'.setup {
  ensure_installed = "maintained", -- one of "all", "maintained" (parsers with maintainers), or a list of languages
  ignore_install = { "haskell" }, -- List of parsers to ignore installing
  highlight = {
    enable = true,              -- false will disable the whole extension
    disable = { "c", "rust" },  -- list of language that will be disabled
  },
}
EOF
nathom commented 3 years ago

I was able to fix this on my mac by doing the following