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

Highlight definitions leads to "Error detected while processing CursorHold" #20

Open
madskjeldgaard opened this issue May 18, 2021 · 4 comments
Labels
bug Something isn't working

Comments

@madskjeldgaard
Copy link

Describe the bug
Hello
Highlight definitions for me freaks out Nvim when it encounters and error in the parser tree it seems:

E5108: Error executing lua ...m/plugged/nvim-treesitter/lua/nvim-treesitter/locals.lua:133: bad argument #1 to 'pairs' (table expected, g
ot string)   ```

This is tested with the supercollider grammar.

**Expected behavior**
I expect it to fail silently.

**Output of `:checkhealth nvim_treesitter`**

<details>
<code>

health#nvim_treesitter#check
========================================================================
## Installation
  - OK: `tree-sitter` found  0.19.4 (parser generator, only needed for :TSInstallFromGrammar)
  - OK: `node` found v14.16.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
  - c_sharp        ✓ . . . 
  - svelte         ✓ . ✓ ✓ 
  - beancount      ✓ . ✓ . 
  - zig            ✓ ✓ ✓ ✓ 
  - c              ✓ ✓ ✓ ✓ 
  - fortran        ✓ . ✓ . 
  - teal           ✓ ✓ ✓ ✓ 
  - java           ✓ ✓ . ✓ 
  - python         ✓ ✓ ✓ ✓ 
  - bibtex         ✓ . ✓ ✓ 
  - sparql         ✓ ✓ ✓ ✓ 
  - comment        ✓ . . . 
  - gomod          ✓ . . . 
  - dart           ✓ ✓ . ✓ 
  - lua            ✓ ✓ ✓ ✓ 
  - latex          ✓ . ✓ . 
  - ocaml          ✓ ✓ ✓ . 
  - bash           ✓ ✓ ✓ . 
  - r              ✓ ✓ . . 
  - scss           ✓ . . ✓ 
  - yaml           ✓ ✓ ✓ ✓ 
  - json           ✓ ✓ ✓ ✓ 
  - jsdoc          ✓ . . . 
  - ledger         ✓ . ✓ ✓ 
  - php            ✓ ✓ ✓ ✓ 
  - julia          ✓ ✓ ✓ . 
  - supercollider  ✓ ✓ ✓ ✓ 
  - devicetree     ✓ ✓ ✓ ✓ 
  - gdscript       ✓ ✓ . . 
  - turtle         ✓ ✓ ✓ ✓ 
  - vue            ✓ . ✓ . 
  - html           ✓ ✓ ✓ ✓ 
  - typescript     ✓ ✓ ✓ ✓ 
  - regex          ✓ . . . 
  - verilog        ✓ ✓ ✓ . 
  - jsonc          ✓ ✓ ✓ ✓ 
  - ql             ✓ ✓ . ✓ 
  - fennel         ✓ ✓ . . 
  - swift          . . . . 
  - rst            ✓ ✓ . . 
  - nix            ✓ ✓ ✓ . 
  - elm            . . . . 
  - query          ✓ ✓ ✓ ✓ 
  - graphql        ✓ . . ✓ 
  - cpp            ✓ ✓ ✓ ✓ 
  - toml           ✓ ✓ ✓ ✓ 
  - kotlin         ✓ . . . 
  - ruby           ✓ ✓ ✓ ✓ 
  - fish           ✓ ✓ ✓ ✓ 
  - ocamllex       ✓ . . . 
  - scala          . . . . 
  - dockerfile     ✓ . . . 
  - rust           ✓ ✓ ✓ ✓ 
  - haskell        . . . . 
  - ocaml_interface✓ ✓ ✓ . 
  - javascript     ✓ ✓ ✓ ✓ 
  - css            ✓ . ✓ ✓ 
  - glimmer        ✓ . . . 
  - erlang         . . . . 
  - clojure        ✓ ✓ . . 
  - go             ✓ ✓ ✓ ✓ 
  - tsx            ✓ ✓ ✓ ✓ 

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


</code>
</details>

**Output of `nvim --version`**

NVIM v0.5.0-dev+1318-g61aefaf29
Build type: RelWithDebInfo
LuaJIT 2.0.5
Compilation: /usr/bin/cc -D_FORTIFY
_SOURCE=2 -march=x86-64 -mtune=gene
ric -O2 -pipe -fno-plt -U_FORTIFY_S
OURCE -D_FORTIFY_SOURCE=1 -O2 -g -O
g -g -Wall -Wextra -pedantic -Wno-u
nused-parameter -Wstrict-prototypes
-std=gnu99 -Wshadow -Wconversion -
Wmissing-prototypes -Wimplicit-fall
through -Wvla -fstack-protector-str
ong -fno-common -fdiagnostics-color
=auto -DINCLUDE_GENERATED_DECLARATI
ONS -D_GNU_SOURCE -DNVIM_MSGPACK_HA
S_FLOAT32 -DNVIM_UNIBI_HAS_VAR_FROM
-DMIN_LOG_LEVEL=3 -I/home/mads/.ca
che/yay/neovim-git/src/build/config
-I/home/mads/.cache/yay/neovim-git
/src/neovim-git/src -I/usr/include
-I/home/mads/.cache/yay/neovim-git/
src/build/src/nvim/auto -I/home/mad
s/.cache/yay/neovim-git/src/build/i
nclude
Compiled by mads

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

system vimrc file: "$VIM/sysinit
.vim"
fall-back for $VIM: "/usr/share/n
vim"


**Additional context**
Add any other context about the problem here.
@madskjeldgaard madskjeldgaard added the bug Something isn't working label May 18, 2021
@madskjeldgaard
Copy link
Author

It seems that when using this, the local_def here is passed the value "local" as a string: https://github.com/nvim-treesitter/nvim-treesitter/blob/506e998da2739024b52f1ca947ae76d3423763e6/lua/nvim-treesitter/locals.lua#L133

@madskjeldgaard
Copy link
Author

Okay, changing that function in nvim-treesitter to the following (which now includes a type check for whether or not it is a table) works:

-- Recurse locals results until a node is found.
-- The accumulator function is given
-- * The table of the node
-- * The node
-- * The full definition match `@definition.var.something` -> 'var.something'
-- * The last definition match `@definition.var.something` -> 'something'
-- @param The locals result
-- @param The accumulator function
-- @param The full match path to append to
-- @param The last match
function M.recurse_local_nodes(local_def, accumulator, full_match, last_match)
	if local_def.node then
		accumulator(local_def, local_def.node, full_match, last_match)
	else
		if(type(local_def) == "table") then
			for match_key, def in pairs(local_def) do
				M.recurse_local_nodes(
				def,
				accumulator,
				full_match and (full_match..'.'..match_key) or match_key,
				match_key)
			end
		end
	end
end

@theHamsta should this function perhaps generally type check to make sure it is a table?

@stsewd
Copy link
Member

stsewd commented May 21, 2021

should this function perhaps generally type check to make sure it is a table?

That makes sense, feel free to open a PR with that change!

@madskjeldgaard
Copy link
Author

should this function perhaps generally type check to make sure it is a table?

That makes sense, feel free to open a PR with that change!

Yes I'll do a PR :)

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

No branches or pull requests

2 participants