aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--runtime/autoload/health/provider.vim44
-rw-r--r--runtime/autoload/provider/node.vim19
-rw-r--r--runtime/autoload/provider/perl.vim28
-rw-r--r--runtime/autoload/provider/ruby.vim3
-rw-r--r--runtime/doc/api.txt29
-rw-r--r--runtime/doc/cmdline.txt1
-rw-r--r--runtime/doc/eval.txt16
-rw-r--r--runtime/doc/if_perl.txt268
-rw-r--r--runtime/doc/index.txt3
-rw-r--r--runtime/doc/lua.txt12
-rw-r--r--runtime/doc/provider.txt6
-rw-r--r--runtime/doc/vim_diff.txt1
-rw-r--r--runtime/lua/vim/highlight.lua2
-rw-r--r--runtime/lua/vim/treesitter/highlighter.lua3
-rw-r--r--runtime/lua/vim/treesitter/query.lua47
-rw-r--r--src/nvim/api/buffer.c60
-rw-r--r--src/nvim/api/ui_events.in.h2
-rw-r--r--src/nvim/api/vim.c6
-rw-r--r--src/nvim/eval.lua1
-rw-r--r--src/nvim/eval/decode.c2
-rw-r--r--src/nvim/eval/funcs.c8
-rw-r--r--src/nvim/ex_cmds.lua10
-rw-r--r--src/nvim/ex_cmds2.c15
-rw-r--r--src/nvim/fold.c3
-rw-r--r--src/nvim/screen.c2
-rw-r--r--src/nvim/testdir/test_perl.vim225
-rw-r--r--src/nvim/testdir/test_window_cmd.vim42
-rw-r--r--src/nvim/tui/tui.c40
-rw-r--r--src/nvim/ui_bridge.c1
-rw-r--r--src/nvim/version.c2
-rw-r--r--src/nvim/viml/parser/expressions.c2
-rw-r--r--src/tree_sitter/alloc.h6
-rw-r--r--src/tree_sitter/lexer.c2
-rw-r--r--src/tree_sitter/parser.c81
-rw-r--r--src/tree_sitter/query.c416
-rw-r--r--src/tree_sitter/stack.c11
-rw-r--r--src/tree_sitter/treesitter_commit_hash.txt2
-rw-r--r--test/functional/api/extmark_spec.lua63
-rw-r--r--test/functional/helpers.lua10
-rw-r--r--test/functional/lua/treesitter_spec.lua18
-rw-r--r--test/functional/provider/perl_spec.lua50
-rw-r--r--test/functional/ui/bufhl_spec.lua6
42 files changed, 1245 insertions, 323 deletions
diff --git a/runtime/autoload/health/provider.vim b/runtime/autoload/health/provider.vim
index 0482cb7f3c..e8e38f581f 100644
--- a/runtime/autoload/health/provider.vim
+++ b/runtime/autoload/health/provider.vim
@@ -573,7 +573,7 @@ function! s:check_ruby() abort
endif
call health#report_info('Ruby: '. s:system('ruby -v'))
- let host = provider#ruby#Detect()
+ let [host, err] = provider#ruby#Detect()
if empty(host)
call health#report_warn('`neovim-ruby-host` not found.',
\ ['Run `gem install neovim` to ensure the neovim RubyGem is installed.',
@@ -636,7 +636,7 @@ function! s:check_node() abort
call health#report_warn('node.js on this system does not support --inspect-brk so $NVIM_NODE_HOST_DEBUG is ignored.')
endif
- let host = provider#node#Detect()
+ let [host, err] = provider#node#Detect()
if empty(host)
call health#report_warn('Missing "neovim" npm (or yarn) package.',
\ ['Run in shell: npm install -g neovim',
@@ -689,29 +689,31 @@ function! s:check_perl() abort
return
endif
- if !executable('perl') || !executable('cpanm')
- call health#report_warn(
- \ '`perl` and `cpanm` must be in $PATH.',
- \ ['Install Perl and cpanminus and verify that `perl` and `cpanm` commands work.'])
- return
+ let [perl_exec, perl_errors] = provider#perl#Detect()
+ if empty(perl_exec)
+ if !empty(perl_errors)
+ call health#report_error('perl provider error:', perl_errors)
+ else
+ call health#report_warn('No usable perl executable found')
+ endif
+ return
endif
- let perl_v = get(split(s:system(['perl', '-W', '-e', 'print $^V']), "\n"), 0, '')
- call health#report_info('Perl: '. perl_v)
+
+ call health#report_info('perl executable: '. perl_exec)
+
+ " we cannot use cpanm that is on the path, as it may not be for the perl
+ " set with g:perl_host_prog
+ call s:system([perl_exec, '-W', '-MApp::cpanminus', '-e', ''])
if s:shell_error
- call health#report_warn('Nvim perl host does not support '.perl_v)
- " Skip further checks, they are nonsense if perl is too old.
- return
+ return [perl_exec, '"App::cpanminus" module is not installed']
endif
- let host = provider#perl#Detect()
- if empty(host)
- call health#report_warn('Missing "Neovim::Ext" cpan module.',
- \ ['Run in shell: cpanm Neovim::Ext'])
- return
- endif
- call health#report_info('Nvim perl host: '. host)
+ let latest_cpan_cmd = [perl_exec,
+ \ '-MApp::cpanminus::fatscript', '-e',
+ \ 'my $app = App::cpanminus::script->new;
+ \ $app->parse_options ("--info", "-q", "Neovim::Ext");
+ \ exit $app->doit']
- let latest_cpan_cmd = 'cpanm --info -q Neovim::Ext'
let latest_cpan = s:system(latest_cpan_cmd)
if s:shell_error || empty(latest_cpan)
call health#report_error('Failed to run: '. latest_cpan_cmd,
@@ -735,7 +737,7 @@ function! s:check_perl() abort
return
endif
- let current_cpan_cmd = [host, '-W', '-MNeovim::Ext', '-e', 'print $Neovim::Ext::VERSION']
+ let current_cpan_cmd = [perl_exec, '-W', '-MNeovim::Ext', '-e', 'print $Neovim::Ext::VERSION']
let current_cpan = s:system(current_cpan_cmd)
if s:shell_error
call health#report_error('Failed to run: '. string(current_cpan_cmd),
diff --git a/runtime/autoload/provider/node.vim b/runtime/autoload/provider/node.vim
index c5d5e87729..17b6137816 100644
--- a/runtime/autoload/provider/node.vim
+++ b/runtime/autoload/provider/node.vim
@@ -48,14 +48,15 @@ function! provider#node#can_inspect() abort
endfunction
function! provider#node#Detect() abort
+ let minver = [6, 0]
if exists('g:node_host_prog')
- return expand(g:node_host_prog)
+ return [expand(g:node_host_prog), '']
endif
if !executable('node')
- return ''
+ return ['', 'node not found (or not executable)']
endif
- if !s:is_minimum_version(v:null, 6, 0)
- return ''
+ if !s:is_minimum_version(v:null, minver[0], minver[1])
+ return ['', printf('node version %s.%s not found', minver[0], minver[1])]
endif
let npm_opts = {}
@@ -75,7 +76,7 @@ function! provider#node#Detect() abort
if has('unix')
let yarn_default_path = $HOME . '/.config/yarn/global/' . yarn_opts.entry_point
if filereadable(yarn_default_path)
- return yarn_default_path
+ return [yarn_default_path, '']
endif
endif
let yarn_opts.job_id = jobstart('yarn global dir', yarn_opts)
@@ -85,18 +86,18 @@ function! provider#node#Detect() abort
if !empty(npm_opts)
let result = jobwait([npm_opts.job_id])
if result[0] == 0 && npm_opts.result != ''
- return npm_opts.result
+ return [npm_opts.result, '']
endif
endif
if !empty(yarn_opts)
let result = jobwait([yarn_opts.job_id])
if result[0] == 0 && yarn_opts.result != ''
- return yarn_opts.result
+ return [yarn_opts.result, '']
endif
endif
- return ''
+ return ['', 'failed to detect node']
endfunction
function! provider#node#Prog() abort
@@ -142,7 +143,7 @@ endfunction
let s:err = ''
-let s:prog = provider#node#Detect()
+let [s:prog, s:_] = provider#node#Detect()
let g:loaded_node_provider = empty(s:prog) ? 1 : 2
if g:loaded_node_provider != 2
diff --git a/runtime/autoload/provider/perl.vim b/runtime/autoload/provider/perl.vim
index 36ca2bbf14..24f2b018bb 100644
--- a/runtime/autoload/provider/perl.vim
+++ b/runtime/autoload/provider/perl.vim
@@ -5,15 +5,25 @@ endif
let s:loaded_perl_provider = 1
function! provider#perl#Detect() abort
- " use g:perl_host_prof if set or check if perl is on the path
+ " use g:perl_host_prog if set or check if perl is on the path
let prog = exepath(get(g:, 'perl_host_prog', 'perl'))
if empty(prog)
- return ''
+ return ['', '']
+ endif
+
+ " if perl is available, make sure we have 5.22+
+ call system([prog, '-e', 'use v5.22'])
+ if v:shell_error
+ return ['', 'Perl version is too old, 5.22+ required']
endif
" if perl is available, make sure the required module is available
call system([prog, '-W', '-MNeovim::Ext', '-e', ''])
- return v:shell_error ? '' : prog
+ if v:shell_error
+ return ['', '"Neovim::Ext" cpan module is not installed']
+ endif
+
+ return [prog, '']
endfunction
function! provider#perl#Prog() abort
@@ -46,7 +56,7 @@ function! provider#perl#Call(method, args) abort
if !exists('s:host')
try
- let s:host = remote#host#Require('perl')
+ let s:host = remote#host#Require('legacy-perl-provider')
catch
let s:err = v:exception
echohl WarningMsg
@@ -58,12 +68,16 @@ function! provider#perl#Call(method, args) abort
return call('rpcrequest', insert(insert(a:args, 'perl_'.a:method), s:host))
endfunction
-let s:err = ''
-let s:prog = provider#perl#Detect()
+let [s:prog, s:err] = provider#perl#Detect()
let g:loaded_perl_provider = empty(s:prog) ? 1 : 2
if g:loaded_perl_provider != 2
let s:err = 'Cannot find perl or the required perl module'
endif
-call remote#host#RegisterPlugin('perl-provider', 'perl', [])
+
+" The perl provider plugin will run in a separate instance of the perl
+" host.
+call remote#host#RegisterClone('legacy-perl-provider', 'perl')
+call remote#host#RegisterPlugin('legacy-perl-provider', 'ScriptHost.pm', [])
+
diff --git a/runtime/autoload/provider/ruby.vim b/runtime/autoload/provider/ruby.vim
index f843050df9..1f49c623ac 100644
--- a/runtime/autoload/provider/ruby.vim
+++ b/runtime/autoload/provider/ruby.vim
@@ -5,7 +5,8 @@ endif
let g:loaded_ruby_provider = 1
function! provider#ruby#Detect() abort
- return s:prog
+ let e = empty(s:prog) ? 'missing ruby or ruby-host' : ''
+ return [s:prog, e]
endfunction
function! provider#ruby#Prog() abort
diff --git a/runtime/doc/api.txt b/runtime/doc/api.txt
index 851f63ead2..0d896f33f4 100644
--- a/runtime/doc/api.txt
+++ b/runtime/doc/api.txt
@@ -336,7 +336,7 @@ callbacks. These callbacks are called frequently in various contexts;
|textlock| prevents changing buffer contents and window layout (use
|vim.schedule| to defer such operations to the main loop instead).
-|nvim_buf_attach| will take keyword args for the callbacks. "on_lines" will
+|nvim_buf_attach()| will take keyword args for the callbacks. "on_lines" will
receive parameters ("lines", {buf}, {changedtick}, {firstline}, {lastline},
{new_lastline}, {old_byte_size}[, {old_utf32_size}, {old_utf16_size}]).
Unlike remote channel events the text contents are not passed. The new text can
@@ -355,7 +355,7 @@ was changed. The parameters recieved are ("changedtick", {buf}, {changedtick}).
*api-lua-detach*
In-process Lua callbacks can detach by returning `true`. This will detach all
-callbacks attached with the same |nvim_buf_attach| call.
+callbacks attached with the same |nvim_buf_attach()| call.
==============================================================================
@@ -1603,19 +1603,20 @@ nvim_buf_add_highlight({buffer}, {src_id}, {hl_group}, {line},
marks do.
Namespaces are used for batch deletion/updating of a set of
- highlights. To create a namespace, use |nvim_create_namespace|
- which returns a namespace id. Pass it in to this function as
- `ns_id` to add highlights to the namespace. All highlights in
- the same namespace can then be cleared with single call to
- |nvim_buf_clear_namespace|. If the highlight never will be
- deleted by an API call, pass `ns_id = -1` .
+ highlights. To create a namespace, use
+ |nvim_create_namespace()| which returns a namespace id. Pass
+ it in to this function as `ns_id` to add highlights to the
+ namespace. All highlights in the same namespace can then be
+ cleared with single call to |nvim_buf_clear_namespace()|. If
+ the highlight never will be deleted by an API call, pass
+ `ns_id = -1` .
As a shorthand, `ns_id = 0` can be used to create a new
namespace for the highlight, the allocated id is then
returned. If `hl_group` is the empty string no highlight is
added, but a new `ns_id` is still returned. This is supported
for backwards compatibility, new code should use
- |nvim_create_namespace| to create a new empty namespace.
+ |nvim_create_namespace()| to create a new empty namespace.
Parameters: ~
{buffer} Buffer handle, or 0 for current buffer
@@ -2066,12 +2067,12 @@ nvim_buf_set_virtual_text({buffer}, {src_id}, {line}, {chunks},
Namespaces are used to support batch deletion/updating of
virtual text. To create a namespace, use
- |nvim_create_namespace|. Virtual text is cleared using
- |nvim_buf_clear_namespace|. The same `ns_id` can be used for
+ |nvim_create_namespace()|. Virtual text is cleared using
+ |nvim_buf_clear_namespace()|. The same `ns_id` can be used for
both virtual text and highlights added by
- |nvim_buf_add_highlight|, both can then be cleared with a
- single call to |nvim_buf_clear_namespace|. If the virtual text
- never will be cleared by an API call, pass `ns_id = -1` .
+ |nvim_buf_add_highlight()|, both can then be cleared with a
+ single call to |nvim_buf_clear_namespace()|. If the virtual
+ text never will be cleared by an API call, pass `ns_id = -1` .
As a shorthand, `ns_id = 0` can be used to create a new
namespace for the virtual text, the allocated id is then
diff --git a/runtime/doc/cmdline.txt b/runtime/doc/cmdline.txt
index b31177ce0e..163dc81804 100644
--- a/runtime/doc/cmdline.txt
+++ b/runtime/doc/cmdline.txt
@@ -556,6 +556,7 @@ followed by another Vim command:
:lfdo
:make
:normal
+ :perlfile
:promptfind
:promptrepl
:pyfile
diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt
index 48b41ea1b0..5127a9f390 100644
--- a/runtime/doc/eval.txt
+++ b/runtime/doc/eval.txt
@@ -2288,6 +2288,7 @@ nr2char({expr}[, {utf8}]) String single char with ASCII/UTF8 value {expr}
nvim_...({args}...) any call nvim |api| functions
or({expr}, {expr}) Number bitwise OR
pathshorten({expr}) String shorten directory names in a path
+perleval({expr}) any evaluate |perl| expression
pow({x}, {y}) Float {x} to the power of {y}
prevnonblank({lnum}) Number line nr of non-blank line <= {lnum}
printf({fmt}, {expr1}...) String format text
@@ -6423,6 +6424,21 @@ pathshorten({expr}) *pathshorten()*
< ~/.c/n/a/file1.vim ~
It doesn't matter if the path exists or not.
+perleval({expr}) *perleval()*
+ Evaluate |perl| expression {expr} and return its result
+ converted to Vim data structures.
+ Numbers and strings are returned as they are (strings are
+ copied though).
+ Lists are represented as Vim |List| type.
+ Dictionaries are represented as Vim |Dictionary| type,
+ non-string keys result in error.
+
+ Note: If you want an array or hash, {expr} must return a
+ reference to it.
+ Example: >
+ :echo perleval('[1 .. 4]')
+< [1, 2, 3, 4]
+
pow({x}, {y}) *pow()*
Return the power of {x} to the exponent {y} as a |Float|.
{x} and {y} must evaluate to a |Float| or a |Number|.
diff --git a/runtime/doc/if_perl.txt b/runtime/doc/if_perl.txt
new file mode 100644
index 0000000000..f1d07ddb20
--- /dev/null
+++ b/runtime/doc/if_perl.txt
@@ -0,0 +1,268 @@
+*if_perl.txt* Nvim
+
+
+ VIM REFERENCE MANUAL by Jacques Germishuys
+
+The perl Interface to Vim *if_perl* *perl*
+
+See |provider-perl| for more information.
+
+ Type |gO| to see the table of contents.
+
+==============================================================================
+1. Commands *perl-commands*
+
+ *:perl*
+:[range]perl {stmt}
+ Execute perl statement {stmt}. The current package is
+ "main". A simple check if the `:perl` command is
+ working: >
+ :perl print "Hello"
+
+:[range]perl << [endmarker]
+{script}
+{endmarker}
+ Execute perl script {script}. Useful for including
+ perl code in Vim scripts. Requires perl, see
+ |script-here|.
+
+The {endmarker} below the {script} must NOT be preceded by any white space.
+
+If [endmarker] is omitted from after the "<<", a dot '.' must be used after
+{script}, like for the |:append| and |:insert| commands.
+
+Example: >
+ function! MyVimMethod()
+ perl << EOF
+ sub my_vim_method
+ {
+ print "Hello World!\n";
+ }
+ EOF
+ endfunction
+
+To see what version of perl you have: >
+
+ :perl print $^V
+<
+ *:perldo*
+:[range]perldo {cmd} Execute perl command {cmd} for each line in the[range],
+ with $_ being set to the test of each line in turn,
+ without a trailing <EOL>. In addition to $_, $line and
+ $linenr is also set to the line content and line number
+ respectively. Setting $_ will change the text, but note
+ that it is not possible to add or delete lines using
+ this command.
+ The default for [range] is the whole file: "1,$".
+
+Examples:
+>
+ :perldo $_ = reverse($_);
+ :perldo $_ = "".$linenr." => $line";
+
+One can use `:perldo` in conjunction with `:perl` to filter a range using
+perl. For example: >
+
+ :perl << EOF
+ sub perl_vim_string_replace
+ {
+ my $line = shift;
+ my $needle = $vim->eval('@a');
+ my $replacement = $vim->eval('@b');
+ $line =~ s/$needle/$replacement/g;
+ return $line;
+ }
+ EOF
+ :let @a='somevalue'
+ :let @b='newvalue'
+ :'<,'>perldo $_ = perl_vim_string_replace($_)
+<
+ *:perlfile*
+:[range]perlfile {file}
+ Execute the perl script in {file}. The whole
+ argument is used as a single file name.
+
+Both of these commands do essentially the same thing - they execute a piece of
+perl code, with the "current range" set to the given line range.
+
+In the case of :perl, the code to execute is in the command-line.
+In the case of :perlfile, the code to execute is the contents of the given file.
+
+perl commands cannot be used in the |sandbox|.
+
+To pass arguments you need to set @ARGV explicitly. Example: >
+
+ :perl @ARGV = ("foo", "bar");
+ :perlfile myscript.pl
+
+Here are some examples *perl-examples* >
+
+ :perl print "Hello"
+ :perl $current->line (uc ($current->line))
+ :perl my $str = $current->buffer->[42]; print "Set \$str to: $str"
+
+Note that changes (such as the "use" statements) persist from one command
+to the next.
+
+==============================================================================
+2. The VIM module *perl-vim*
+
+Perl code gets all of its access to Neovim via the "VIM" module.
+
+Overview >
+ print "Hello" # displays a message
+ VIM::Msg("Hello") # displays a message
+ VIM::SetOption("ai") # sets a vim option
+ $nbuf = VIM::Buffers() # returns the number of buffers
+ @buflist = VIM::Buffers() # returns array of all buffers
+ $mybuf = (VIM::Buffers('a.c'))[0] # returns buffer object for 'a.c'
+ @winlist = VIM::Windows() # returns array of all windows
+ $nwin = VIM::Windows() # returns the number of windows
+ ($success, $v) = VIM::Eval('&path') # $v: option 'path', $success: 1
+ ($success, $v) = VIM::Eval('&xyz') # $v: '' and $success: 0
+ $v = VIM::Eval('expand("<cfile>")') # expands <cfile>
+ $curwin->SetHeight(10) # sets the window height
+ @pos = $curwin->Cursor() # returns (row, col) array
+ @pos = (10, 10)
+ $curwin->Cursor(@pos) # sets cursor to @pos
+ $curwin->Cursor(10,10) # sets cursor to row 10 col 10
+ $mybuf = $curwin->Buffer() # returns the buffer object for window
+ $curbuf->Name() # returns buffer name
+ $curbuf->Number() # returns buffer number
+ $curbuf->Count() # returns the number of lines
+ $l = $curbuf->Get(10) # returns line 10
+ @l = $curbuf->Get(1 .. 5) # returns lines 1 through 5
+ $curbuf->Delete(10) # deletes line 10
+ $curbuf->Delete(10, 20) # delete lines 10 through 20
+ $curbuf->Append(10, "Line") # appends a line
+ $curbuf->Append(10, "L1", "L2", "L3") # appends 3 lines
+ @l = ("L1", "L2", "L3")
+ $curbuf->Append(10, @l) # appends L1, L2 and L3
+ $curbuf->Set(10, "Line") # replaces line 10
+ $curbuf->Set(10, "Line1", "Line2") # replaces lines 10 and 11
+ $curbuf->Set(10, @l) # replaces 3 lines
+
+Module Functions:
+
+ *perl-Msg*
+VIM::Msg({msg})
+ Displays the message {msg}.
+
+ *perl-SetOption*
+VIM::SetOption({arg}) Sets a vim option. {arg} can be any argument that the
+ ":set" command accepts. Note that this means that no
+ spaces are allowed in the argument! See |:set|.
+
+ *perl-Buffers*
+VIM::Buffers([{bn}...]) With no arguments, returns a list of all the buffers
+ in an array context or returns the number of buffers
+ in a scalar context. For a list of buffer names or
+ numbers {bn}, returns a list of the buffers matching
+ {bn}, using the same rules as Vim's internal
+ |bufname()| function.
+ WARNING: the list becomes invalid when |:bwipe| is
+ used.
+
+ *perl-Windows*
+VIM::Windows([{wn}...]) With no arguments, returns a list of all the windows
+ in an array context or returns the number of windows
+ in a scalar context. For a list of window numbers
+ {wn}, returns a list of the windows with those
+ numbers.
+ WARNING: the list becomes invalid when a window is
+ closed.
+
+ *perl-DoCommand*
+VIM::DoCommand({cmd}) Executes Ex command {cmd}.
+
+ *perl-Eval*
+VIM::Eval({expr}) Evaluates {expr} and returns (success, value) in list
+ context or just value in scalar context.
+ success=1 indicates that val contains the value of
+ {expr}; success=0 indicates a failure to evaluate
+ the expression. '@x' returns the contents of register
+ x, '&x' returns the value of option x, 'x' returns the
+ value of internal |variables| x, and '$x' is equivalent
+ to perl's $ENV{x}. All |functions| accessible from
+ the command-line are valid for {expr}.
+ A |List| is turned into a string by joining the items
+ and inserting line breaks.
+
+==============================================================================
+3. VIM::Buffer objects *perl-buffer*
+
+Methods:
+
+ *perl-Buffer-Name*
+Name() Returns the filename for the Buffer.
+
+ *perl-Buffer-Number*
+Number() Returns the number of the Buffer.
+
+ *perl-Buffer-Count*
+Count() Returns the number of lines in the Buffer.
+
+ *perl-Buffer-Get*
+Get({lnum}, {lnum}?, ...)
+ Returns a text string of line {lnum} in the Buffer
+ for each {lnum} specified. An array can be passed
+ with a list of {lnum}'s specified.
+
+ *perl-Buffer-Delete*
+Delete({lnum}, {lnum}?)
+ Deletes line {lnum} in the Buffer. With the second
+ {lnum}, deletes the range of lines from the first
+ {lnum} to the second {lnum}.
+
+ *perl-Buffer-Append*
+Append({lnum}, {line}, {line}?, ...)
+ Appends each {line} string after Buffer line {lnum}.
+ The list of {line}s can be an array.
+
+ *perl-Buffer-Set*
+Set({lnum}, {line}, {line}?, ...)
+ Replaces one or more Buffer lines with specified
+ {lines}s, starting at Buffer line {lnum}. The list of
+ {line}s can be an array. If the arguments are
+ invalid, replacement does not occur.
+
+==============================================================================
+4. VIM::Window objects *perl-window*
+
+Methods:
+ *perl-Window-SetHeight*
+SetHeight({height})
+ Sets the Window height to {height}, within screen
+ limits.
+
+ *perl-Window-GetCursor*
+Cursor({row}?, {col}?)
+ With no arguments, returns a (row, col) array for the
+ current cursor position in the Window. With {row} and
+ {col} arguments, sets the Window's cursor position to
+ {row} and {col}. Note that {col} is numbered from 0,
+ Perl-fashion, and thus is one less than the value in
+ Vim's ruler.
+
+Buffer() *perl-Window-Buffer*
+ Returns the Buffer object corresponding to the given
+ Window.
+
+==============================================================================
+5. Lexical variables *perl-globals*
+
+There are multiple lexical variables.
+
+$curwin The current Window object.
+$curbuf The current Buffer object.
+$vim A Neovim::Ext object.
+$nvim The same as $nvim.
+$current A Neovim::Ext::Current object.
+
+These are also available via the "main" package:
+
+$main::curwin The current Window object.
+$main::curbuf The current Buffer object.
+
+==============================================================================
+ vim:tw=78:ts=8:noet:ft=help:norl:
diff --git a/runtime/doc/index.txt b/runtime/doc/index.txt
index bdab10c0e4..afcacad460 100644
--- a/runtime/doc/index.txt
+++ b/runtime/doc/index.txt
@@ -1441,6 +1441,9 @@ tag command action ~
|:packloadall| :packl[oadall] load all packages under 'packpath'
|:pclose| :pc[lose] close preview window
|:pedit| :ped[it] edit file in the preview window
+|:perl| :perl execute perl command
+|:perldo| :perldo execute perl command for each line
+|:perfile| :perlfile execute perl script file
|:print| :p[rint] print lines
|:profdel| :profd[el] stop profiling a function or script
|:profile| :prof[ile] profiling functions and scripts
diff --git a/runtime/doc/lua.txt b/runtime/doc/lua.txt
index e692274383..050483fb5e 100644
--- a/runtime/doc/lua.txt
+++ b/runtime/doc/lua.txt
@@ -756,14 +756,15 @@ Here is a list of built-in predicates :
((node1) @left (node2) @right (#eq? @left @right))
<
`match?` *ts-predicate-match?*
- This will match if the provived lua regex matches the text
+ `vim-match?` *ts-predicate-vim-match?*
+ This will match if the provived vim regex matches the text
corresponding to a node : >
((idenfitier) @constant (#match? @constant "^[A-Z_]+$"))
< Note: the `^` and `$` anchors will respectively match the
start and end of the node's text.
- `vim-match?` *ts-predicate-vim-match?*
- This will match the same way than |match?| but using vim
+ `lua-match?` *ts-predicate-lua-match?*
+ This will match the same way than |match?| but using lua
regexes.
`contains?` *ts-predicate-contains?*
@@ -782,6 +783,11 @@ vim.treesitter.query.add_predicate({name}, {handler})
This adds a predicate with the name {name} to be used in queries.
{handler} should be a function whose signature will be : >
handler(match, pattern, bufnr, predicate)
+<
+ *vim.treesitter.query.list_predicates()*
+vim.treesitter.query.list_predicates()
+
+This lists the currently available predicates to use in queries.
Treesitter syntax highlighting (WIP) *lua-treesitter-highlight*
diff --git a/runtime/doc/provider.txt b/runtime/doc/provider.txt
index a92f3ed712..f944689d0b 100644
--- a/runtime/doc/provider.txt
+++ b/runtime/doc/provider.txt
@@ -129,9 +129,13 @@ To use the RVM "system" Ruby installation: >
==============================================================================
Perl integration *provider-perl*
-Nvim supports Perl |remote-plugin|s.
+Nvim supports Perl |remote-plugin|s on Unix platforms. Support for polling STDIN
+on MS-Windows is currently lacking from all known event loop implementations.
+The Vim legacy |perl-vim| interface is also supported (which is itself
+implemented as a Nvim remote-plugin).
https://github.com/jacquesg/p5-Neovim-Ext
+Note: Only perl versions from 5.22 onward are supported.
PERL QUICKSTART~
diff --git a/runtime/doc/vim_diff.txt b/runtime/doc/vim_diff.txt
index 7b121be579..4bcea3e3fe 100644
--- a/runtime/doc/vim_diff.txt
+++ b/runtime/doc/vim_diff.txt
@@ -408,7 +408,6 @@ Some legacy Vim features are not implemented:
- |if_lua|: Nvim Lua API is not compatible with Vim's "if_lua"
- *if_mzscheme*
-- *if_perl*
- |if_py|: *python-bindeval* *python-Function* are not supported
- *if_tcl*
diff --git a/runtime/lua/vim/highlight.lua b/runtime/lua/vim/highlight.lua
index ce0a3de520..705b34dc99 100644
--- a/runtime/lua/vim/highlight.lua
+++ b/runtime/lua/vim/highlight.lua
@@ -14,7 +14,7 @@ function highlight.range(bufnr, ns, higroup, start, finish, rtype, inclusive)
inclusive = inclusive or false
-- sanity check
- if start[2] < 0 or finish[2] < start[2] then return end
+ if start[2] < 0 or finish[1] < start[1] then return end
local region = vim.region(bufnr, start, finish, rtype, inclusive)
for linenr, cols in pairs(region) do
diff --git a/runtime/lua/vim/treesitter/highlighter.lua b/runtime/lua/vim/treesitter/highlighter.lua
index bb78b5654c..1acf888821 100644
--- a/runtime/lua/vim/treesitter/highlighter.lua
+++ b/runtime/lua/vim/treesitter/highlighter.lua
@@ -98,7 +98,8 @@ function TSHighlighter:get_hl_from_capture(capture)
return vim.split(name, '.', true)[1]
else
-- Default to false to avoid recomputing
- return a.nvim_get_hl_id_by_name(TSHighlighter.hl_map[name])
+ local hl = TSHighlighter.hl_map[name]
+ return hl and a.nvim_get_hl_id_by_name(hl) or 0
end
end
diff --git a/runtime/lua/vim/treesitter/query.lua b/runtime/lua/vim/treesitter/query.lua
index 803b9edbf0..ca27a50c6a 100644
--- a/runtime/lua/vim/treesitter/query.lua
+++ b/runtime/lua/vim/treesitter/query.lua
@@ -60,7 +60,7 @@ local predicate_handlers = {
return true
end,
- ["match?"] = function(match, _, bufnr, predicate)
+ ["lua-match?"] = function(match, _, bufnr, predicate)
local node = match[predicate[2]]
local regex = predicate[3]
local start_row, _, end_row, _ = node:range()
@@ -71,7 +71,7 @@ local predicate_handlers = {
return string.find(M.get_node_text(node, bufnr), regex)
end,
- ["vim-match?"] = (function()
+ ["match?"] = (function()
local magic_prefixes = {['\\v']=true, ['\\m']=true, ['\\M']=true, ['\\V']=true}
local function check_magic(str)
if string.len(str) < 2 or magic_prefixes[string.sub(str,1,2)] then
@@ -114,6 +114,9 @@ local predicate_handlers = {
end
}
+-- As we provide lua-match? also expose vim-match?
+predicate_handlers["vim-match?"] = predicate_handlers["match?"]
+
--- Adds a new predicates to be used in queries
--
-- @param name the name of the predicate, without leading #
@@ -127,25 +130,43 @@ function M.add_predicate(name, handler, force)
predicate_handlers[name] = handler
end
+--- Returns the list of currently supported predicates
+function M.list_predicates()
+ return vim.tbl_keys(predicate_handlers)
+end
+
+local function xor(x, y)
+ return (x or y) and not (x and y)
+end
+
function Query:match_preds(match, pattern, bufnr)
local preds = self.info.patterns[pattern]
- if not preds then
- return true
- end
- for _, pred in pairs(preds) do
+
+ for _, pred in pairs(preds or {}) do
-- Here we only want to return if a predicate DOES NOT match, and
-- continue on the other case. This way unknown predicates will not be considered,
-- which allows some testing and easier user extensibility (#12173).
-- Also, tree-sitter strips the leading # from predicates for us.
+ local pred_name
+ local is_not
if string.sub(pred[1], 1, 4) == "not-" then
- local pred_name = string.sub(pred[1], 5)
- if predicate_handlers[pred_name] and
- predicate_handlers[pred_name](match, pattern, bufnr, pred) then
- return false
- end
+ pred_name = string.sub(pred[1], 5)
+ is_not = true
+ else
+ pred_name = pred[1]
+ is_not = false
+ end
+
+ local handler = predicate_handlers[pred_name]
+
+ if not handler then
+ a.nvim_err_writeln(string.format("No handler for %s", pred[1]))
+ return false
+ end
+
+ local pred_matches = handler(match, pattern, bufnr, pred)
- elseif predicate_handlers[pred[1]] and
- not predicate_handlers[pred[1]](match, pattern, bufnr, pred) then
+ if not xor(is_not, pred_matches) then
return false
end
end
diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c
index a57d8c8050..5290011325 100644
--- a/src/nvim/api/buffer.c
+++ b/src/nvim/api/buffer.c
@@ -1161,11 +1161,13 @@ static Array extmark_to_array(ExtmarkInfo extmark, bool id, bool add_dict)
/// @param buffer Buffer handle, or 0 for current buffer
/// @param ns_id Namespace id from |nvim_create_namespace()|
/// @param id Extmark id
-/// @param details Wether to include the details dict
+/// @param opts Optional parameters. Keys:
+/// - limit: Maximum number of marks to return
+/// - details Whether to include the details dict
/// @param[out] err Error details, if any
/// @return (row, col) tuple or empty list () if extmark id was absent
ArrayOf(Integer) nvim_buf_get_extmark_by_id(Buffer buffer, Integer ns_id,
- Integer id, Boolean details,
+ Integer id, Dictionary opts,
Error *err)
FUNC_API_SINCE(7)
{
@@ -1182,6 +1184,26 @@ ArrayOf(Integer) nvim_buf_get_extmark_by_id(Buffer buffer, Integer ns_id,
return rv;
}
+ bool details = false;
+ for (size_t i = 0; i < opts.size; i++) {
+ String k = opts.items[i].key;
+ Object *v = &opts.items[i].value;
+ if (strequal("details", k.data)) {
+ if (v->type == kObjectTypeBoolean) {
+ details = v->data.boolean;
+ } else if (v->type == kObjectTypeInteger) {
+ details = v->data.integer;
+ } else {
+ api_set_error(err, kErrorTypeValidation, "details is not an boolean");
+ return rv;
+ }
+ } else {
+ api_set_error(err, kErrorTypeValidation, "unexpected key: %s", k.data);
+ return rv;
+ }
+ }
+
+
ExtmarkInfo extmark = extmark_from_id(buf, (uint64_t)ns_id, (uint64_t)id);
if (extmark.row < 0) {
return rv;
@@ -1229,13 +1251,12 @@ ArrayOf(Integer) nvim_buf_get_extmark_by_id(Buffer buffer, Integer ns_id,
/// (whose position defines the bound)
/// @param opts Optional parameters. Keys:
/// - limit: Maximum number of marks to return
-/// @param details Wether to include the details dict
+/// - details Whether to include the details dict
/// @param[out] err Error details, if any
/// @return List of [extmark_id, row, col] tuples in "traversal order".
Array nvim_buf_get_extmarks(Buffer buffer, Integer ns_id,
Object start, Object end,
- Dictionary opts, Boolean details,
- Error *err)
+ Dictionary opts, Error *err)
FUNC_API_SINCE(7)
{
Array rv = ARRAY_DICT_INIT;
@@ -1249,7 +1270,9 @@ Array nvim_buf_get_extmarks(Buffer buffer, Integer ns_id,
api_set_error(err, kErrorTypeValidation, "Invalid ns_id");
return rv;
}
+
Integer limit = -1;
+ bool details = false;
for (size_t i = 0; i < opts.size; i++) {
String k = opts.items[i].key;
@@ -1260,6 +1283,15 @@ Array nvim_buf_get_extmarks(Buffer buffer, Integer ns_id,
return rv;
}
limit = v->data.integer;
+ } else if (strequal("details", k.data)) {
+ if (v->type == kObjectTypeBoolean) {
+ details = v->data.boolean;
+ } else if (v->type == kObjectTypeInteger) {
+ details = v->data.integer;
+ } else {
+ api_set_error(err, kErrorTypeValidation, "details is not an boolean");
+ return rv;
+ }
} else {
api_set_error(err, kErrorTypeValidation, "unexpected key: %s", k.data);
return rv;
@@ -1503,17 +1535,17 @@ Boolean nvim_buf_del_extmark(Buffer buffer,
/// like signs and marks do.
///
/// Namespaces are used for batch deletion/updating of a set of highlights. To
-/// create a namespace, use |nvim_create_namespace| which returns a namespace
+/// create a namespace, use |nvim_create_namespace()| which returns a namespace
/// id. Pass it in to this function as `ns_id` to add highlights to the
/// namespace. All highlights in the same namespace can then be cleared with
-/// single call to |nvim_buf_clear_namespace|. If the highlight never will be
+/// single call to |nvim_buf_clear_namespace()|. If the highlight never will be
/// deleted by an API call, pass `ns_id = -1`.
///
/// As a shorthand, `ns_id = 0` can be used to create a new namespace for the
/// highlight, the allocated id is then returned. If `hl_group` is the empty
/// string no highlight is added, but a new `ns_id` is still returned. This is
/// supported for backwards compatibility, new code should use
-/// |nvim_create_namespace| to create a new empty namespace.
+/// |nvim_create_namespace()| to create a new empty namespace.
///
/// @param buffer Buffer handle, or 0 for current buffer
/// @param ns_id namespace to use or -1 for ungrouped highlight
@@ -1615,7 +1647,7 @@ void nvim_buf_clear_namespace(Buffer buffer,
/// Clears highlights and virtual text from namespace and range of lines
///
-/// @deprecated use |nvim_buf_clear_namespace|.
+/// @deprecated use |nvim_buf_clear_namespace()|.
///
/// @param buffer Buffer handle, or 0 for current buffer
/// @param ns_id Namespace to clear, or -1 to clear all.
@@ -1679,11 +1711,11 @@ free_exit:
/// begin one cell (|lcs-eol| or space) after the ordinary text.
///
/// Namespaces are used to support batch deletion/updating of virtual text.
-/// To create a namespace, use |nvim_create_namespace|. Virtual text is
-/// cleared using |nvim_buf_clear_namespace|. The same `ns_id` can be used for
-/// both virtual text and highlights added by |nvim_buf_add_highlight|, both
-/// can then be cleared with a single call to |nvim_buf_clear_namespace|. If the
-/// virtual text never will be cleared by an API call, pass `ns_id = -1`.
+/// To create a namespace, use |nvim_create_namespace()|. Virtual text is
+/// cleared using |nvim_buf_clear_namespace()|. The same `ns_id` can be used for
+/// both virtual text and highlights added by |nvim_buf_add_highlight()|, both
+/// can then be cleared with a single call to |nvim_buf_clear_namespace()|. If
+/// the virtual text never will be cleared by an API call, pass `ns_id = -1`.
///
/// As a shorthand, `ns_id = 0` can be used to create a new namespace for the
/// virtual text, the allocated id is then returned.
diff --git a/src/nvim/api/ui_events.in.h b/src/nvim/api/ui_events.in.h
index ab31db39e9..ef5e90bf5c 100644
--- a/src/nvim/api/ui_events.in.h
+++ b/src/nvim/api/ui_events.in.h
@@ -36,6 +36,8 @@ void set_title(String title)
FUNC_API_SINCE(3);
void set_icon(String icon)
FUNC_API_SINCE(3);
+void screenshot(String path)
+ FUNC_API_SINCE(7) FUNC_API_REMOTE_IMPL;
void option_set(String name, Object value)
FUNC_API_SINCE(4) FUNC_API_BRIDGE_IMPL;
// Stop event is not exported as such, represented by EOF in the msgpack stream.
diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c
index fbd6511161..632f55f49a 100644
--- a/src/nvim/api/vim.c
+++ b/src/nvim/api/vim.c
@@ -2627,3 +2627,9 @@ void nvim__put_attr(Integer id, Integer start_row, Integer start_col,
decorations_add_luahl_attr(attr, (int)start_row, (colnr_T)start_col,
(int)end_row, (colnr_T)end_col);
}
+
+void nvim__screenshot(String path)
+ FUNC_API_FAST
+{
+ ui_call_screenshot(path);
+}
diff --git a/src/nvim/eval.lua b/src/nvim/eval.lua
index be16ddd7f6..372c950825 100644
--- a/src/nvim/eval.lua
+++ b/src/nvim/eval.lua
@@ -256,6 +256,7 @@ return {
py3eval={args=1},
pyeval={args=1},
pyxeval={args=1},
+ perleval={args=1},
range={args={1, 3}},
readdir={args={1, 2}},
readfile={args={1, 3}},
diff --git a/src/nvim/eval/decode.c b/src/nvim/eval/decode.c
index daba304f00..638fef331a 100644
--- a/src/nvim/eval/decode.c
+++ b/src/nvim/eval/decode.c
@@ -586,7 +586,7 @@ parse_json_number_check:
if (p == ints) {
emsgf(_("E474: Missing number after minus sign: %.*s"), LENP(s, e));
goto parse_json_number_fail;
- } else if (p == fracs || exps_s == fracs + 1) {
+ } else if (p == fracs || (fracs != NULL && exps_s == fracs + 1)) {
emsgf(_("E474: Missing number after decimal dot: %.*s"), LENP(s, e));
goto parse_json_number_fail;
} else if (p == exps) {
diff --git a/src/nvim/eval/funcs.c b/src/nvim/eval/funcs.c
index ac560124bf..f4d9db53c4 100644
--- a/src/nvim/eval/funcs.c
+++ b/src/nvim/eval/funcs.c
@@ -6374,6 +6374,14 @@ static void f_pyxeval(typval_T *argvars, typval_T *rettv, FunPtr fptr)
}
}
+///
+/// "perleval()" function
+///
+static void f_perleval(typval_T *argvars, typval_T *rettv, FunPtr fptr)
+{
+ script_host_eval("perl", argvars, rettv);
+}
+
/*
* "range()" function
*/
diff --git a/src/nvim/ex_cmds.lua b/src/nvim/ex_cmds.lua
index 252af409c0..a01f92df27 100644
--- a/src/nvim/ex_cmds.lua
+++ b/src/nvim/ex_cmds.lua
@@ -1927,13 +1927,19 @@ return {
command='perl',
flags=bit.bor(RANGE, EXTRA, DFLALL, NEEDARG, SBOXOK, CMDWIN, RESTRICT),
addr_type=ADDR_LINES,
- func='ex_script_ni',
+ func='ex_perl',
},
{
command='perldo',
flags=bit.bor(RANGE, EXTRA, DFLALL, NEEDARG, CMDWIN, RESTRICT),
addr_type=ADDR_LINES,
- func='ex_ni',
+ func='ex_perldo',
+ },
+ {
+ command='perlfile',
+ flags=bit.bor(RANGE, FILE1, NEEDARG, CMDWIN, RESTRICT),
+ addr_type=ADDR_LINES,
+ func='ex_perlfile',
},
{
command='pedit',
diff --git a/src/nvim/ex_cmds2.c b/src/nvim/ex_cmds2.c
index 636fc96bde..3e169f7a4e 100644
--- a/src/nvim/ex_cmds2.c
+++ b/src/nvim/ex_cmds2.c
@@ -935,6 +935,21 @@ void ex_pydo3(exarg_T *eap)
script_host_do_range("python3", eap);
}
+void ex_perl(exarg_T *eap)
+{
+ script_host_execute("perl", eap);
+}
+
+void ex_perlfile(exarg_T *eap)
+{
+ script_host_execute_file("perl", eap);
+}
+
+void ex_perldo(exarg_T *eap)
+{
+ script_host_do_range("perl", eap);
+}
+
// Command line expansion for :profile.
static enum {
PEXP_SUBCMD, ///< expand :profile sub-commands
diff --git a/src/nvim/fold.c b/src/nvim/fold.c
index 16281f40f0..c29b878491 100644
--- a/src/nvim/fold.c
+++ b/src/nvim/fold.c
@@ -2681,7 +2681,8 @@ static void foldRemove(
fold_changed = true;
continue;
}
- if (fp >= (fold_T *)(gap->ga_data) + gap->ga_len
+ if (gap->ga_data == NULL
+ || fp >= (fold_T *)(gap->ga_data) + gap->ga_len
|| fp->fd_top > bot) {
// 6: Found a fold below bot, can stop looking.
break;
diff --git a/src/nvim/screen.c b/src/nvim/screen.c
index c68a90d6e3..fde6b1ceeb 100644
--- a/src/nvim/screen.c
+++ b/src/nvim/screen.c
@@ -6211,7 +6211,7 @@ void win_grid_alloc(win_T *wp)
|| grid->Rows != rows
|| grid->Columns != cols) {
if (want_allocation) {
- grid_alloc(grid, rows, cols, wp->w_grid.valid, wp->w_grid.valid);
+ grid_alloc(grid, rows, cols, wp->w_grid.valid, false);
grid->valid = true;
} else {
// Single grid mode, all rendering will be redirected to default_grid.
diff --git a/src/nvim/testdir/test_perl.vim b/src/nvim/testdir/test_perl.vim
new file mode 100644
index 0000000000..2343f389fa
--- /dev/null
+++ b/src/nvim/testdir/test_perl.vim
@@ -0,0 +1,225 @@
+" Tests for Perl interface
+
+if !has('perl') || has('win32')
+ finish
+endif
+
+perl $SIG{__WARN__} = sub { die "Unexpected warnings from perl: @_" };
+
+func Test_change_buffer()
+ call setline(line('$'), ['1 line 1'])
+ perl VIM::DoCommand("normal /^1\n")
+ perl $curline = VIM::Eval("line('.')")
+ perl $curbuf->Set($curline, "1 changed line 1")
+ call assert_equal('1 changed line 1', getline('$'))
+endfunc
+
+func Test_evaluate_list()
+ call setline(line('$'), ['2 line 2'])
+ perl VIM::DoCommand("normal /^2\n")
+ perl $curline = VIM::Eval("line('.')")
+ let l = ["abc", "def"]
+ perl << EOF
+ $l = VIM::Eval("l");
+ $curbuf->Append($curline, $l);
+EOF
+endfunc
+
+funct Test_VIM_Blob()
+ call assert_equal('0z', perleval('VIM::Blob("")'))
+ "call assert_equal('0z31326162', 'VIM::Blob("12ab")'->perleval())
+ call assert_equal('0z00010203', perleval('VIM::Blob("\x00\x01\x02\x03")'))
+ call assert_equal('0z8081FEFF', perleval('VIM::Blob("\x80\x81\xfe\xff")'))
+endfunc
+
+func Test_buffer_Delete()
+ new
+ call setline(1, ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'])
+ perl $curbuf->Delete(7)
+ perl $curbuf->Delete(2, 5)
+ perl $curbuf->Delete(10)
+ call assert_equal(['a', 'f', 'h'], getline(1, '$'))
+ bwipe!
+endfunc
+
+func Test_buffer_Append()
+ new
+ perl $curbuf->Append(1, '1')
+ perl $curbuf->Append(2, '2', '3', '4')
+ call assert_equal(['', '1', '2', '3', '4'], getline(1, '$'))
+ perl @l = ('5' ..'7')
+ perl $curbuf->Append(0, @l)
+ call assert_equal(['5', '6', '7', '', '1', '2', '3', '4'], getline(1, '$'))
+ bwipe!
+endfunc
+
+func Test_buffer_Set()
+ new
+ call setline(1, ['1', '2', '3', '4', '5'])
+ perl $curbuf->Set(2, 'a', 'b', 'c')
+ perl $curbuf->Set(4, 'A', 'B', 'C')
+ call assert_equal(['1', 'a', 'b', 'A', 'B'], getline(1, '$'))
+ bwipe!
+endfunc
+
+func Test_buffer_Get()
+ new
+ call setline(1, ['1', '2', '3', '4'])
+ call assert_equal('2:3', perleval('join(":", $curbuf->Get(2, 3))'))
+ bwipe!
+endfunc
+
+func Test_buffer_Count()
+ new
+ call setline(1, ['a', 'b', 'c'])
+ call assert_equal(3, perleval('$curbuf->Count()'))
+ bwipe!
+endfunc
+
+func Test_buffer_Name()
+ new
+ call assert_equal('', perleval('$curbuf->Name()'))
+ bwipe!
+ new Xfoo
+ call assert_equal('Xfoo', perleval('$curbuf->Name()'))
+ bwipe!
+endfunc
+
+func Test_buffer_Number()
+ call assert_equal(bufnr('%'), perleval('$curbuf->Number()'))
+endfunc
+
+func Test_window_Cursor()
+ new
+ call setline(1, ['line1', 'line2'])
+ perl $curwin->Cursor(2, 3)
+ call assert_equal('2:3', perleval('join(":", $curwin->Cursor())'))
+ " Col is numbered from 0 in Perl, and from 1 in Vim script.
+ call assert_equal([0, 2, 4, 0], getpos('.'))
+ bwipe!
+endfunc
+
+func Test_window_SetHeight()
+ new
+ perl $curwin->SetHeight(2)
+ call assert_equal(2, winheight(0))
+ bwipe!
+endfunc
+
+func Test_VIM_Windows()
+ new
+ " VIM::Windows() without argument in scalar and list context.
+ perl $winnr = VIM::Windows()
+ perl @winlist = VIM::Windows()
+ perl $curbuf->Append(0, $winnr, scalar(@winlist))
+ call assert_equal(['2', '2', ''], getline(1, '$'))
+
+ "" VIM::Windows() with window number argument.
+ perl (VIM::Windows(VIM::Eval('winnr()')))[0]->Buffer()->Set(1, 'bar')
+ call assert_equal('bar', getline(1))
+ bwipe!
+endfunc
+
+func Test_VIM_Buffers()
+ new Xbar
+ " VIM::Buffers() without argument in scalar and list context.
+ perl $nbuf = VIM::Buffers()
+ perl @buflist = VIM::Buffers()
+
+ " VIM::Buffers() with argument.
+ perl $curbuf = (VIM::Buffers('Xbar'))[0]
+ perl $curbuf->Append(0, $nbuf, scalar(@buflist))
+ call assert_equal(['2', '2', ''], getline(1, '$'))
+ bwipe!
+endfunc
+
+func Test_perleval()
+ call assert_false(perleval('undef'))
+
+ "" scalar
+ call assert_equal(0, perleval('0'))
+ call assert_equal(2, perleval('2'))
+ call assert_equal(-2, perleval('-2'))
+ if has('float')
+ call assert_equal(2.5, perleval('2.5'))
+ else
+ call assert_equal(2, perleval('2.5'))
+ end
+
+ call assert_equal('abc', perleval('"abc"'))
+
+ "" ref
+ call assert_equal([], perleval('[]'))
+ call assert_equal(['word', 42, [42],{}], perleval('["word", 42, [42], {}]'))
+
+ call assert_equal({}, perleval('{}'))
+ call assert_equal({'foo': 'bar'}, perleval('{foo => "bar"}'))
+
+ perl our %h; our @a;
+ let a = perleval('[\%h, \%h, \@a, \@a]')
+ echo a
+ call assert_equal(a[0], a[1])
+ call assert_equal(a[2], a[3])
+ perl undef %h; undef @a;
+
+ call assert_equal('*VIM', perleval('"*VIM"'))
+endfunc
+
+func Test_perldo()
+ sp __TEST__
+ exe 'read ' g:testname
+ perldo s/perl/vieux_chameau/g
+ 1
+ call assert_false(search('\Cperl'))
+ bw!
+
+ " Check deleting lines does not trigger ml_get error.
+ new
+ call setline(1, ['one', 'two', 'three'])
+ perldo VIM::DoCommand("%d_")
+ bwipe!
+
+ "" Check switching to another buffer does not trigger ml_get error.
+ new
+ let wincount = winnr('$')
+ call setline(1, ['one', 'two', 'three'])
+ perldo VIM::DoCommand("new")
+ call assert_equal(wincount + 1, winnr('$'))
+ bwipe!
+ bwipe!
+endfunc
+
+func Test_VIM_package()
+ perl VIM::DoCommand('let l:var = "foo"')
+ call assert_equal(l:var, 'foo')
+
+ set noet
+ perl VIM::SetOption('et')
+ call assert_true(&et)
+endfunc
+
+func Test_set_cursor()
+ " Check that setting the cursor position works.
+ new
+ call setline(1, ['first line', 'second line'])
+ normal gg
+ perldo $curwin->Cursor(1, 5)
+ call assert_equal([1, 6], [line('.'), col('.')])
+
+ " Check that movement after setting cursor position keeps current column.
+ normal j
+ call assert_equal([2, 6], [line('.'), col('.')])
+endfunc
+
+" Test for various heredoc syntax
+func Test_perl_heredoc()
+ perl << END
+VIM::DoCommand('let s = "A"')
+END
+ perl <<
+VIM::DoCommand('let s ..= "B"')
+.
+ call assert_equal('AB', s)
+endfunc
+
+" vim: shiftwidth=2 sts=2 expandtab
diff --git a/src/nvim/testdir/test_window_cmd.vim b/src/nvim/testdir/test_window_cmd.vim
index aaa291f87d..9f47ee2904 100644
--- a/src/nvim/testdir/test_window_cmd.vim
+++ b/src/nvim/testdir/test_window_cmd.vim
@@ -841,4 +841,46 @@ func Test_winnr()
only | tabonly
endfunc
+func Test_window_resize()
+ " Vertical :resize (absolute, relative, min and max size).
+ vsplit
+ vert resize 8
+ call assert_equal(8, winwidth(0))
+ vert resize +2
+ call assert_equal(10, winwidth(0))
+ vert resize -2
+ call assert_equal(8, winwidth(0))
+ vert resize
+ call assert_equal(&columns - 2, winwidth(0))
+ vert resize 0
+ call assert_equal(1, winwidth(0))
+ vert resize 99999
+ call assert_equal(&columns - 2, winwidth(0))
+
+ %bwipe!
+
+ " Horizontal :resize (with absolute, relative size, min and max size).
+ split
+ resize 8
+ call assert_equal(8, winheight(0))
+ resize +2
+ call assert_equal(10, winheight(0))
+ resize -2
+ call assert_equal(8, winheight(0))
+ resize
+ call assert_equal(&lines - 4, winheight(0))
+ resize 0
+ call assert_equal(1, winheight(0))
+ resize 99999
+ call assert_equal(&lines - 4, winheight(0))
+
+ " :resize with explicit window number.
+ let other_winnr = winnr('j')
+ exe other_winnr .. 'resize 10'
+ call assert_equal(10, winheight(other_winnr))
+ call assert_equal(&lines - 10 - 3, winheight(0))
+
+ %bwipe!
+endfunc
+
" vim: shiftwidth=2 sts=2 expandtab
diff --git a/src/nvim/tui/tui.c b/src/nvim/tui/tui.c
index 3b71066094..dde17726fd 100644
--- a/src/nvim/tui/tui.c
+++ b/src/nvim/tui/tui.c
@@ -108,6 +108,7 @@ typedef struct {
bool cork, overflow;
bool cursor_color_changed;
bool is_starting;
+ FILE *screenshot;
cursorentry_T cursor_shapes[SHAPE_IDX_COUNT];
HlAttrs clear_attrs;
kvec_t(HlAttrs) attrs;
@@ -167,6 +168,7 @@ UI *tui_start(void)
ui->suspend = tui_suspend;
ui->set_title = tui_set_title;
ui->set_icon = tui_set_icon;
+ ui->screenshot = tui_screenshot;
ui->option_set= tui_option_set;
ui->raw_line = tui_raw_line;
@@ -412,6 +414,7 @@ static void tui_main(UIBridgeData *bridge, UI *ui)
data->bridge = bridge;
data->loop = &tui_loop;
data->is_starting = true;
+ data->screenshot = NULL;
kv_init(data->invalid_regions);
signal_watcher_init(data->loop, &data->winch_handle, ui);
signal_watcher_init(data->loop, &data->cont_handle, data);
@@ -1317,6 +1320,31 @@ static void tui_set_icon(UI *ui, String icon)
{
}
+static void tui_screenshot(UI *ui, String path)
+{
+ TUIData *data = ui->data;
+ UGrid *grid = &data->grid;
+ flush_buf(ui);
+ grid->row = 0;
+ grid->col = 0;
+
+ FILE *f = fopen(path.data, "w");
+ data->screenshot = f;
+ fprintf(f, "%d,%d\n", grid->height, grid->width);
+ unibi_out(ui, unibi_clear_screen);
+ for (int i = 0; i < grid->height; i++) {
+ cursor_goto(ui, i, 0);
+ for (int j = 0; j < grid->width; j++) {
+ print_cell(ui, &grid->cells[i][j]);
+ }
+ }
+ flush_buf(ui);
+ data->screenshot = NULL;
+
+ fclose(f);
+}
+
+
static void tui_option_set(UI *ui, String name, Object value)
{
TUIData *data = ui->data;
@@ -2054,9 +2082,15 @@ static void flush_buf(UI *ui)
}
}
- uv_write(&req, STRUCT_CAST(uv_stream_t, &data->output_handle),
- bufs, (unsigned)(bufp - bufs), NULL);
- uv_run(&data->write_loop, UV_RUN_DEFAULT);
+ if (data->screenshot) {
+ for (size_t i = 0; i < (size_t)(bufp - bufs); i++) {
+ fwrite(bufs[i].base, bufs[i].len, 1, data->screenshot);
+ }
+ } else {
+ uv_write(&req, STRUCT_CAST(uv_stream_t, &data->output_handle),
+ bufs, (unsigned)(bufp - bufs), NULL);
+ uv_run(&data->write_loop, UV_RUN_DEFAULT);
+ }
data->bufpos = 0;
data->overflow = false;
}
diff --git a/src/nvim/ui_bridge.c b/src/nvim/ui_bridge.c
index 9a1988739c..25f45b8fe6 100644
--- a/src/nvim/ui_bridge.c
+++ b/src/nvim/ui_bridge.c
@@ -61,6 +61,7 @@ UI *ui_bridge_attach(UI *ui, ui_main_fn ui_main, event_scheduler scheduler)
rv->bridge.suspend = ui_bridge_suspend;
rv->bridge.set_title = ui_bridge_set_title;
rv->bridge.set_icon = ui_bridge_set_icon;
+ rv->bridge.screenshot = ui_bridge_screenshot;
rv->bridge.option_set = ui_bridge_option_set;
rv->bridge.raw_line = ui_bridge_raw_line;
rv->bridge.inspect = ui_bridge_inspect;
diff --git a/src/nvim/version.c b/src/nvim/version.c
index bf80de6026..d6d933245b 100644
--- a/src/nvim/version.c
+++ b/src/nvim/version.c
@@ -464,7 +464,7 @@ static const int included_patches[] = {
1457,
1456,
// 1455,
- // 1454,
+ 1454,
1453,
1452,
1451,
diff --git a/src/nvim/viml/parser/expressions.c b/src/nvim/viml/parser/expressions.c
index b77b80a5f3..44b6ab5f5a 100644
--- a/src/nvim/viml/parser/expressions.c
+++ b/src/nvim/viml/parser/expressions.c
@@ -1431,7 +1431,7 @@ static inline void east_set_error(const ParserState *const pstate,
const ParserLine pline = pstate->reader.lines.items[start.line];
ret_ast_err->msg = msg;
ret_ast_err->arg_len = (int)(pline.size - start.col);
- ret_ast_err->arg = pline.data + start.col;
+ ret_ast_err->arg = pline.data ? pline.data + start.col : NULL;
}
/// Set error from the given token and given message
diff --git a/src/tree_sitter/alloc.h b/src/tree_sitter/alloc.h
index d3c6b5eca8..32c90f23c8 100644
--- a/src/tree_sitter/alloc.h
+++ b/src/tree_sitter/alloc.h
@@ -58,7 +58,7 @@ static inline bool ts_toggle_allocation_recording(bool value) {
static inline void *ts_malloc(size_t size) {
void *result = malloc(size);
if (size > 0 && !result) {
- fprintf(stderr, "tree-sitter failed to allocate %lu bytes", size);
+ fprintf(stderr, "tree-sitter failed to allocate %zu bytes", size);
exit(1);
}
return result;
@@ -67,7 +67,7 @@ static inline void *ts_malloc(size_t size) {
static inline void *ts_calloc(size_t count, size_t size) {
void *result = calloc(count, size);
if (count > 0 && !result) {
- fprintf(stderr, "tree-sitter failed to allocate %lu bytes", count * size);
+ fprintf(stderr, "tree-sitter failed to allocate %zu bytes", count * size);
exit(1);
}
return result;
@@ -76,7 +76,7 @@ static inline void *ts_calloc(size_t count, size_t size) {
static inline void *ts_realloc(void *buffer, size_t size) {
void *result = realloc(buffer, size);
if (size > 0 && !result) {
- fprintf(stderr, "tree-sitter failed to reallocate %lu bytes", size);
+ fprintf(stderr, "tree-sitter failed to reallocate %zu bytes", size);
exit(1);
}
return result;
diff --git a/src/tree_sitter/lexer.c b/src/tree_sitter/lexer.c
index 3f8a4c0ae8..a3c29544d3 100644
--- a/src/tree_sitter/lexer.c
+++ b/src/tree_sitter/lexer.c
@@ -73,7 +73,6 @@ static void ts_lexer__get_chunk(Lexer *self) {
// code that spans the current position.
static void ts_lexer__get_lookahead(Lexer *self) {
uint32_t position_in_chunk = self->current_position.bytes - self->chunk_start;
- const uint8_t *chunk = (const uint8_t *)self->chunk + position_in_chunk;
uint32_t size = self->chunk_size - position_in_chunk;
if (size == 0) {
@@ -82,6 +81,7 @@ static void ts_lexer__get_lookahead(Lexer *self) {
return;
}
+ const uint8_t *chunk = (const uint8_t *)self->chunk + position_in_chunk;
UnicodeDecodeFunction decode = self->input.encoding == TSInputEncodingUTF8
? ts_decode_utf8
: ts_decode_utf16;
diff --git a/src/tree_sitter/parser.c b/src/tree_sitter/parser.c
index dd222cd3c4..79cad797a0 100644
--- a/src/tree_sitter/parser.c
+++ b/src/tree_sitter/parser.c
@@ -292,6 +292,7 @@ static bool ts_parser__better_version_exists(
return true;
case ErrorComparisonPreferRight:
if (ts_stack_can_merge(self->stack, i, version)) return true;
+ break;
default:
break;
}
@@ -355,10 +356,14 @@ static Subtree ts_parser__lex(
StackVersion version,
TSStateId parse_state
) {
+ TSLexMode lex_mode = self->language->lex_modes[parse_state];
+ if (lex_mode.lex_state == (uint16_t)-1) {
+ LOG("no_lookahead_after_non_terminal_extra");
+ return NULL_SUBTREE;
+ }
+
Length start_position = ts_stack_position(self->stack, version);
Subtree external_token = ts_stack_last_external_token(self->stack, version);
- TSLexMode lex_mode = self->language->lex_modes[parse_state];
- if (lex_mode.lex_state == (uint16_t)-1) return NULL_SUBTREE;
const bool *valid_external_tokens = ts_language_enabled_external_tokens(
self->language,
lex_mode.external_lex_state
@@ -761,20 +766,26 @@ static StackVersion ts_parser__reduce(
int dynamic_precedence,
uint16_t production_id,
bool is_fragile,
- bool is_extra
+ bool end_of_non_terminal_extra
) {
uint32_t initial_version_count = ts_stack_version_count(self->stack);
- uint32_t removed_version_count = 0;
- StackSliceArray pop = ts_stack_pop_count(self->stack, version, count);
+ // Pop the given number of nodes from the given version of the parse stack.
+ // If stack versions have previously merged, then there may be more than one
+ // path back through the stack. For each path, create a new parent node to
+ // contain the popped children, and push it onto the stack in place of the
+ // children.
+ StackSliceArray pop = ts_stack_pop_count(self->stack, version, count);
+ uint32_t removed_version_count = 0;
for (uint32_t i = 0; i < pop.size; i++) {
StackSlice slice = pop.contents[i];
StackVersion slice_version = slice.version - removed_version_count;
- // Error recovery can sometimes cause lots of stack versions to merge,
- // such that a single pop operation can produce a lots of slices.
- // Avoid creating too many stack versions in that situation.
- if (i > 0 && slice_version > MAX_VERSION_COUNT + MAX_VERSION_COUNT_OVERFLOW) {
+ // This is where new versions are added to the parse stack. The versions
+ // will all be sorted and truncated at the end of the outer parsing loop.
+ // Allow the maximum version count to be temporarily exceeded, but only
+ // by a limited threshold.
+ if (slice_version > MAX_VERSION_COUNT + MAX_VERSION_COUNT_OVERFLOW) {
ts_stack_remove_version(self->stack, slice_version);
ts_subtree_array_delete(&self->tree_pool, &slice.subtrees);
removed_version_count++;
@@ -826,7 +837,9 @@ static StackVersion ts_parser__reduce(
TSStateId state = ts_stack_state(self->stack, slice_version);
TSStateId next_state = ts_language_next_state(self->language, state, symbol);
- if (is_extra) parent.ptr->extra = true;
+ if (end_of_non_terminal_extra && next_state == state) {
+ parent.ptr->extra = true;
+ }
if (is_fragile || pop.size > 1 || initial_version_count > 1) {
parent.ptr->fragile_left = true;
parent.ptr->fragile_right = true;
@@ -963,6 +976,7 @@ static bool ts_parser__do_all_potential_reductions(
.dynamic_precedence = action.params.reduce.dynamic_precedence,
.production_id = action.params.reduce.production_id,
});
+ break;
default:
break;
}
@@ -1339,23 +1353,26 @@ static bool ts_parser__advance(
);
}
- // Otherwise, re-run the lexer.
- if (!lookahead.ptr) {
- lookahead = ts_parser__lex(self, version, state);
- if (lookahead.ptr) {
- ts_parser__set_cached_token(self, position, last_external_token, lookahead);
- ts_language_table_entry(self->language, state, ts_subtree_symbol(lookahead), &table_entry);
- }
+ bool needs_lex = !lookahead.ptr;
+ for (;;) {
+ // Otherwise, re-run the lexer.
+ if (needs_lex) {
+ needs_lex = false;
+ lookahead = ts_parser__lex(self, version, state);
+
+ if (lookahead.ptr) {
+ ts_parser__set_cached_token(self, position, last_external_token, lookahead);
+ ts_language_table_entry(self->language, state, ts_subtree_symbol(lookahead), &table_entry);
+ }
- // When parsing a non-terminal extra, a null lookahead indicates the
- // end of the rule. The reduction is stored in the EOF table entry.
- // After the reduction, the lexer needs to be run again.
- else {
- ts_language_table_entry(self->language, state, ts_builtin_sym_end, &table_entry);
+ // When parsing a non-terminal extra, a null lookahead indicates the
+ // end of the rule. The reduction is stored in the EOF table entry.
+ // After the reduction, the lexer needs to be run again.
+ else {
+ ts_language_table_entry(self->language, state, ts_builtin_sym_end, &table_entry);
+ }
}
- }
- for (;;) {
// If a cancellation flag or a timeout was provided, then check every
// time a fixed number of parse actions has been processed.
if (++self->operation_count == OP_COUNT_PER_TIMEOUT_CHECK) {
@@ -1407,12 +1424,12 @@ static bool ts_parser__advance(
case TSParseActionTypeReduce: {
bool is_fragile = table_entry.action_count > 1;
- bool is_extra = lookahead.ptr == NULL;
+ bool end_of_non_terminal_extra = lookahead.ptr == NULL;
LOG("reduce sym:%s, child_count:%u", SYM_NAME(action.params.reduce.symbol), action.params.reduce.child_count);
StackVersion reduction_version = ts_parser__reduce(
self, version, action.params.reduce.symbol, action.params.reduce.child_count,
action.params.reduce.dynamic_precedence, action.params.reduce.production_id,
- is_fragile, is_extra
+ is_fragile, end_of_non_terminal_extra
);
if (reduction_version != STACK_VERSION_NONE) {
last_reduction_version = reduction_version;
@@ -1452,8 +1469,10 @@ static bool ts_parser__advance(
// (and completing the non-terminal extra rule) run the lexer again based
// on the current parse state.
if (!lookahead.ptr) {
- lookahead = ts_parser__lex(self, version, state);
+ needs_lex = true;
+ continue;
}
+
ts_language_table_entry(
self->language,
state,
@@ -1463,6 +1482,11 @@ static bool ts_parser__advance(
continue;
}
+ if (!lookahead.ptr) {
+ ts_stack_pause(self->stack, version, ts_builtin_sym_end);
+ return true;
+ }
+
// If there were no parse actions for the current lookahead token, then
// it is not valid in this state. If the current lookahead token is a
// keyword, then switch to treating it as the normal word token if that
@@ -1500,6 +1524,9 @@ static bool ts_parser__advance(
// push each of its children. Then try again to process the current
// lookahead.
if (ts_parser__breakdown_top_of_stack(self, version)) {
+ state = ts_stack_state(self->stack, version);
+ ts_subtree_release(&self->tree_pool, lookahead);
+ needs_lex = true;
continue;
}
diff --git a/src/tree_sitter/query.c b/src/tree_sitter/query.c
index 59902dee3b..b887b74ff6 100644
--- a/src/tree_sitter/query.c
+++ b/src/tree_sitter/query.c
@@ -11,7 +11,6 @@
// #define LOG(...) fprintf(stderr, __VA_ARGS__)
#define LOG(...)
-#define MAX_STATE_COUNT 256
#define MAX_CAPTURE_LIST_COUNT 32
#define MAX_STEP_CAPTURE_COUNT 3
@@ -49,7 +48,6 @@ typedef struct {
uint16_t alternative_index;
uint16_t depth;
bool contains_captures: 1;
- bool is_pattern_start: 1;
bool is_immediate: 1;
bool is_last_child: 1;
bool is_pass_through: 1;
@@ -119,9 +117,10 @@ typedef struct {
uint16_t step_index;
uint16_t pattern_index;
uint16_t capture_list_id;
- uint16_t consumed_capture_count: 14;
+ uint16_t consumed_capture_count: 12;
bool seeking_immediate_match: 1;
bool has_in_progress_alternatives: 1;
+ bool dead: 1;
} QueryState;
typedef Array(TSQueryCapture) CaptureList;
@@ -172,6 +171,7 @@ struct TSQueryCursor {
TSPoint start_point;
TSPoint end_point;
bool ascending;
+ bool halted;
};
static const TSQueryError PARENT_DONE = -1;
@@ -448,7 +448,6 @@ static QueryStep query_step__new(
.alternative_index = NONE,
.contains_captures = false,
.is_last_child = false,
- .is_pattern_start = false,
.is_pass_through = false,
.is_dead_end = false,
.is_immediate = is_immediate,
@@ -546,6 +545,23 @@ static inline void ts_query__pattern_map_insert(
) {
uint32_t index;
ts_query__pattern_map_search(self, symbol, &index);
+
+ // Ensure that the entries are sorted not only by symbol, but also
+ // by pattern_index. This way, states for earlier patterns will be
+ // initiated first, which allows the ordering of the states array
+ // to be maintained more efficiently.
+ while (index < self->pattern_map.size) {
+ PatternEntry *entry = &self->pattern_map.contents[index];
+ if (
+ self->steps.contents[entry->step_index].symbol == symbol &&
+ entry->pattern_index < pattern_index
+ ) {
+ index++;
+ } else {
+ break;
+ }
+ }
+
array_insert(&self->pattern_map, index, ((PatternEntry) {
.step_index = start_step_index,
.pattern_index = pattern_index,
@@ -715,7 +731,7 @@ static TSQueryError ts_query__parse_pattern(
uint32_t *capture_count,
bool is_immediate
) {
- uint32_t starting_step_index = self->steps.size;
+ const uint32_t starting_step_index = self->steps.size;
if (stream->next == 0) return TSQueryErrorSyntax;
@@ -804,8 +820,8 @@ static TSQueryError ts_query__parse_pattern(
}
}
- // A pound character indicates the start of a predicate.
- else if (stream->next == '#') {
+ // A dot/pound character indicates the start of a predicate.
+ else if (stream->next == '.' || stream->next == '#') {
stream_advance(stream);
return ts_query__parse_predicate(self, stream);
}
@@ -951,7 +967,6 @@ static TSQueryError ts_query__parse_pattern(
stream_skip_whitespace(stream);
// Parse the pattern
- uint32_t step_index = self->steps.size;
TSQueryError e = ts_query__parse_pattern(
self,
stream,
@@ -972,7 +987,22 @@ static TSQueryError ts_query__parse_pattern(
stream->input = field_name;
return TSQueryErrorField;
}
- self->steps.contents[step_index].field = field_id;
+
+ uint32_t step_index = starting_step_index;
+ QueryStep *step = &self->steps.contents[step_index];
+ for (;;) {
+ step->field = field_id;
+ if (
+ step->alternative_index != NONE &&
+ step->alternative_index > step_index &&
+ step->alternative_index < self->steps.size
+ ) {
+ step_index = step->alternative_index;
+ step = &self->steps.contents[step_index];
+ } else {
+ break;
+ }
+ }
}
else {
@@ -1041,15 +1071,16 @@ static TSQueryError ts_query__parse_pattern(
length
);
+ uint32_t step_index = starting_step_index;
for (;;) {
query_step__add_capture(step, capture_id);
if (
step->alternative_index != NONE &&
- step->alternative_index > starting_step_index &&
+ step->alternative_index > step_index &&
step->alternative_index < self->steps.size
) {
- starting_step_index = step->alternative_index;
- step = &self->steps.contents[starting_step_index];
+ step_index = step->alternative_index;
+ step = &self->steps.contents[step_index];
} else {
break;
}
@@ -1152,7 +1183,6 @@ TSQuery *ts_query_new(
// Maintain a map that can look up patterns for a given root symbol.
for (;;) {
QueryStep *step = &self->steps.contents[start_step_index];
- step->is_pattern_start = true;
ts_query__pattern_map_insert(self, step->symbol, start_step_index, pattern_index);
if (step->symbol == WILDCARD_SYMBOL) {
self->wildcard_root_pattern_count++;
@@ -1162,6 +1192,7 @@ TSQuery *ts_query_new(
// then add multiple entries to the pattern map.
if (step->alternative_index != NONE) {
start_step_index = step->alternative_index;
+ step->alternative_index = NONE;
} else {
break;
}
@@ -1221,6 +1252,9 @@ const TSQueryPredicateStep *ts_query_predicates_for_pattern(
) {
Slice slice = self->predicates_by_pattern.contents[pattern_index];
*step_count = slice.length;
+ if (self->predicate_steps.contents == NULL) {
+ return NULL;
+ }
return &self->predicate_steps.contents[slice.offset];
}
@@ -1271,6 +1305,7 @@ TSQueryCursor *ts_query_cursor_new(void) {
TSQueryCursor *self = ts_malloc(sizeof(TSQueryCursor));
*self = (TSQueryCursor) {
.ascending = false,
+ .halted = false,
.states = array_new(),
.finished_states = array_new(),
.capture_list_pool = capture_list_pool_new(),
@@ -1279,8 +1314,8 @@ TSQueryCursor *ts_query_cursor_new(void) {
.start_point = {0, 0},
.end_point = POINT_MAX,
};
- array_reserve(&self->states, MAX_STATE_COUNT);
- array_reserve(&self->finished_states, MAX_CAPTURE_LIST_COUNT);
+ array_reserve(&self->states, 8);
+ array_reserve(&self->finished_states, 8);
return self;
}
@@ -1304,6 +1339,7 @@ void ts_query_cursor_exec(
self->next_state_id = 0;
self->depth = 0;
self->ascending = false;
+ self->halted = false;
self->query = query;
}
@@ -1347,6 +1383,7 @@ static bool ts_query_cursor__first_in_progress_capture(
*pattern_index = UINT32_MAX;
for (unsigned i = 0; i < self->states.size; i++) {
const QueryState *state = &self->states.contents[i];
+ if (state->dead) continue;
const CaptureList *captures = capture_list_pool_get(
&self->capture_list_pool,
state->capture_list_id
@@ -1441,65 +1478,138 @@ void ts_query_cursor__compare_captures(
}
}
-static bool ts_query_cursor__add_state(
+static void ts_query_cursor__add_state(
TSQueryCursor *self,
const PatternEntry *pattern
) {
- if (self->states.size >= MAX_STATE_COUNT) {
- LOG(" too many states");
- return false;
+ QueryStep *step = &self->query->steps.contents[pattern->step_index];
+ uint32_t start_depth = self->depth - step->depth;
+
+ // Keep the states array in ascending order of start_depth and pattern_index,
+ // so that it can be processed more efficiently elsewhere. Usually, there is
+ // no work to do here because of two facts:
+ // * States with lower start_depth are naturally added first due to the
+ // order in which nodes are visited.
+ // * Earlier patterns are naturally added first because of the ordering of the
+ // pattern_map data structure that's used to initiate matches.
+ //
+ // This loop is only needed in cases where two conditions hold:
+ // * A pattern consists of more than one sibling node, so that its states
+ // remain in progress after exiting the node that started the match.
+ // * The first node in the pattern matches against multiple nodes at the
+ // same depth.
+ //
+ // An example of this is the pattern '((comment)* (function))'. If multiple
+ // `comment` nodes appear in a row, then we may initiate a new state for this
+ // pattern while another state for the same pattern is already in progress.
+ // If there are multiple patterns like this in a query, then this loop will
+ // need to execute in order to keep the states ordered by pattern_index.
+ uint32_t index = self->states.size;
+ while (index > 0) {
+ QueryState *prev_state = &self->states.contents[index - 1];
+ if (prev_state->start_depth < start_depth) break;
+ if (prev_state->start_depth == start_depth) {
+ if (prev_state->pattern_index < pattern->pattern_index) break;
+ if (prev_state->pattern_index == pattern->pattern_index) {
+ // Avoid unnecessarily inserting an unnecessary duplicate state,
+ // which would be immediately pruned by the longest-match criteria.
+ if (prev_state->step_index == pattern->step_index) return;
+ }
+ }
+ index--;
}
+
LOG(
" start state. pattern:%u, step:%u\n",
pattern->pattern_index,
pattern->step_index
);
- QueryStep *step = &self->query->steps.contents[pattern->step_index];
- array_push(&self->states, ((QueryState) {
+ array_insert(&self->states, index, ((QueryState) {
.capture_list_id = NONE,
.step_index = pattern->step_index,
.pattern_index = pattern->pattern_index,
- .start_depth = self->depth - step->depth,
+ .start_depth = start_depth,
.consumed_capture_count = 0,
- .seeking_immediate_match = false,
+ .seeking_immediate_match = true,
+ .has_in_progress_alternatives = false,
+ .dead = false,
}));
- return true;
}
-// Duplicate the given state and insert the newly-created state immediately after
-// the given state in the `states` array.
-static QueryState *ts_query__cursor_copy_state(
+// Acquire a capture list for this state. If there are no capture lists left in the
+// pool, this will steal the capture list from another existing state, and mark that
+// other state as 'dead'.
+static CaptureList *ts_query_cursor__prepare_to_capture(
TSQueryCursor *self,
- const QueryState *state
+ QueryState *state,
+ unsigned state_index_to_preserve
) {
- if (self->states.size >= MAX_STATE_COUNT) {
- LOG(" too many states");
- return NULL;
+ if (state->capture_list_id == NONE) {
+ state->capture_list_id = capture_list_pool_acquire(&self->capture_list_pool);
+
+ // If there are no capture lists left in the pool, then terminate whichever
+ // state has captured the earliest node in the document, and steal its
+ // capture list.
+ if (state->capture_list_id == NONE) {
+ uint32_t state_index, byte_offset, pattern_index;
+ if (
+ ts_query_cursor__first_in_progress_capture(
+ self,
+ &state_index,
+ &byte_offset,
+ &pattern_index
+ ) &&
+ state_index != state_index_to_preserve
+ ) {
+ LOG(
+ " abandon state. index:%u, pattern:%u, offset:%u.\n",
+ state_index, pattern_index, byte_offset
+ );
+ QueryState *other_state = &self->states.contents[state_index];
+ state->capture_list_id = other_state->capture_list_id;
+ other_state->capture_list_id = NONE;
+ other_state->dead = true;
+ CaptureList *list = capture_list_pool_get_mut(
+ &self->capture_list_pool,
+ state->capture_list_id
+ );
+ array_clear(list);
+ return list;
+ } else {
+ LOG(" ran out of capture lists");
+ return NULL;
+ }
+ }
}
+ return capture_list_pool_get_mut(&self->capture_list_pool, state->capture_list_id);
+}
- // If the state has captures, copy its capture list.
+// Duplicate the given state and insert the newly-created state immediately after
+// the given state in the `states` array. Ensures that the given state reference is
+// still valid, even if the states array is reallocated.
+static QueryState *ts_query_cursor__copy_state(
+ TSQueryCursor *self,
+ QueryState **state_ref
+) {
+ const QueryState *state = *state_ref;
+ uint32_t state_index = state - self->states.contents;
QueryState copy = *state;
- copy.capture_list_id = state->capture_list_id;
+ copy.capture_list_id = NONE;
+
+ // If the state has captures, copy its capture list.
if (state->capture_list_id != NONE) {
- copy.capture_list_id = capture_list_pool_acquire(&self->capture_list_pool);
- if (copy.capture_list_id == NONE) {
- LOG(" too many capture lists");
- return NULL;
- }
+ CaptureList *new_captures = ts_query_cursor__prepare_to_capture(self, &copy, state_index);
+ if (!new_captures) return NULL;
const CaptureList *old_captures = capture_list_pool_get(
&self->capture_list_pool,
state->capture_list_id
);
- CaptureList *new_captures = capture_list_pool_get_mut(
- &self->capture_list_pool,
- copy.capture_list_id
- );
array_push_all(new_captures, old_captures);
}
- uint32_t index = (state - self->states.contents) + 1;
- array_insert(&self->states, index, copy);
- return &self->states.contents[index];
+ array_insert(&self->states, state_index + 1, copy);
+ *state_ref = &self->states.contents[state_index];
+ return &self->states.contents[state_index + 1];
}
// Walk the tree, processing patterns until at least one pattern finishes,
@@ -1507,18 +1617,30 @@ static QueryState *ts_query__cursor_copy_state(
// `finished_states` array. Multiple patterns can finish on the same node. If
// there are no more matches, return `false`.
static inline bool ts_query_cursor__advance(TSQueryCursor *self) {
- do {
+ bool did_match = false;
+ for (;;) {
+ if (self->halted) {
+ while (self->states.size > 0) {
+ QueryState state = array_pop(&self->states);
+ capture_list_pool_release(
+ &self->capture_list_pool,
+ state.capture_list_id
+ );
+ }
+ }
+
+ if (did_match || self->halted) return did_match;
+
if (self->ascending) {
LOG("leave node. type:%s\n", ts_node_type(ts_tree_cursor_current_node(&self->cursor)));
// Leave this node by stepping to its next sibling or to its parent.
- bool did_move = true;
if (ts_tree_cursor_goto_next_sibling(&self->cursor)) {
self->ascending = false;
} else if (ts_tree_cursor_goto_parent(&self->cursor)) {
self->depth--;
} else {
- did_move = false;
+ self->halted = true;
}
// After leaving a node, remove any states that cannot make further progress.
@@ -1530,10 +1652,11 @@ static inline bool ts_query_cursor__advance(TSQueryCursor *self) {
// If a state completed its pattern inside of this node, but was deferred from finishing
// in order to search for longer matches, mark it as finished.
if (step->depth == PATTERN_DONE_MARKER) {
- if (state->start_depth > self->depth || !did_move) {
+ if (state->start_depth > self->depth || self->halted) {
LOG(" finish pattern %u\n", state->pattern_index);
state->id = self->next_state_id++;
array_push(&self->finished_states, *state);
+ did_match = true;
deleted_count++;
continue;
}
@@ -1560,10 +1683,6 @@ static inline bool ts_query_cursor__advance(TSQueryCursor *self) {
}
}
self->states.size -= deleted_count;
-
- if (!did_move) {
- return self->finished_states.size > 0;
- }
} else {
// If this node is before the selected range, then avoid descending into it.
TSNode node = ts_tree_cursor_current_node(&self->cursor);
@@ -1581,7 +1700,10 @@ static inline bool ts_query_cursor__advance(TSQueryCursor *self) {
if (
self->end_byte <= ts_node_start_byte(node) ||
point_lte(self->end_point, ts_node_start_point(node))
- ) return false;
+ ) {
+ self->halted = true;
+ continue;
+ }
// Get the properties of the current node.
TSSymbol symbol = ts_node_symbol(node);
@@ -1613,7 +1735,7 @@ static inline bool ts_query_cursor__advance(TSQueryCursor *self) {
// If this node matches the first step of the pattern, then add a new
// state at the start of this pattern.
if (step->field && field_id != step->field) continue;
- if (!ts_query_cursor__add_state(self, pattern)) break;
+ ts_query_cursor__add_state(self, pattern);
}
// Add new states for any patterns whose root node matches this node.
@@ -1625,7 +1747,7 @@ static inline bool ts_query_cursor__advance(TSQueryCursor *self) {
// If this node matches the first step of the pattern, then add a new
// state at the start of this pattern.
if (step->field && field_id != step->field) continue;
- if (!ts_query_cursor__add_state(self, pattern)) break;
+ ts_query_cursor__add_state(self, pattern);
// Advance to the next pattern whose root node matches this node.
i++;
@@ -1693,12 +1815,8 @@ static inline bool ts_query_cursor__advance(TSQueryCursor *self) {
// parent, then this query state cannot simply be updated in place. It must be
// split into two states: one that matches this node, and one which skips over
// this node, to preserve the possibility of matching later siblings.
- if (
- later_sibling_can_match &&
- !step->is_pattern_start &&
- step->contains_captures
- ) {
- if (ts_query__cursor_copy_state(self, state)) {
+ if (later_sibling_can_match && step->contains_captures) {
+ if (ts_query_cursor__copy_state(self, &state)) {
LOG(
" split state for capture. pattern:%u, step:%u\n",
state->pattern_index,
@@ -1709,45 +1827,14 @@ static inline bool ts_query_cursor__advance(TSQueryCursor *self) {
}
// If the current node is captured in this pattern, add it to the capture list.
- // For the first capture in a pattern, lazily acquire a capture list.
if (step->capture_ids[0] != NONE) {
- if (state->capture_list_id == NONE) {
- state->capture_list_id = capture_list_pool_acquire(&self->capture_list_pool);
-
- // If there are no capture lists left in the pool, then terminate whichever
- // state has captured the earliest node in the document, and steal its
- // capture list.
- if (state->capture_list_id == NONE) {
- uint32_t state_index, byte_offset, pattern_index;
- if (ts_query_cursor__first_in_progress_capture(
- self,
- &state_index,
- &byte_offset,
- &pattern_index
- )) {
- LOG(
- " abandon state. index:%u, pattern:%u, offset:%u.\n",
- state_index, pattern_index, byte_offset
- );
- state->capture_list_id = self->states.contents[state_index].capture_list_id;
- array_erase(&self->states, state_index);
- if (state_index < i) {
- i--;
- state--;
- }
- } else {
- LOG(" too many finished states.\n");
- array_erase(&self->states, i);
- i--;
- continue;
- }
- }
+ CaptureList *capture_list = ts_query_cursor__prepare_to_capture(self, state, UINT32_MAX);
+ if (!capture_list) {
+ array_erase(&self->states, i);
+ i--;
+ continue;
}
- CaptureList *capture_list = capture_list_pool_get_mut(
- &self->capture_list_pool,
- state->capture_list_id
- );
for (unsigned j = 0; j < MAX_STEP_CAPTURE_COUNT; j++) {
uint16_t capture_id = step->capture_ids[j];
if (step->capture_ids[j] == NONE) break;
@@ -1770,10 +1857,9 @@ static inline bool ts_query_cursor__advance(TSQueryCursor *self) {
state->step_index
);
- // If this state's next step has an 'alternative' step (the step is either optional,
- // or is the end of a repetition), then copy the state in order to pursue both
- // alternatives. The alternative step itself may have an alternative, so this is
- // an interative process.
+ // If this state's next step has an alternative step, then copy the state in order
+ // to pursue both alternatives. The alternative step itself may have an alternative,
+ // so this is an interative process.
unsigned end_index = i + 1;
for (unsigned j = i; j < end_index; j++) {
QueryState *state = &self->states.contents[j];
@@ -1785,25 +1871,27 @@ static inline bool ts_query_cursor__advance(TSQueryCursor *self) {
continue;
}
- QueryState *copy = ts_query__cursor_copy_state(self, state);
if (next_step->is_pass_through) {
state->step_index++;
j--;
}
+
+ QueryState *copy = ts_query_cursor__copy_state(self, &state);
if (copy) {
- copy_count++;
+ LOG(
+ " split state for branch. pattern:%u, from_step:%u, to_step:%u, immediate:%d, capture_count: %u\n",
+ copy->pattern_index,
+ copy->step_index,
+ next_step->alternative_index,
+ next_step->alternative_is_immediate,
+ capture_list_pool_get(&self->capture_list_pool, copy->capture_list_id)->size
+ );
end_index++;
+ copy_count++;
copy->step_index = next_step->alternative_index;
if (next_step->alternative_is_immediate) {
copy->seeking_immediate_match = true;
}
- LOG(
- " split state for branch. pattern:%u, step:%u, step:%u, immediate:%d\n",
- copy->pattern_index,
- state->step_index,
- copy->step_index,
- copy->seeking_immediate_match
- );
}
}
}
@@ -1811,59 +1899,77 @@ static inline bool ts_query_cursor__advance(TSQueryCursor *self) {
for (unsigned i = 0; i < self->states.size; i++) {
QueryState *state = &self->states.contents[i];
- bool did_remove = false;
+ if (state->dead) {
+ array_erase(&self->states, i);
+ i--;
+ continue;
+ }
// Enfore the longest-match criteria. When a query pattern contains optional or
- // repeated nodes, this is necesssary to avoid multiple redundant states, where
+ // repeated nodes, this is necessary to avoid multiple redundant states, where
// one state has a strict subset of another state's captures.
+ bool did_remove = false;
for (unsigned j = i + 1; j < self->states.size; j++) {
QueryState *other_state = &self->states.contents[j];
+
+ // Query states are kept in ascending order of start_depth and pattern_index.
+ // Since the longest-match criteria is only used for deduping matches of the same
+ // pattern and root node, we only need to perform pairwise comparisons within a
+ // small slice of the states array.
if (
- state->pattern_index == other_state->pattern_index &&
- state->start_depth == other_state->start_depth
- ) {
- bool left_contains_right, right_contains_left;
- ts_query_cursor__compare_captures(
- self,
- state,
- other_state,
- &left_contains_right,
- &right_contains_left
- );
- if (left_contains_right) {
- if (state->step_index == other_state->step_index) {
- LOG(
- " drop shorter state. pattern: %u, step_index: %u\n",
- state->pattern_index,
- state->step_index
- );
- capture_list_pool_release(&self->capture_list_pool, other_state->capture_list_id);
- array_erase(&self->states, j);
- j--;
- continue;
- }
- other_state->has_in_progress_alternatives = true;
+ other_state->start_depth != state->start_depth ||
+ other_state->pattern_index != state->pattern_index
+ ) break;
+
+ bool left_contains_right, right_contains_left;
+ ts_query_cursor__compare_captures(
+ self,
+ state,
+ other_state,
+ &left_contains_right,
+ &right_contains_left
+ );
+ if (left_contains_right) {
+ if (state->step_index == other_state->step_index) {
+ LOG(
+ " drop shorter state. pattern: %u, step_index: %u\n",
+ state->pattern_index,
+ state->step_index
+ );
+ capture_list_pool_release(&self->capture_list_pool, other_state->capture_list_id);
+ array_erase(&self->states, j);
+ j--;
+ continue;
}
- if (right_contains_left) {
- if (state->step_index == other_state->step_index) {
- LOG(
- " drop shorter state. pattern: %u, step_index: %u\n",
- state->pattern_index,
- state->step_index
- );
- capture_list_pool_release(&self->capture_list_pool, state->capture_list_id);
- array_erase(&self->states, i);
- did_remove = true;
- break;
- }
- state->has_in_progress_alternatives = true;
+ other_state->has_in_progress_alternatives = true;
+ }
+ if (right_contains_left) {
+ if (state->step_index == other_state->step_index) {
+ LOG(
+ " drop shorter state. pattern: %u, step_index: %u\n",
+ state->pattern_index,
+ state->step_index
+ );
+ capture_list_pool_release(&self->capture_list_pool, state->capture_list_id);
+ array_erase(&self->states, i);
+ i--;
+ did_remove = true;
+ break;
}
+ state->has_in_progress_alternatives = true;
}
}
// If there the state is at the end of its pattern, remove it from the list
// of in-progress states and add it to the list of finished states.
if (!did_remove) {
+ LOG(
+ " keep state. pattern: %u, start_depth: %u, step_index: %u, capture_count: %u\n",
+ state->pattern_index,
+ state->start_depth,
+ state->step_index,
+ capture_list_pool_get(&self->capture_list_pool, state->capture_list_id)->size
+ );
QueryStep *next_step = &self->query->steps.contents[state->step_index];
if (next_step->depth == PATTERN_DONE_MARKER) {
if (state->has_in_progress_alternatives) {
@@ -1873,6 +1979,7 @@ static inline bool ts_query_cursor__advance(TSQueryCursor *self) {
state->id = self->next_state_id++;
array_push(&self->finished_states, *state);
array_erase(&self->states, state - self->states.contents);
+ did_match = true;
i--;
}
}
@@ -1886,9 +1993,7 @@ static inline bool ts_query_cursor__advance(TSQueryCursor *self) {
self->ascending = true;
}
}
- } while (self->finished_states.size == 0);
-
- return true;
+ }
}
bool ts_query_cursor_next_match(
@@ -2028,7 +2133,10 @@ bool ts_query_cursor_next_capture(
// If there are no finished matches that are ready to be returned, then
// continue finding more matches.
- if (!ts_query_cursor__advance(self)) return false;
+ if (
+ !ts_query_cursor__advance(self) &&
+ self->finished_states.size == 0
+ ) return false;
}
}
diff --git a/src/tree_sitter/stack.c b/src/tree_sitter/stack.c
index 6ceee2577f..6a8d897c37 100644
--- a/src/tree_sitter/stack.c
+++ b/src/tree_sitter/stack.c
@@ -571,7 +571,12 @@ void ts_stack_record_summary(Stack *self, StackVersion version, unsigned max_dep
};
array_init(session.summary);
stack__iter(self, version, summarize_stack_callback, &session, -1);
- self->heads.contents[version].summary = session.summary;
+ StackHead *head = &self->heads.contents[version];
+ if (head->summary) {
+ array_delete(head->summary);
+ ts_free(head->summary);
+ }
+ head->summary = session.summary;
}
StackSummary *ts_stack_get_summary(Stack *self, StackVersion version) {
@@ -743,6 +748,10 @@ bool ts_stack_print_dot_graph(Stack *self, const TSLanguage *language, FILE *f)
ts_stack_error_cost(self, i)
);
+ if (head->summary) {
+ fprintf(f, "\nsummary_size: %u", head->summary->size);
+ }
+
if (head->last_external_token.ptr) {
const ExternalScannerState *state = &head->last_external_token.ptr->external_scanner_state;
const char *data = ts_external_scanner_state_data(state);
diff --git a/src/tree_sitter/treesitter_commit_hash.txt b/src/tree_sitter/treesitter_commit_hash.txt
index bd7fcfbe76..322cdd24a6 100644
--- a/src/tree_sitter/treesitter_commit_hash.txt
+++ b/src/tree_sitter/treesitter_commit_hash.txt
@@ -1 +1 @@
-81d533d2d1b580fdb507accabc91ceddffb5b6f0
+87df53a99b51bce0d1e901cd6838f24e1c7a4073
diff --git a/test/functional/api/extmark_spec.lua b/test/functional/api/extmark_spec.lua
index 602f879ae8..a2a188d036 100644
--- a/test/functional/api/extmark_spec.lua
+++ b/test/functional/api/extmark_spec.lua
@@ -17,17 +17,6 @@ local function expect(contents)
return eq(contents, helpers.curbuf_contents())
end
-local function check_undo_redo(ns, mark, sr, sc, er, ec) --s = start, e = end
- local rv = curbufmeths.get_extmark_by_id(ns, mark, false)
- eq({er, ec}, rv)
- feed("u")
- rv = curbufmeths.get_extmark_by_id(ns, mark, false)
- eq({sr, sc}, rv)
- feed("<c-r>")
- rv = curbufmeths.get_extmark_by_id(ns, mark, false)
- eq({er, ec}, rv)
-end
-
local function set_extmark(ns_id, id, line, col, opts)
if opts == nil then
opts = {}
@@ -42,7 +31,25 @@ local function get_extmarks(ns_id, start, end_, opts)
if opts == nil then
opts = {}
end
- return curbufmeths.get_extmarks(ns_id, start, end_, opts, false)
+ return curbufmeths.get_extmarks(ns_id, start, end_, opts)
+end
+
+local function get_extmark_by_id(ns_id, id, opts)
+ if opts == nil then
+ opts = {}
+ end
+ return curbufmeths.get_extmark_by_id(ns_id, id, opts)
+end
+
+local function check_undo_redo(ns, mark, sr, sc, er, ec) --s = start, e = end
+ local rv = get_extmark_by_id(ns, mark)
+ eq({er, ec}, rv)
+ feed("u")
+ rv = get_extmark_by_id(ns, mark)
+ eq({sr, sc}, rv)
+ feed("<c-r>")
+ rv = get_extmark_by_id(ns, mark)
+ eq({er, ec}, rv)
end
local function batch_set(ns_id, positions)
@@ -96,7 +103,7 @@ describe('API/extmarks', function()
it('adds, updates and deletes marks', function()
local rv = set_extmark(ns, marks[1], positions[1][1], positions[1][2])
eq(marks[1], rv)
- rv = curbufmeths.get_extmark_by_id(ns, marks[1], false)
+ rv = get_extmark_by_id(ns, marks[1])
eq({positions[1][1], positions[1][2]}, rv)
-- Test adding a second mark on same row works
rv = set_extmark(ns, marks[2], positions[2][1], positions[2][2])
@@ -105,14 +112,14 @@ describe('API/extmarks', function()
-- Test an update, (same pos)
rv = set_extmark(ns, marks[1], positions[1][1], positions[1][2])
eq(marks[1], rv)
- rv = curbufmeths.get_extmark_by_id(ns, marks[2], false)
+ rv = get_extmark_by_id(ns, marks[2])
eq({positions[2][1], positions[2][2]}, rv)
-- Test an update, (new pos)
row = positions[1][1]
col = positions[1][2] + 1
rv = set_extmark(ns, marks[1], row, col)
eq(marks[1], rv)
- rv = curbufmeths.get_extmark_by_id(ns, marks[1], false)
+ rv = get_extmark_by_id(ns, marks[1])
eq({row, col}, rv)
-- remove the test marks
@@ -435,7 +442,7 @@ describe('API/extmarks', function()
~ |
|
]])
- local rv = curbufmeths.get_extmark_by_id(ns, marks[1], false)
+ local rv = get_extmark_by_id(ns, marks[1])
eq({0, 6}, rv)
check_undo_redo(ns, marks[1], 0, 3, 0, 6)
end)
@@ -909,9 +916,9 @@ describe('API/extmarks', function()
-- Set the mark before the cursor, should stay there
set_extmark(ns, marks[2], 0, 10)
feed("i<cr><esc>")
- local rv = curbufmeths.get_extmark_by_id(ns, marks[1], false)
+ local rv = get_extmark_by_id(ns, marks[1])
eq({1, 3}, rv)
- rv = curbufmeths.get_extmark_by_id(ns, marks[2], false)
+ rv = get_extmark_by_id(ns, marks[2])
eq({0, 10}, rv)
check_undo_redo(ns, marks[1], 0, 12, 1, 3)
end)
@@ -924,12 +931,12 @@ describe('API/extmarks', function()
feed("0iint <esc>A {<cr><esc>0i1M1<esc>")
set_extmark(ns, marks[1], 1, 1)
feed("0i<c-f><esc>")
- local rv = curbufmeths.get_extmark_by_id(ns, marks[1], false)
+ local rv = get_extmark_by_id(ns, marks[1])
eq({1, 3}, rv)
check_undo_redo(ns, marks[1], 1, 1, 1, 3)
-- now check when cursor at eol
feed("uA<c-f><esc>")
- rv = curbufmeths.get_extmark_by_id(ns, marks[1], false)
+ rv = get_extmark_by_id(ns, marks[1])
eq({1, 3}, rv)
end)
@@ -940,12 +947,12 @@ describe('API/extmarks', function()
feed("0i<tab><esc>")
set_extmark(ns, marks[1], 0, 3)
feed("bi<c-d><esc>")
- local rv = curbufmeths.get_extmark_by_id(ns, marks[1], false)
+ local rv = get_extmark_by_id(ns, marks[1])
eq({0, 1}, rv)
check_undo_redo(ns, marks[1], 0, 3, 0, 1)
-- check when cursor at eol
feed("uA<c-d><esc>")
- rv = curbufmeths.get_extmark_by_id(ns, marks[1], false)
+ rv = get_extmark_by_id(ns, marks[1])
eq({0, 1}, rv)
end)
@@ -1075,7 +1082,7 @@ describe('API/extmarks', function()
check_undo_redo(ns, marks[5], 2, 0, 3, 0)
feed('u')
feed([[:1,2s:3:\rxx<cr>]])
- eq({1, 3}, curbufmeths.get_extmark_by_id(ns, marks[3], false))
+ eq({1, 3}, get_extmark_by_id(ns, marks[3]))
end)
it('substitions over multiple lines with replace in substition', function()
@@ -1314,16 +1321,16 @@ describe('API/extmarks', function()
eq("Invalid ns_id", pcall_err(set_extmark, ns_invalid, marks[1], positions[1][1], positions[1][2]))
eq("Invalid ns_id", pcall_err(curbufmeths.del_extmark, ns_invalid, marks[1]))
eq("Invalid ns_id", pcall_err(get_extmarks, ns_invalid, positions[1], positions[2]))
- eq("Invalid ns_id", pcall_err(curbufmeths.get_extmark_by_id, ns_invalid, marks[1], false))
+ eq("Invalid ns_id", pcall_err(get_extmark_by_id, ns_invalid, marks[1]))
end)
it('when col = line-length, set the mark on eol', function()
set_extmark(ns, marks[1], 0, -1)
- local rv = curbufmeths.get_extmark_by_id(ns, marks[1], false)
+ local rv = get_extmark_by_id(ns, marks[1])
eq({0, init_text:len()}, rv)
-- Test another
set_extmark(ns, marks[1], 0, -1)
- rv = curbufmeths.get_extmark_by_id(ns, marks[1], false)
+ rv = get_extmark_by_id(ns, marks[1])
eq({0, init_text:len()}, rv)
end)
@@ -1336,7 +1343,7 @@ describe('API/extmarks', function()
local invalid_col = init_text:len() + 1
local invalid_lnum = 3
eq('line value outside range', pcall_err(set_extmark, ns, marks[1], invalid_lnum, invalid_col))
- eq({}, curbufmeths.get_extmark_by_id(ns, marks[1], false))
+ eq({}, get_extmark_by_id(ns, marks[1]))
end)
it('bug from check_col in extmark_set', function()
@@ -1361,7 +1368,7 @@ describe('API/extmarks', function()
local buf = request('nvim_create_buf', 0, 1)
request('nvim_buf_set_lines', buf, 0, -1, 1, {"", ""})
local id = bufmeths.set_extmark(buf, ns, 1, 0, {})
- eq({{id, 1, 0}}, bufmeths.get_extmarks(buf, ns, 0, -1, {}, false))
+ eq({{id, 1, 0}}, bufmeths.get_extmarks(buf, ns, 0, -1, {}))
end)
it('does not crash with append/delete/undo seqence', function()
diff --git a/test/functional/helpers.lua b/test/functional/helpers.lua
index e8435cd3b7..e4fb95442c 100644
--- a/test/functional/helpers.lua
+++ b/test/functional/helpers.lua
@@ -769,14 +769,14 @@ end
function module.missing_provider(provider)
if provider == 'ruby' or provider == 'node' or provider == 'perl' then
- local prog = module.funcs['provider#' .. provider .. '#Detect']()
- return prog == '' and (provider .. ' not detected') or false
+ local e = module.funcs['provider#'..provider..'#Detect']()[2]
+ return e ~= '' and e or false
elseif provider == 'python' or provider == 'python3' then
local py_major_version = (provider == 'python3' and 3 or 2)
- local errors = module.funcs['provider#pythonx#Detect'](py_major_version)[2]
- return errors ~= '' and errors or false
+ local e = module.funcs['provider#pythonx#Detect'](py_major_version)[2]
+ return e ~= '' and e or false
else
- assert(false, 'Unknown provider: ' .. provider)
+ assert(false, 'Unknown provider: '..provider)
end
end
diff --git a/test/functional/lua/treesitter_spec.lua b/test/functional/lua/treesitter_spec.lua
index aa36e6f8f0..5bca42a4fc 100644
--- a/test/functional/lua/treesitter_spec.lua
+++ b/test/functional/lua/treesitter_spec.lua
@@ -250,13 +250,13 @@ void ui_refresh(void)
}, res)
end)
- it('allow loading query with escaped quotes and capture them with `match?` and `vim-match?`', function()
+ it('allow loading query with escaped quotes and capture them with `lua-match?` and `vim-match?`', function()
if not check_parser() then return end
insert('char* astring = "Hello World!";')
local res = exec_lua([[
- cquery = vim.treesitter.parse_query("c", '((_) @quote (vim-match? @quote "^\\"$")) ((_) @quote (match? @quote "^\\"$"))')
+ cquery = vim.treesitter.parse_query("c", '((_) @quote (vim-match? @quote "^\\"$")) ((_) @quote (lua-match? @quote "^\\"$"))')
parser = vim.treesitter.get_parser(0, "c")
tree = parser:parse()
res = {}
@@ -312,6 +312,18 @@ void ui_refresh(void)
]], custom_query)
eq({{0, 4, 0, 8}}, res)
+
+ local res_list = exec_lua[[
+ local query = require'vim.treesitter.query'
+
+ local list = query.list_predicates()
+
+ table.sort(list)
+
+ return list
+ ]]
+
+ eq({ 'contains?', 'eq?', 'is-main?', 'lua-match?', 'match?', 'vim-match?' }, res_list)
end)
it('supports highlighting', function()
@@ -361,7 +373,7 @@ static int nlua_schedule(lua_State *const lstate)
; Use lua regexes
((identifier) @Identifier (#contains? @Identifier "lua_"))
-((identifier) @Constant (#match? @Constant "^[A-Z_]+$"))
+((identifier) @Constant (#lua-match? @Constant "^[A-Z_]+$"))
((identifier) @Normal (#vim-match? @Constant "^lstate$"))
((binary_expression left: (identifier) @WarningMsg.left right: (identifier) @WarningMsg.right) (#eq? @WarningMsg.left @WarningMsg.right))
diff --git a/test/functional/provider/perl_spec.lua b/test/functional/provider/perl_spec.lua
index 7b446e4ab3..125674660b 100644
--- a/test/functional/provider/perl_spec.lua
+++ b/test/functional/provider/perl_spec.lua
@@ -5,6 +5,10 @@ local command = helpers.command
local write_file = helpers.write_file
local eval = helpers.eval
local retry = helpers.retry
+local curbufmeths = helpers.curbufmeths
+local insert = helpers.insert
+local expect = helpers.expect
+local feed = helpers.feed
do
clear()
@@ -19,7 +23,51 @@ before_each(function()
clear()
end)
-describe('perl host', function()
+describe('legacy perl provider', function()
+ if helpers.pending_win32(pending) then return end
+
+ it('feature test', function()
+ eq(1, eval('has("perl")'))
+ end)
+
+ it(':perl command', function()
+ command('perl $vim->vars->{set_by_perl} = [100, 0];')
+ eq({100, 0}, eval('g:set_by_perl'))
+ end)
+
+ it(':perlfile command', function()
+ local fname = 'perlfile.pl'
+ write_file(fname, '$vim->command("let set_by_perlfile = 123")')
+ command('perlfile perlfile.pl')
+ eq(123, eval('g:set_by_perlfile'))
+ os.remove(fname)
+ end)
+
+ it(':perldo command', function()
+ -- :perldo 1; doesn't change $_,
+ -- the buffer should not be changed
+ command('normal :perldo 1;')
+ eq(false, curbufmeths.get_option('modified'))
+ -- insert some text
+ insert('abc\ndef\nghi')
+ expect([[
+ abc
+ def
+ ghi]])
+ -- go to top and select and replace the first two lines
+ feed('ggvj:perldo $_ = reverse ($_)."$linenr"<CR>')
+ expect([[
+ cba1
+ fed2
+ ghi]])
+ end)
+
+ it('perleval()', function()
+ eq({1, 2, {['key'] = 'val'}}, eval([[perleval('[1, 2, {"key" => "val"}]')]]))
+ end)
+end)
+
+describe('perl provider', function()
if helpers.pending_win32(pending) then return end
teardown(function ()
os.remove('Xtest-perl-hello.pl')
diff --git a/test/functional/ui/bufhl_spec.lua b/test/functional/ui/bufhl_spec.lua
index 0262a5b59b..d7269d2c29 100644
--- a/test/functional/ui/bufhl_spec.lua
+++ b/test/functional/ui/bufhl_spec.lua
@@ -699,14 +699,14 @@ describe('Buffer highlighting', function()
-- TODO: only a virtual text from the same ns curretly overrides
-- an existing virtual text. We might add a prioritation system.
set_virtual_text(id1, 0, s1, {})
- eq({{1, 0, 0, {virt_text = s1}}}, get_extmarks(id1, {0,0}, {0, -1}, {}, true))
+ eq({{1, 0, 0, {virt_text = s1}}}, get_extmarks(id1, {0,0}, {0, -1}, {details=true}))
-- TODO: is this really valid? shouldn't the max be line_count()-1?
local lastline = line_count()
set_virtual_text(id1, line_count(), s2, {})
- eq({{3, lastline, 0, {virt_text = s2}}}, get_extmarks(id1, {lastline,0}, {lastline, -1}, {}, true))
+ eq({{3, lastline, 0, {virt_text = s2}}}, get_extmarks(id1, {lastline,0}, {lastline, -1}, {details=true}))
- eq({}, get_extmarks(id1, {lastline+9000,0}, {lastline+9000, -1}, {}, false))
+ eq({}, get_extmarks(id1, {lastline+9000,0}, {lastline+9000, -1}, {}))
end)
it('is not highlighted by visual selection', function()