neovim / tree-sitter-vimdoc

Tree-sitter parser for Vim help files
Apache License 2.0
97 stars 13 forks source link

Vimdoc parser breaks down around LOCAL ADDITIONS in the help section #99

Closed dundargoc closed 1 year ago

dundargoc commented 1 year ago

The text changes based on installed plugins, so it's not always apparent. Minimal reproduction:

LOCAL ADDITIONS:                *local-additions*
|lazy.nvim.txt|         For Neovim >= 0.8.0         Last change: 2023 March 07
|nvim-treesitter|  Treesitter configurations and abstraction layer for Neovim.
|matchit.txt|   Extended "%" matching
clason commented 1 year ago

screenshot shows this better:

Screenshot 2023-03-11 at 22 38 56

why is i in gitsigns being concealed? why is ng in matching a @string.special? No idea.

justinmk commented 1 year ago

@clason are you seeing that on your system? When I use :InspectTree on the provided text the parse tree looks perfect (NVIM v0.9.0-dev-1163+g4385f8a7430f):

(block) ; [1:1 - 5]
 (line) ; [1:1 - 1]
  (word) ; [1:1 - 6:0]
  (word) ; [1:7 - 16:0]
  (word) ; [1:16 - 17:0]
  (tag) ; [1:21 - 38:0]
   text: (word) ; [1:22 - 37:0]
 (line) ; [2:1 - 1:2]
  (taglink) ; [2:1 - 16:1]
   text: (word) ; [2:2 - 15:1]
  (word) ; [2:25 - 28:1]
  (word) ; [2:29 - 35:1]
  (word) ; [2:36 - 37:1]
  (word) ; [2:37 - 38:1]
  (word) ; [2:39 - 44:1]
  (word) ; [2:53 - 57:1]
  (word) ; [2:58 - 65:1]
  (word) ; [2:66 - 70:1]
  (word) ; [2:71 - 76:1]
  (word) ; [2:77 - 79:1]
 (line) ; [3:1 - 1:3]
  (taglink) ; [3:1 - 18:2]
   text: (word) ; [3:2 - 17:2]
  (word) ; [3:20 - 30:2]
  (word) ; [3:31 - 45:2]
  (word) ; [3:46 - 49:2]
  (word) ; [3:50 - 61:2]
  (word) ; [3:62 - 67:2]
  (word) ; [3:68 - 71:2]
  (word) ; [3:72 - 79:2]
 (line) ; [4:1 - 1:4]
  (taglink) ; [4:1 - 14:3]
   text: (word) ; [4:2 - 13:3]
  (word) ; [4:15 - 23:3]
  (word) ; [4:24 - 27:3]
  (word) ; [4:28 - 36:3]
justinmk commented 1 year ago

Could nvim-treesitter be interfering? I don't have it enabled.

dundargoc commented 1 year ago

n=1 for the culprit being nvim-treesitter, I can recreate the problem with nvim-treesitter but not with the builtin parser.

clason commented 1 year ago

I'm actually seeing this on my system, yes, and it's without nvim-treesitter. I'll try to paste the tree, but I'm getting an error traversing it right now (probably an unrelated regression from recent treesitter refactors):

Error detected while processing CursorMoved Autocommands for "<buffer=3>":
Error executing lua callback: /usr/local/share/nvim/runtime/lua/vim/treesitter.lua:554: Invalid 'col': out of
range
stack traceback:
        [C]: in function 'nvim_buf_set_extmark'
        /usr/local/share/nvim/runtime/lua/vim/treesitter.lua:554: in function </usr/local/share/nvim/runtime/l
ua/vim/treesitter.lua:550>

(The error occurs when visiting the "weird" nodes, in particular keycode.)

(block) ; [184:1 - 1:185]
 (line) ; [184:1 - 1:184]
  (word) ; [184:1 - 6:183]
  (word) ; [184:7 - 16:183]
  (word) ; [184:16 - 17:183]
  (tag) ; [184:21 - 38:183]
   text: (word) ; [184:22 - 37:183]
(block) ; [186:1 - 1:188]
 (line) ; [186:1 - 1:187]
  (h2) ; [186:1 - 1:187]
   (tag) ; [187:1 - 7:186]
    text: (word) ; [187:2 - 6:186]
   (word) ; [187:9 - 13:186]
   (word) ; [187:14 - 21:186]
(block) ; [189:1 - 1:191]
 (line) ; [189:1 - 1:189]
  (word) ; [189:1 - 4:188]
  (word) ; [189:5 - 9:188]
  (word) ; [189:10 - 16:188]
  (word) ; [189:17 - 23:188]
  (word) ; [189:24 - 28:188]
  (word) ; [189:29 - 33:188]
  (keycode) ; [189:34 - 40:188]
  (word) ; [189:41 - 43:188]
  (word) ; [189:44 - 45:188]
  (word) ; [189:46 - 52:188]
  (word) ; [189:53 - 58:188]
  (word) ; [189:59 - 65:188]
  (word) ; [189:66 - 69:188]
  (word) ; [189:70 - 73:188]
  (word) ; [189:74 - 77:188]
 (line) ; [190:1 - 1:190]
  (word) ; [190:1 - 7:189]
  (word) ; [190:7 - 8:189]
  (keycode) ; [190:9 - 15:189]
  (word) ; [190:15 - 16:189]
  (word) ; [190:17 - 31:189]
  (word) ; [190:32 - 34:189]
  (keycode) ; [190:35 - 49:189]
  (word) ; [190:50 - 52:189]
  (word) ; [190:53 - 55:189]
  (word) ; [190:56 - 60:189]
  (word) ; [190:61 - 63:189]
  (word) ; [190:64 - 69:189]
  (word) ; [190:70 - 73:189]
  (word) ; [190:74 - 79:189]
clason commented 1 year ago

(Weird, I never noticed that the row and column are flipped in the node range end, compared to the start. Also the start line seems 1-indexed and the end line 0-indexed?)

clason commented 1 year ago

Update: copying the generated file into a fresh buffer works fine, so this may be a race condition? (Disabling and re-enabling treesitter doesn't make a difference, though.)

In particular, this means it's actually a Neovim issue, not a vimdoc issue.

clason commented 1 year ago

But there is one minor issue: the LOCAL ADDITIONS: are not parsed as a column heading due to the trailing colon ;)