11local api = vim .api
22
3- local parsers = require " nvim-treesitter. parsers"
4- local utils = require " guihua.ts_obsolete.utils"
3+ local parsers = require ( ' guihua.ts_obsolete. parsers' )
4+ local utils = require ( ' guihua.ts_obsolete.utils' )
55local ts = vim .treesitter
66
77local M = {}
@@ -49,11 +49,11 @@ function M._get_line_for_node(node, type_patterns, transform_fn, bufnr)
4949 end
5050 end
5151 if not is_valid then
52- return " "
52+ return ' '
5353 end
54- local line = transform_fn (vim .trim (get_node_text (node , bufnr )[1 ] or " " ), node )
54+ local line = transform_fn (vim .trim (get_node_text (node , bufnr )[1 ] or ' ' ), node )
5555 -- Escape % to avoid statusline to evaluate content as expression
56- return line :gsub (" %% " , " %%%%" )
56+ return line :gsub (' %% ' , ' %%%%' )
5757end
5858
5959-- Gets the actual text content of a node
6363-- @return list of lines of text of the node
6464function M .get_node_text (node , bufnr )
6565 vim .notify_once (
66- " nvim-treesitter.ts_utils.get_node_text is deprecated: use vim.treesitter.get_node_text" ,
66+ ' nvim-treesitter.ts_utils.get_node_text is deprecated: use vim.treesitter.get_node_text' ,
6767 vim .log .levels .WARN
6868 )
6969 return get_node_text (node , bufnr )
@@ -200,7 +200,7 @@ function M.get_root_for_position(line, col, root_lang_tree)
200200 root_lang_tree = parsers .get_parser ()
201201 end
202202
203- local lang_tree = root_lang_tree :language_for_range { line , col , line , col }
203+ local lang_tree = root_lang_tree :language_for_range ( { line , col , line , col })
204204
205205 while true do
206206 for _ , tree in pairs (lang_tree :trees ()) do
@@ -270,7 +270,7 @@ function M.get_vim_range(range, buf)
270270 -- Use the value of the last col of the previous row instead.
271271 erow = erow - 1
272272 if not buf or buf == 0 then
273- ecol = vim .fn .col { erow , " $ " } - 1
273+ ecol = vim .fn .col ( { erow , ' $ ' }) - 1
274274 else
275275 ecol = # api .nvim_buf_get_lines (buf , erow - 1 , erow , false )[1 ]
276276 end
292292function M .update_selection (buf , node , selection_mode )
293293 local start_row , start_col , end_row , end_col = M .get_vim_range ({ ts .get_node_range (node ) }, buf )
294294
295- local v_table = { charwise = " v " , linewise = " V " , blockwise = " <C-v>" }
296- selection_mode = selection_mode or " charwise"
295+ local v_table = { charwise = ' v ' , linewise = ' V ' , blockwise = ' <C-v>' }
296+ selection_mode = selection_mode or ' charwise'
297297
298298 -- Normalise selection_mode
299299 if vim .tbl_contains (vim .tbl_keys (v_table ), selection_mode ) then
@@ -308,11 +308,11 @@ function M.update_selection(buf, node, selection_mode)
308308 if mode .mode ~= selection_mode then
309309 -- Call to `nvim_replace_termcodes()` is needed for sending appropriate command to enter blockwise mode
310310 selection_mode = vim .api .nvim_replace_termcodes (selection_mode , true , true , true )
311- api .nvim_cmd ({ cmd = " normal" , bang = true , args = { selection_mode } }, {})
311+ api .nvim_cmd ({ cmd = ' normal' , bang = true , args = { selection_mode } }, {})
312312 end
313313
314314 api .nvim_win_set_cursor (0 , { start_row , start_col - 1 })
315- vim .cmd " normal! o"
315+ vim .cmd ( ' normal! o' )
316316 api .nvim_win_set_cursor (0 , { end_row , end_col - 1 })
317317end
318318
328328--- @deprecated Use `vim.treesitter.is_in_node_range()` instead
329329function M .is_in_node_range (node , line , col )
330330 vim .notify_once (
331- " nvim-treesitter.ts_utils.is_in_node_range is deprecated: use vim.treesitter.is_in_node_range" ,
331+ ' nvim-treesitter.ts_utils.is_in_node_range is deprecated: use vim.treesitter.is_in_node_range' ,
332332 vim .log .levels .WARN
333333 )
334334 return ts .is_in_node_range (node , line , col )
337337--- @deprecated Use `vim.treesitter.get_node_range()` instead
338338function M .get_node_range (node_or_range )
339339 vim .notify_once (
340- " nvim-treesitter.ts_utils.get_node_range is deprecated: use vim.treesitter.get_node_range" ,
340+ ' nvim-treesitter.ts_utils.get_node_range is deprecated: use vim.treesitter.get_node_range' ,
341341 vim .log .levels .WARN
342342 )
343343 return ts .get_node_range (node_or_range )
@@ -349,7 +349,7 @@ function M.node_to_lsp_range(node)
349349 local start_line , start_col , end_line , end_col = ts .get_node_range (node )
350350 local rtn = {}
351351 rtn .start = { line = start_line , character = start_col }
352- rtn [" end" ] = { line = end_line , character = end_col }
352+ rtn [' end' ] = { line = end_line , character = end_col }
353353 return rtn
354354end
355355
@@ -365,7 +365,7 @@ function M.memoize_by_buf_tick(fn, options)
365365 options = options or {}
366366
367367 --- @type table<string , { result : any , last_tick : integer } >
368- local cache = setmetatable ({}, { __mode = " kv " })
368+ local cache = setmetatable ({}, { __mode = ' kv ' })
369369 local bufnr_fn = utils .to_func (options .bufnr or utils .identity )
370370 local key_fn = utils .to_func (options .key or utils .identity )
371371
@@ -409,32 +409,32 @@ function M.swap_nodes(node_or_range1, node_or_range2, bufnr, cursor_to_second)
409409 local text1 = get_node_text (node_or_range1 , bufnr )
410410 local text2 = get_node_text (node_or_range2 , bufnr )
411411
412- local edit1 = { range = range1 , newText = table.concat (text2 , " \n " ) }
413- local edit2 = { range = range2 , newText = table.concat (text1 , " \n " ) }
412+ local edit1 = { range = range1 , newText = table.concat (text2 , ' \n ' ) }
413+ local edit2 = { range = range2 , newText = table.concat (text1 , ' \n ' ) }
414414 bufnr = bufnr == 0 and vim .api .nvim_get_current_buf () or bufnr
415- vim .lsp .util .apply_text_edits ({ edit1 , edit2 }, bufnr , " utf-8" )
415+ vim .lsp .util .apply_text_edits ({ edit1 , edit2 }, bufnr , ' utf-8' )
416416
417417 if cursor_to_second then
418418 utils .set_jump ()
419419
420420 local char_delta = 0
421421 local line_delta = 0
422422 if
423- range1 [" end" ].line < range2 .start .line
424- or (range1 [" end" ].line == range2 .start .line and range1 [" end" ].character <= range2 .start .character )
423+ range1 [' end' ].line < range2 .start .line
424+ or (range1 [' end' ].line == range2 .start .line and range1 [' end' ].character <= range2 .start .character )
425425 then
426426 line_delta = # text2 - # text1
427427 end
428428
429- if range1 [" end" ].line == range2 .start .line and range1 [" end" ].character <= range2 .start .character then
429+ if range1 [' end' ].line == range2 .start .line and range1 [' end' ].character <= range2 .start .character then
430430 if line_delta ~= 0 then
431431 --- why?
432432 -- correction_after_line_change = -range2.start.character
433433 -- text_now_before_range2 = #(text2[#text2])
434434 -- space_between_ranges = range2.start.character - range1["end"].character
435435 -- char_delta = correction_after_line_change + text_now_before_range2 + space_between_ranges
436436 --- Equivalent to:
437- char_delta = # text2 [# text2 ] - range1 [" end" ].character
437+ char_delta = # text2 [# text2 ] - range1 [' end' ].character
438438
439439 -- add range1.start.character if last line of range1 (now text2) does not start at 0
440440 if range1 .start .line == range2 .start .line + line_delta then
@@ -459,7 +459,7 @@ function M.goto_node(node, goto_end, avoid_set_jump)
459459 if not avoid_set_jump then
460460 utils .set_jump ()
461461 end
462- local range = { M .get_vim_range { node :range () } }
462+ local range = { M .get_vim_range ( { node :range () }) }
463463 --- @type table<number>
464464 local position
465465 if not goto_end then
@@ -471,8 +471,8 @@ function M.goto_node(node, goto_end, avoid_set_jump)
471471 -- Enter visual mode if we are in operator pending mode
472472 -- If we don't do this, it will miss the last character.
473473 local mode = vim .api .nvim_get_mode ()
474- if mode .mode == " no " then
475- vim .cmd " normal! v"
474+ if mode .mode == ' no ' then
475+ vim .cmd ( ' normal! v' )
476476 end
477477
478478 -- Position is 1, 0 indexed.
0 commit comments