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

Getting weird errors on autocommands for *.norg #74

Closed
vhyrro opened this issue Aug 26, 2021 · 36 comments
Closed

Getting weird errors on autocommands for *.norg #74

vhyrro opened this issue Aug 26, 2021 · 36 comments
Labels
bug Issues related to bugs. Please attach a severity, a priority and category with this label.

Comments

@vhyrro
Copy link
Member

vhyrro commented Aug 26, 2021

Are you experiencing errors after updating the plugin to the latest version, and are getting an error along the lines of:

E5108: Error executing lua [string "luaeval()"]:1: Vim(echoerr):E121: Undefined variable: Failed                                                                                                                    
Error detected while processing BufEnter Autocommands for "*.norg":                                                                                                                                                 
E5108: Error executing lua Failed to load parser: uv_dlopen: /home/vhyrro/.local/share/nvim/site/pack/packer/start/nvim-treesitter/parser/norg.so: undefined symbol: tree_sitter_norg_external_scanner_create          
Error detected while processing BufEnter Autocommands for "*":                                                                                                                                                      
E5108: Error executing lua Failed to load parser: uv_dlopen: /home/vhyrro/.local/share/nvim/site/pack/packer/start/nvim-treesitter/parser/norg.so: undefined symbol: tree_sitter_norg_external_scanner_create          
Error detected while processing CursorMoved Autocommands for "*":                                                                                                                                                   
E5108: Error executing lua ...start/nvim-treesitter-context/lua/treesitter-context.lua:236: Vim(lua):E5108: Error executing lua Failed to load parser: uv_dlopen: /home/vhyrrolocal/share/nvim/site/pack/packer/start
/nvim-treesitter/parser/norg.so: undefined symbol: tree_sitter_norg_external_scanner_create                                                                                                                         
Error detected while processing WinScrolled Autocommands for "*":                                                                                                                                                   
E5108: Error executing lua Failed to load parser: uv_dlopen: /home/vhyrro/.local/share/nvim/site/pack/packer/start/nvim-treesitter/parser/norg.so: undefined symbol: tree_sitter_norg_external_scanner_create          
Failed to get context: Failed to load parser: uv_dlopen: /home/vhyrro/.local/share/nvim/site/pack/packer/start/nvim-treesitter/parser/norg.so: undefined symbol: tree_sitter_norg_external_scanner_create     

Fear no more! Simply take a look at the readme present in the unstable branch and scroll down to the treesitter installation section. We've slightly changed the code snippet as the new parser we're using also includes a scanner. After you've taken that code and replaced it in your own config run :TSUpdate and voila!

@vhyrro vhyrro pinned this issue Aug 26, 2021
@toan2406
Copy link

I just updated the treesitter config in unstable branch and then updated the parser, but I got this error

Screen Shot 2021-08-27 at 00 12 41

I'm using MacOS 10.15. I used to use the main branch and it worked well.

Thanks a lot for your hard work 🙏 I'm really excited for the zettelkasten feature

@danymat
Copy link
Member

danymat commented Aug 26, 2021

I just updated the treesitter config in unstable branch and then updated the parser, but I got this error

Screen Shot 2021-08-27 at 00 12 41

I'm using MacOS 10.15. I used to use the main branch and it worked well.

Thanks a lot for your hard work 🙏 I'm really excited for the zettelkasten feature

Did you update the code snippet in tree sitter config ?

@toan2406
Copy link

@danymat I did. This is my config

local parser_configs = require('nvim-treesitter.parsers').get_parser_configs()

parser_configs.norg = {
  install_info = {
    url = 'https://github.com/vhyrro/tree-sitter-norg',
    files = {'src/parser.c', 'src/scanner.cc'},
    branch = 'main'
  }
}

