neorg icon indicating copy to clipboard operation
neorg copied to clipboard

Getting weird errors on autocommands for *.norg

Open vhyrro opened this issue 5 years ago • 36 comments

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 avatar Aug 26 '21 16:08 vhyrro

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

toan2406 avatar Aug 26 '21 17:08 toan2406

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 ?

danymat avatar Aug 26 '21 17:08 danymat

@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'},

toan2406 avatar Aug 26 '21 17:08 toan2406

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

robbielyman avatar Aug 26 '21 17:08 robbielyman

@toan2406 what plugin manager do you use ?

danymat avatar Aug 26 '21 17:08 danymat

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?

vhyrro avatar Aug 26 '21 17:08 vhyrro

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)

robbielyman avatar Aug 26 '21 17:08 robbielyman

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

vhyrro avatar Aug 26 '21 17:08 vhyrro

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

danymat avatar Aug 26 '21 18:08 danymat

That worked for me! 🙌

robbielyman avatar Aug 26 '21 18:08 robbielyman

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

vhyrro avatar Aug 26 '21 18:08 vhyrro

Work perfectly! Thanks 🙏

toan2406 avatar Aug 26 '21 18:08 toan2406

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.

johnallen3d avatar Aug 26 '21 19:08 johnallen3d

@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.

danymat avatar Aug 26 '21 21:08 danymat

Got it, will open a separate issue.

johnallen3d avatar Aug 26 '21 21:08 johnallen3d

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 :sweat_smile:

vhyrro avatar Aug 28 '21 11:08 vhyrro

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.

robbielyman avatar Aug 28 '21 17:08 robbielyman

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.

wfchandler avatar Aug 29 '21 04:08 wfchandler

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.

vhyrro avatar Aug 29 '21 07:08 vhyrro

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

Gelio avatar Aug 31 '21 10:08 Gelio