diff options
author | Riley Bruins <ribru17@hotmail.com> | 2024-09-19 13:08:22 -0700 |
---|---|---|
committer | Christian Clason <c.clason@uni-graz.at> | 2024-10-11 18:15:07 +0200 |
commit | d3193afc2559e7d84ed2d76664a650dc03b4c6ef (patch) | |
tree | cfa3e37e11d158713ae01a691e03853509317e39 /runtime/lua/vim/treesitter/_query_linter.lua | |
parent | 267c7525f738cdd6024c39da758e885c026ffaaa (diff) | |
download | rneovim-d3193afc2559e7d84ed2d76664a650dc03b4c6ef.tar.gz rneovim-d3193afc2559e7d84ed2d76664a650dc03b4c6ef.tar.bz2 rneovim-d3193afc2559e7d84ed2d76664a650dc03b4c6ef.zip |
fix(treesitter): remove duplicate symbol names in language.inspect()
**Problems:**
- `vim.treesitter.language.inspect()` returns duplicate
symbol names, sometimes up to 6 of one kind in the case of `markdown`
- The list-like `symbols` table can have holes and is thus not even a
valid msgpack table anyway, mentioned in a test
**Solution:** Return symbols as a map, rather than a list, where field
names are the names of the symbol. The boolean value associated with the
field encodes whether or not the symbol is named.
Note that anonymous nodes are surrounded with double quotes (`"`) to
prevent potential collisions with named counterparts that have the same
identifier.
Diffstat (limited to 'runtime/lua/vim/treesitter/_query_linter.lua')
-rw-r--r-- | runtime/lua/vim/treesitter/_query_linter.lua | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/runtime/lua/vim/treesitter/_query_linter.lua b/runtime/lua/vim/treesitter/_query_linter.lua index c5e4b86e1e..a825505378 100644 --- a/runtime/lua/vim/treesitter/_query_linter.lua +++ b/runtime/lua/vim/treesitter/_query_linter.lua @@ -240,8 +240,12 @@ function M.omnifunc(findstart, base) table.insert(items, text) end end - for _, s in pairs(parser_info.symbols) do - local text = s[2] and s[1] or string.format('%q', s[1]):gsub('\n', 'n') ---@type string + for text, named in + pairs(parser_info.symbols --[[@as table<string, boolean>]]) + do + if not named then + text = string.format('%q', text:sub(2, -2)):gsub('\n', 'n') ---@type string + end if text:find(base, 1, true) then table.insert(items, text) end |