diff options
-rw-r--r-- | runtime/doc/treesitter.txt | 6 | ||||
-rw-r--r-- | runtime/lua/vim/lsp.lua | 11 | ||||
-rw-r--r-- | runtime/lua/vim/lsp/util.lua | 19 | ||||
-rw-r--r-- | runtime/lua/vim/treesitter.lua | 2 | ||||
-rw-r--r-- | src/nvim/lua/executor.c | 11 | ||||
-rw-r--r-- | src/nvim/lua/treesitter.c | 2 | ||||
-rw-r--r-- | src/nvim/option.c | 6 | ||||
-rw-r--r-- | src/nvim/testdir/test_gn.vim | 4 | ||||
-rw-r--r-- | src/nvim/testdir/test_quotestar.vim | 2 | ||||
-rw-r--r-- | src/nvim/testdir/test_registers.vim | 2 | ||||
-rw-r--r-- | src/nvim/testdir/test_syntax.vim | 4 | ||||
-rw-r--r-- | src/nvim/testdir/test_tabpage.vim | 3 | ||||
-rw-r--r-- | src/nvim/testdir/test_vartabs.vim | 7 | ||||
-rw-r--r-- | src/nvim/testdir/test_visual.vim | 2 |
14 files changed, 56 insertions, 25 deletions
diff --git a/runtime/doc/treesitter.txt b/runtime/doc/treesitter.txt index 1696d3b9ba..343f4a62c2 100644 --- a/runtime/doc/treesitter.txt +++ b/runtime/doc/treesitter.txt @@ -32,6 +32,12 @@ retained for the lifetime of a buffer but this is subject to change. A plugin should keep a reference to the parser object as long as it wants incremental updates. + *vim.treesitter.language_version* +To check which language version is compiled with neovim, the number is stored +within `vim.treesitter.language_version`. This number is not too helpful +unless you are wondering about compatibility between different versions of +compiled grammars. + Parser files *treesitter-parsers* Parsers are the heart of tree-sitter. They are libraries that tree-sitter will diff --git a/runtime/lua/vim/lsp.lua b/runtime/lua/vim/lsp.lua index 4c453df3f6..4110bd1910 100644 --- a/runtime/lua/vim/lsp.lua +++ b/runtime/lua/vim/lsp.lua @@ -850,20 +850,23 @@ do end util.buf_versions[bufnr] = changedtick - -- Lazy initialize these because clients may not even need them. - local incremental_changes = once(function(client) + + local incremental_changes = function(client) local lines = nvim_buf_get_lines(bufnr, 0, -1, true) local startline = math.min(firstline + 1, math.min(#client._cached_buffers[bufnr], #lines)) local endline = math.min(-(#lines - new_lastline), -1) - local incremental_change = vim.lsp.util.compute_diff(client._cached_buffers[bufnr], lines, startline, endline) + local incremental_change = vim.lsp.util.compute_diff( + client._cached_buffers[bufnr], lines, startline, endline, client.offset_encoding or "utf-16") client._cached_buffers[bufnr] = lines return incremental_change - end) + end + local full_changes = once(function() return { text = buf_get_full_text(bufnr); }; end) + local uri = vim.uri_from_bufnr(bufnr) for_each_buffer_client(bufnr, function(client) local allow_incremental_sync = if_nil(client.config.flags.allow_incremental_sync, true) diff --git a/runtime/lua/vim/lsp/util.lua b/runtime/lua/vim/lsp/util.lua index 412be68396..ec1131ae1f 100644 --- a/runtime/lua/vim/lsp/util.lua +++ b/runtime/lua/vim/lsp/util.lua @@ -357,8 +357,11 @@ end --- Returns the range table for the difference between old and new lines --@param old_lines table list of lines --@param new_lines table list of lines +--@param start_line_idx int line to begin search for first difference +--@param end_line_idx int line to begin search for last difference +--@param offset_encoding string encoding requested by language server --@returns table start_line_idx and start_col_idx of range -function M.compute_diff(old_lines, new_lines, start_line_idx, end_line_idx) +function M.compute_diff(old_lines, new_lines, start_line_idx, end_line_idx, offset_encoding) local start_line, start_char = first_difference(old_lines, new_lines, start_line_idx) local end_line, end_char = last_difference(vim.list_slice(old_lines, start_line, #old_lines), vim.list_slice(new_lines, start_line, #new_lines), start_char, end_line_idx) @@ -373,13 +376,19 @@ function M.compute_diff(old_lines, new_lines, start_line_idx, end_line_idx) adj_end_char = #old_lines[#old_lines + end_line + 1] + end_char + 1 end - local _, utf16_start_char = vim.str_utfindex(old_lines[start_line], start_char - 1) - local _, utf16_end_char = vim.str_utfindex(old_lines[#old_lines + end_line + 1], adj_end_char) + local _ + if offset_encoding == "utf-16" then + _, start_char = vim.str_utfindex(old_lines[start_line], start_char - 1) + _, end_char = vim.str_utfindex(old_lines[#old_lines + end_line + 1], adj_end_char) + else + start_char = start_char - 1 + end_char = adj_end_char + end local result = { range = { - start = { line = start_line - 1, character = utf16_start_char}, - ["end"] = { line = adj_end_line, character = utf16_end_char} + start = { line = start_line - 1, character = start_char}, + ["end"] = { line = adj_end_line, character = end_char} }, text = text, rangeLength = length + 1, diff --git a/runtime/lua/vim/treesitter.lua b/runtime/lua/vim/treesitter.lua index 64a5ba1fd8..cac0ab864b 100644 --- a/runtime/lua/vim/treesitter.lua +++ b/runtime/lua/vim/treesitter.lua @@ -10,6 +10,8 @@ local parsers = {} local M = vim.tbl_extend("error", query, language) +M.language_version = vim._ts_get_language_version() + setmetatable(M, { __index = function (t, k) if k == "highlighter" then diff --git a/src/nvim/lua/executor.c b/src/nvim/lua/executor.c index 310b194c8c..03d178467b 100644 --- a/src/nvim/lua/executor.c +++ b/src/nvim/lua/executor.c @@ -1272,6 +1272,12 @@ bool nlua_exec_file(const char *path) return true; } +int tslua_get_language_version(lua_State *L) +{ + lua_pushnumber(L, TREE_SITTER_LANGUAGE_VERSION); + return 1; +} + static void nlua_add_treesitter(lua_State *const lstate) FUNC_ATTR_NONNULL_ALL { tslua_init(lstate); @@ -1288,8 +1294,11 @@ static void nlua_add_treesitter(lua_State *const lstate) FUNC_ATTR_NONNULL_ALL lua_pushcfunction(lstate, tslua_inspect_lang); lua_setfield(lstate, -2, "_ts_inspect_language"); - lua_pushcfunction(lstate, ts_lua_parse_query); + lua_pushcfunction(lstate, tslua_parse_query); lua_setfield(lstate, -2, "_ts_parse_query"); + + lua_pushcfunction(lstate, tslua_get_language_version); + lua_setfield(lstate, -2, "_ts_get_language_version"); } int nlua_expand_pat(expand_T *xp, diff --git a/src/nvim/lua/treesitter.c b/src/nvim/lua/treesitter.c index 33974c71cb..188b2c1ef7 100644 --- a/src/nvim/lua/treesitter.c +++ b/src/nvim/lua/treesitter.c @@ -1109,7 +1109,7 @@ static int querycursor_gc(lua_State *L) // Query methods -int ts_lua_parse_query(lua_State *L) +int tslua_parse_query(lua_State *L) { if (lua_gettop(L) < 2 || !lua_isstring(L, 1) || !lua_isstring(L, 2)) { return luaL_error(L, "string expected"); diff --git a/src/nvim/option.c b/src/nvim/option.c index a4736656cd..612ecca96a 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -2001,7 +2001,9 @@ static void didset_options2(void) // Parse default for 'wildmode'. check_opt_wim(); + xfree(curbuf->b_p_vsts_array); tabstop_set(curbuf->b_p_vsts, &curbuf->b_p_vsts_array); + xfree(curbuf->b_p_vts_array); tabstop_set(curbuf->b_p_vts, &curbuf->b_p_vts_array); } @@ -3167,9 +3169,7 @@ ambw_end: if (errmsg == NULL) { long *oldarray = curbuf->b_p_vts_array; if (tabstop_set(*varp, &(curbuf->b_p_vts_array))) { - if (oldarray) { - xfree(oldarray); - } + xfree(oldarray); if (foldmethodIsIndent(curwin)) { foldUpdateAll(curwin); } diff --git a/src/nvim/testdir/test_gn.vim b/src/nvim/testdir/test_gn.vim index 9acec51913..d09b25b0e7 100644 --- a/src/nvim/testdir/test_gn.vim +++ b/src/nvim/testdir/test_gn.vim @@ -1,9 +1,8 @@ " Test for gn command func Test_gn_command() - set belloff=all noautocmd new - " replace a single char by itsself quoted: + " replace a single char by itself quoted: call setline('.', 'abc x def x ghi x jkl') let @/ = 'x' exe "norm! cgn'x'\<esc>.." @@ -157,7 +156,6 @@ func Test_gn_command() sil! %d _ set wrapscan&vim - set belloff&vim endfunc func Test_gN_repeat() diff --git a/src/nvim/testdir/test_quotestar.vim b/src/nvim/testdir/test_quotestar.vim index 77a5153a81..6e6f91362b 100644 --- a/src/nvim/testdir/test_quotestar.vim +++ b/src/nvim/testdir/test_quotestar.vim @@ -97,7 +97,7 @@ func Do_test_quotestar_for_x11() if has('unix') && has('gui') && !has('gui_running') let @* = '' - " Running in a terminal and the GUI is avaiable: Tell the server to open + " Running in a terminal and the GUI is available: Tell the server to open " the GUI and check that the remote command still works. " Need to wait for the GUI to start up, otherwise the send hangs in trying " to send to the terminal window. diff --git a/src/nvim/testdir/test_registers.vim b/src/nvim/testdir/test_registers.vim index 8d2a768ba0..53069b3d31 100644 --- a/src/nvim/testdir/test_registers.vim +++ b/src/nvim/testdir/test_registers.vim @@ -109,6 +109,8 @@ func Test_recording_esc_sequence() bwipe! if exists('save_F2') let &t_F2 = save_F2 + else + set t_F2= endif endfunc diff --git a/src/nvim/testdir/test_syntax.vim b/src/nvim/testdir/test_syntax.vim index 4cf0e983b0..66cb0bbe22 100644 --- a/src/nvim/testdir/test_syntax.vim +++ b/src/nvim/testdir/test_syntax.vim @@ -30,7 +30,7 @@ func Test_syn_iskeyword() \ 'CREATE TABLE FOOBAR(', \ ' DLTD_BY VARCHAR2(100)', \ ');', - \ '']) + \ '']) syntax on set ft=sql @@ -521,7 +521,7 @@ func Test_synstack_synIDtrans() norm f/ call assert_equal(['cComment', 'cCommentStart'], map(synstack(line("."), col(".")), 'synIDattr(v:val, "name")')) - call assert_equal(['Comment', 'Comment'], map(synstack(line("."), col(".")), 'synIDattr(synIDtrans(v:val), "name")')) + call assert_equal(['Comment', 'Comment'], map(synstack(line("."), col(".")), 'synIDattr(synIDtrans(v:val), "name")')) norm fA call assert_equal(['cComment'], map(synstack(line("."), col(".")), 'synIDattr(v:val, "name")')) diff --git a/src/nvim/testdir/test_tabpage.vim b/src/nvim/testdir/test_tabpage.vim index 2b6a89647e..b261b96c3b 100644 --- a/src/nvim/testdir/test_tabpage.vim +++ b/src/nvim/testdir/test_tabpage.vim @@ -142,9 +142,6 @@ endfunc " Test autocommands function Test_tabpage_with_autocmd() - if !has('autocmd') - return - endif command -nargs=1 -bar C :call add(s:li, '=== ' . <q-args> . ' ===')|<args> augroup TestTabpageGroup au! diff --git a/src/nvim/testdir/test_vartabs.vim b/src/nvim/testdir/test_vartabs.vim index 81e81b7fbe..2fbf130345 100644 --- a/src/nvim/testdir/test_vartabs.vim +++ b/src/nvim/testdir/test_vartabs.vim @@ -5,6 +5,7 @@ if !has("vartabs") endif source view_util.vim + func s:compare_lines(expect, actual) call assert_equal(join(a:expect, "\n"), join(a:actual, "\n")) endfunc @@ -372,3 +373,9 @@ func Test_vartabs_failures() call assert_fails('set vts=,8') call assert_fails('set vsts=,8') endfunc + +func Test_vartabs_reset() + set vts=8 + set all& + call assert_equal('', &vts) +endfunc diff --git a/src/nvim/testdir/test_visual.vim b/src/nvim/testdir/test_visual.vim index 7f50894f66..73c7960579 100644 --- a/src/nvim/testdir/test_visual.vim +++ b/src/nvim/testdir/test_visual.vim @@ -255,7 +255,6 @@ func TriggerTheProblem() endfunc func Test_visual_mode_reset() - set belloff=all enew let g:msg = "Everything's fine." enew @@ -268,7 +267,6 @@ func Test_visual_mode_reset() exe "normal! GV:call TriggerTheProblem()\<CR>" call assert_equal("Everything's fine.", g:msg) - set belloff& endfunc func Test_Visual_word_textobject() |