require('nvim-treesitter.configs').setup({
  ensure_installed = {'javascript', 'ruby', 'lua', 'bash', 'go', 'json', 'typescript', 'elixir', 'norg'},

@robbielyman
Copy link

I'm getting a similarly large set of errors after updating the code snippet whenever I run :TSUpdate.

@danymat
Copy link
Member

danymat commented Aug 26, 2021

@toan2406 what plugin manager do you use ?

@vhyrro
Copy link
Member Author

vhyrro commented Aug 26, 2021

From what I can see that seems to be an old compiler issue. Do you guys have gcc/clang installed and if so, which version?

@robbielyman
Copy link

gcc --version gives me

Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Con
tents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/4.2.1
Apple clang version 12.0.5 (clang-1205.0.22.11)
Target: x86_64-apple-darwin20.6.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

(clang --version gives me a subset of this)

@vhyrro
Copy link
Member Author

vhyrro commented Aug 26, 2021

That's rather peculiar, it seems to be a mac-only issue from what I can see too. Hm.

@danymat
Copy link
Member

danymat commented Aug 26, 2021

Okay i solved the issue (I'm on Mac 11.4).

What causes the issue is that I didn't have the latest gcc installed.
Below are the steps to solve:

  1. Install latest gcc: brew install gcc
  2. Check out which compiler is used in TSInstall: open nvim and run :checkhealth nvim_treesitter.

Note: in installation header, I have this:

- OK: `cc` executable found. Selected from { vim.NIL, "cc", "gcc", "clang", "cl" }

So that means tree sitter will compile with cc

  1. Alias brew gcc-11 with cc: do brew info gccto see where is located the gcc binaries, for me it's:
/usr/local/Cellar/gcc/11.2.0

I can now alias to some directory in my path like /usr/local/bin:

ln -s /usr/local/Cellar/gcc/11.2.0/bin/gcc-11 /usr/local/bin/cc

You can now restart Neovim and run TSUpdate norg

@robbielyman
Copy link

That worked for me! 🙌

@vhyrro
Copy link
Member Author

vhyrro commented Aug 26, 2021

Wow, that's a rather crazy setup process for something as simple as installing a parser lol! Glad it works though, thanks @danymat.

@toan2406
Copy link

Work perfectly! Thanks 🙏

@johnallen3d
Copy link

The symlink worked for me, thanks @danymat!

Now that that is working I'm seeing the following message when I open a .norg file.

[neorg] ^Ino file '/usr/local/lib/lua/5.1/loadall.so'

Screenshot:

CleanShot 2021-08-26 at 15 27 25@2x

So far I'm not sure this is actually causing issues.

@danymat
Copy link
Member

danymat commented Aug 26, 2021

@johnallen3d I think it's best for visibility to create an other issue, as I think this is a unrelated issue.

As I think I provided the steps to fix this issue, we should close this one.

@johnallen3d
Copy link

Got it, will open a separate issue.

@vhyrro
Copy link
Member Author

vhyrro commented Aug 28, 2021

To all people who still had issues: I think all of those should be fixed now. I downgraded the codebase to C++11 and removed the "modern" [[nodiscard]] attribute with parameters. Let me know if it fixes stuff for y'all and sorry for all the issues, things like that happen with a full parser rewrite 😅

@robbielyman
Copy link

I reverted the symlink @danymat suggested and tried doing :TSUpdate norg. Unfortunately it gives me more or less the same slew of errors as before.

@wfchandler
Copy link

wfchandler commented Aug 29, 2021

I'm seeing the same, also on MacOS 11.5 with Clang 12.0.5 aliased as cc. This is a very recent version of Clang and defaults to -std=gnu17, so it should support [[nodiscard]] by default.

Testing https://github.com/vhyrro/tree-sitter-norg outside of nvim, I can run yarn gen successfully, but yarn test fails with the same errors as TSInstall norg:

Expand to view 'yarn test' errors

yarn test
yarn run v1.22.11
$ tree-sitter test
Parser compilation failed.
Stdout:
Stderr: /Users/wchandler/test/tree-sitter-norg/src/scanner.cc:96:39: error: expected '(' for function-style cast or type construction
return std::vector { lhs, static_cast(rhs) };
~~~~~~~~~~~~~~~~~~~~~~ ^
/Users/wchandler/test/tree-sitter-norg/src/scanner.cc:99:24: warning: rvalue references are a C++11 extension [-Wc++11-extensions]
std::vector&& operator|(std::vector&& lhs, TokenType rhs)
^
/Users/wchandler/test/tree-sitter-norg/src/scanner.cc:99:59: warning: rvalue references are a C++11 extension [-Wc++11-extensions]
std::vector&& operator|(std::vector&& lhs, TokenType rhs)
^
/Users/wchandler/test/tree-sitter-norg/src/scanner.cc:322:38: error: expected ';' at end of declaration list
std::vector<size_t>& get_tag_stack() noexcept { return m_TagStack; }
^
;
/Users/wchandler/test/tree-sitter-norg/src/scanner.cc:551:23: warning: in-class initialization of non-static data member is a C++11 extension [-Wc++11-extensions]
bool m_Whitespace = false;
^
/Users/wchandler/test/tree-sitter-norg/src/scanner.cc:555:27: warning: in-class initialization of non-static data member is a C++11 extension [-Wc++11-extensions]
TokenType m_LastToken = NONE;
^
/Users/wchandler/test/tree-sitter-norg/src/scanner.cc:558:26: warning: in-class initialization of non-static data member is a C++11 extension [-Wc++11-extensions]
size_t m_ParsedChars = 0, m_IndentationLevel = 0;
^
/Users/wchandler/test/tree-sitter-norg/src/scanner.cc:558:50: warning: in-class initialization of non-static data member is a C++11 extension [-Wc++11-extensions]
size_t m_ParsedChars = 0, m_IndentationLevel = 0;
^
/Users/wchandler/test/tree-sitter-norg/src/scanner.cc:564:60: warning: in-class initialization of non-static data member is a C++11 extension [-Wc++11-extensions]
const std::array<unsigned char, 6> s_DetachedModifiers = { '*', '-', '>', '|', '=', '~' };
^
/Users/wchandler/test/tree-sitter-norg/src/scanner.cc:125:13: error: use of undeclared identifier 'advance'
advance(lexer);
^
/Users/wchandler/test/tree-sitter-norg/src/scanner.cc:134:13: error: use of undeclared identifier 'advance'
advance(lexer);
^
/Users/wchandler/test/tree-sitter-norg/src/scanner.cc:143:5: error: use of undeclared identifier 'advance'
advance(lexer);
^
/Users/wchandler/test/tree-sitter-norg/src/scanner.cc:148:6: error: use of undeclared identifier 'advance'
advance(lexer);
^
/Users/wchandler/test/tree-sitter-norg/src/scanner.cc:159:4: error: use of undeclared identifier 'advance'
advance(lexer);
^
/Users/wchandler/test/tree-sitter-norg/src/scanner.cc:163:36: error: use of undeclared identifier 'm_Current'
if (lexer->lookahead == ']' && m_Current != '\')
^
/Users/wchandler/test/tree-sitter-norg/src/scanner.cc:165:6: error: use of undeclared identifier 'advance'
advance(lexer);
^
/Users/wchandler/test/tree-sitter-norg/src/scanner.cc:173:5: error: use of undeclared identifier 'advance'
advance(lexer);
^
/Users/wchandler/test/tree-sitter-norg/src/scanner.cc:180:17: error: use of undeclared identifier 'check_link'
return check_link(lexer);
^
/Users/wchandler/test/tree-sitter-norg/src/scanner.cc:183:10: error: use of undeclared identifier 'advance'
advance(lexer);
^
/Users/wchandler/test/tree-sitter-norg/src/scanner.cc:201:14: error: use of undeclared identifier 'skip'
skip(lexer);
^
/Users/wchandler/test/tree-sitter-norg/src/scanner.cc:206:5: error: use of undeclared identifier 'advance'
advance(lexer);
^
/Users/wchandler/test/tree-sitter-norg/src/scanner.cc:212:6: error: use of undeclared identifier 'advance'
advance(lexer);
^
/Users/wchandler/test/tree-sitter-norg/src/scanner.cc:215:7: error: use of undeclared identifier 'advance'
advance(lexer);
^
/Users/wchandler/test/tree-sitter-norg/src/scanner.cc:218:8: error: use of undeclared identifier 'advance'
advance(lexer);
^
/Users/wchandler/test/tree-sitter-norg/src/scanner.cc:222:10: error: use of undeclared identifier 'advance'
advance(lexer);
^
/Users/wchandler/test/tree-sitter-norg/src/scanner.cc:247:7: error: use of undeclared identifier 'advance'
advance(lexer);
^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
7 warnings and 20 errors generated.

error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

The first error looks like the compiler is failing to recognize a braced initializer list, not clear to me why.

Edit: small correction, Clang 12 defaults to c++14, but c++17 is fully supported.

@vhyrro
Copy link
Member Author

vhyrro commented Aug 29, 2021

Wow, this is really weird. I might get in touch with the nvim-treesitter guys and ask them if they know of anything that could be done to fix this stuff.

@Gelio
Copy link

Gelio commented Aug 31, 2021

After including the scanner in the list of files, I am getting the following errors in :messages:

Error detected while processing BufEnter Autocommands for "*":
E5108: Error executing lua ...ejQS/usr/share/nvim/runtime/lua/vim/treesitter/query.lua:161: query: invalid node type at position 50
Error detected while processing CursorMoved Autocommands for "*":
E5108: Error executing lua ...start/nvim-treesitter-context/lua/treesitter-context.lua:236: Vim(lua):E5108: Error executing lua ...ejQS/usr/share/nvim/runtime/lua/vim/treesitter/query.lua:161: query: invalid node type at position 50
Error detected while processing WinScrolled Autocommands for "*":
E5108: Error executing lua ...ejQS/usr/share/nvim/runtime/lua/vim/treesitter/query.lua:161: query: invalid node type at position 50
Failed to get context: ...ejQS/usr/share/nvim/runtime/lua/vim/treesitter/query.lua:161: query: invalid node type at position 50

:checkhealth:

## Installation
  - WARNING: `tree-sitter` executable not found (parser generator, only needed for :TSInstallFromGrammar, not required for :TSInstall)
  - OK: `node` found v14.17.0 (only needed for :TSInstallFromGrammar)
  - OK: `git` executable found.
  - OK: `cc` executable found. Selected from { vim.NIL, "cc", "gcc", "clang", "cl" }
  - 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
  - norg           x . x . x 

The following errors have been detected:
  - ERROR: norg(highlights): ...ejQS/usr/share/nvim/runtime/lua/vim/treesitter/query.lua:161: query: invalid node type at position 1
  - ERROR: norg(folds): ...ejQS/usr/share/nvim/runtime/lua/vim/treesitter/query.lua:161: query: invalid node type at position 4
  - ERROR: norg(injections): ...ejQS/usr/share/nvim/runtime/lua/vim/treesitter/query.lua:161: query: invalid node type at position 50

I'm running Ubuntu 20.04 LTS and I have just executed :TSUpdate norg and :PackerSync, but to no avail.


Interestingly, the error does not manifest itself on the unstable branch

@vhyrro
Copy link
Member Author

vhyrro commented Sep 1, 2021

@Gelio the reason is because the new parser does not work with the main branch yet. I think what we should do is push the unstable branch to main. The issue is that I haven't written any real docs for the new stuff we're making yet and so I dunno whether that'll confuse people

@Gelio
Copy link

Gelio commented Sep 1, 2021

@vhyrro I see, thanks for explaining. In that case, maybe there should be an unstable branch of the parser as well for such changes, which would require using the unstable branch of the plugin? Just an idea, as otherwise, it looks like anyone updating the parser (or installing the plugin from scratch, which is what I've done) has to use the unstable branch

Just a thought for the future

@vhyrro
Copy link
Member Author

vhyrro commented Sep 4, 2021

@Gelio what we ended up doing is we merged the unstable branch into main. We also added an extra disclaimer in the README that Neorg is alpha software and that certain bits of documentation may be out of date. This should alleviate a bunch of issues that people may have had to date 🤞

@glyh
Copy link

glyh commented Nov 2, 2021

I have the same issue, hope this will be fixed soon

@JorisDeRidder
Copy link

I have still the same issue on OSX 10.15 and clang 12.0.0, even with the unstable branch. :TSInstall norg gives lots of errors. The first one is:
src/scanner.cc:360:41: error: expected ';' at end of declaration list
std::vector<size_t>& get_tag_stack() noexcept { return m_TagStack; }

@danymat
Copy link
Member

danymat commented Nov 8, 2021

As this is the most upvoted answer: #74 (comment)

I tried simplifying it a little bit.
We do not need to create symlinks for cc stuff, as tree sitter allow us to have an environment variable called CC.

You can do CC=/path/to/gcc-12 nvim before doing any actual update or installation, or put CC=/path/to/gcc-12 in your bashrc or zshrc for the change to be permanent

@ray-x
Copy link
Contributor

ray-x commented Nov 19, 2021

I followed instructions in #74 (comment)
Still have issue.
double check with this:

gcc --version
gcc (Homebrew GCC 11.2.0_2) 11.2.0
Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Also I linked gcc, linked cc, export CC, none of the tricks helps. Is there anything missing?

@vhyrro
Copy link
Member Author

vhyrro commented Nov 20, 2021

Hmm, i think that looks fine. @danymat since you're the one that fixed the issue is there anything else ray can do?

Man we really need that makefile support in the nvim-treesitter repo

@danymat
Copy link
Member

danymat commented Nov 20, 2021

I followed instructions in #74 (comment)

Still have issue.

double check with this:


gcc --version

gcc (Homebrew GCC 11.2.0_2) 11.2.0

Copyright (C) 2021 Free Software Foundation, Inc.

This is free software; see the source for copying conditions.  There is NO

warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Also I linked gcc, linked cc, export CC, none of the tricks helps. Is there anything missing?

Hello, can you print the output of which cc, env | GREP CC in the same terminal just before you enter neovim ?

@ray-x
Copy link
Contributor

ray-x commented Nov 20, 2021

Yes, here is what is printed out:

❯❯❯ cc -v
Using built-in specs.
COLLECT_GCC=/usr/local/Cellar/gcc/11.2.0_2/bin/gcc-11
COLLECT_LTO_WRAPPER=/usr/local/Cellar/gcc/11.2.0_2/libexec/gcc/x86_64-apple-darwin19/11/lto-wrapper
Target: x86_64-apple-darwin19
Configured with: ../configure --prefix=/usr/local/Cellar/gcc/11.2.0_2 --libdir=/usr/local/Cellar/gcc/11.2.0_2/lib/gcc/11 --disable-nls --enable-checking=release --with-gcc-major-version-only --enable-languages=c,c++,objc,obj-c++,fortran,d --program-suffix=-11 --with-gmp=/usr/local/opt/gmp --with-mpfr=/usr/local/opt/mpfr --with-mpc=/usr/local/opt/libmpc --with-isl=/usr/local/opt/isl --with-zstd=/usr/local/opt/zstd --with-pkgversion='Homebrew GCC 11.2.0_2' --with-bugurl=https://github.com/Homebrew/homebrew-core/issues --enable-libphobos --build=x86_64-apple-darwin19 --with-system-zlib --disable-multilib --with-native-system-header-dir=/usr/include --with-sysroot=/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 11.2.0 (Homebrew GCC 11.2.0_2) 


❯❯❯ echo $CC
/usr/local/Cellar/gcc/11.2.0_2

❯❯❯ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/local/Cellar/gcc/11.2.0_2/libexec/gcc/x86_64-apple-darwin19/11/lto-wrapper
Target: x86_64-apple-darwin19
Configured with: ../configure --prefix=/usr/local/Cellar/gcc/11.2.0_2 --libdir=/usr/local/Cellar/gcc/11.2.0_2/lib/gcc/11 --disable-nls --enable-checking=release --with-gcc-major-version-only --enable-languages=c,c++,objc,obj-c++,fortran,d --program-suffix=-11 --with-gmp=/usr/local/opt/gmp --with-mpfr=/usr/local/opt/mpfr --with-mpc=/usr/local/opt/libmpc --with-isl=/usr/local/opt/isl --with-zstd=/usr/local/opt/zstd --with-pkgversion='Homebrew GCC 11.2.0_2' --with-bugurl=https://github.com/Homebrew/homebrew-core/issues --enable-libphobos --build=x86_64-apple-darwin19 --with-system-zlib --disable-multilib --with-native-system-header-dir=/usr/include --with-sysroot=/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 11.2.0 (Homebrew GCC 11.2.0_2) 

later on, I found that it was alias setup not working. I was intend to use alias instead of symbol link for cc . Seems I have to symble link cc to gcc-11 to make things work.
If only setup CC, it does not work, also link gcc to gcc-11 does not work.

brendonsoto added a commit to brendonsoto/dotfiles_orig that referenced this issue Nov 29, 2021
Norg's treesitter config was not compiling on TSUpdate
Kudos to nvim-neorg/neorg#74 (comment)
@vitaly
Copy link

vitaly commented Dec 18, 2021

this worked for me: CC=gcc-11 nvim and then :TSInstall norg

@CLZamb
Copy link

CLZamb commented Dec 19, 2021

"export CC=gcc-11" on mac worked for me.

@brendonsoto
Copy link

brendonsoto commented Oct 31, 2022

For anyone running into this but receiving an error ending with something like,

ld: Assertion failed: (_file->_atomsArrayCount == computedAtomCount && "more atoms allocated than expected"), function parse, file macho_relocatable_file.cpp, line 2061.
collect2: error: ld returned 1 exit status

check out this thread.
tl;dr - either downgrade command line tools for xcode or dl the beta.
I hope this saves someone some time.

@haikyuu
Copy link

haikyuu commented Feb 8, 2023

Thanks @brendonsoto facing the same issue

@transcendr
Copy link

@danymat thanks worked!

I did:
which gcc-12 which gave me /opt/homebrew/bin/gcc-12

Then in .zshrc:

export CC=/opt/homebrew/bin/gcc-12

Then I ran:

nvim -c "TSInstallSync norg"

And all good!

@howarddo2208
Copy link
Contributor

I just got this error during a fresh install on MacOS. I think the README instruction is misleading, what needed is gcc11, not C++14 at all.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issues related to bugs. Please attach a severity, a priority and category with this label.
Projects
None yet
Development

No branches or pull requests