diff options
author | Björn Linse <bjorn.linse@gmail.com> | 2020-03-21 19:55:19 +0100 |
---|---|---|
committer | Björn Linse <bjorn.linse@gmail.com> | 2020-09-09 21:22:21 +0200 |
commit | 9437327d5ee627ddb15bfbc88112bd77e4e3ffcf (patch) | |
tree | bddcf9e744db25241f51cb2fe8e7e26c53e5a552 /src | |
parent | bc86f76c0a1d3234b749a105c9aae65f84c51320 (diff) | |
download | rneovim-9437327d5ee627ddb15bfbc88112bd77e4e3ffcf.tar.gz rneovim-9437327d5ee627ddb15bfbc88112bd77e4e3ffcf.tar.bz2 rneovim-9437327d5ee627ddb15bfbc88112bd77e4e3ffcf.zip |
treesitter: use new on_bytes interface
This will significantly reduce the parsing work
needed e.g. when rehighlighting after every keypress
in insert mode.
Also add safety check for tree-sitter trying to read
past the end of a line. This can happen after we sent
an incorrect buffer update.
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/lua/treesitter.c | 27 |
1 files changed, 13 insertions, 14 deletions
diff --git a/src/nvim/lua/treesitter.c b/src/nvim/lua/treesitter.c index 9a58823d64..8be4b6f376 100644 --- a/src/nvim/lua/treesitter.c +++ b/src/nvim/lua/treesitter.c @@ -286,22 +286,21 @@ static const char *input_cb(void *payload, uint32_t byte_index, } char_u *line = ml_get_buf(bp, position.row+1, false); size_t len = STRLEN(line); - if (position.column > len) { *bytes_read = 0; - } else { - size_t tocopy = MIN(len-position.column, BUFSIZE); - - memcpy(buf, line+position.column, tocopy); - // Translate embedded \n to NUL - memchrsub(buf, '\n', '\0', tocopy); - *bytes_read = (uint32_t)tocopy; - if (tocopy < BUFSIZE) { - // now add the final \n. If it didn't fit, input_cb will be called again - // on the same line with advanced column. - buf[tocopy] = '\n'; - (*bytes_read)++; - } + return ""; + } + size_t tocopy = MIN(len-position.column, BUFSIZE); + + memcpy(buf, line+position.column, tocopy); + // Translate embedded \n to NUL + memchrsub(buf, '\n', '\0', tocopy); + *bytes_read = (uint32_t)tocopy; + if (tocopy < BUFSIZE) { + // now add the final \n. If it didn't fit, input_cb will be called again + // on the same line with advanced column. + buf[tocopy] = '\n'; + (*bytes_read)++; } return buf; #undef BUFSIZE |