Commit Graph

332 Commits

Author SHA1 Message Date
Björn Linse
ead2fcf4ee api: add nvim_buf_call to call function with curbuf changed to buffer 2020-09-13 09:11:38 +02:00
Thomas Vigouroux
e4b5efa51e fix: use luahl in treesitter 2020-09-13 07:46:39 +02:00
Thomas Vigouroux
a8f71676a1 fix(bufupdates): avoid sending empty updates 2020-09-11 14:48:10 +02:00
Thomas Vigouroux
f0e258cf85 fix(bytetrack): send correct events when opening lines
a bit of test cleanup

ärrår

feeel

SPLIT

fix: sned correct updates on <CR>
2020-09-11 14:38:58 +02:00
Björn Linse
f239134fee tests: disable hl glitch test for now, will be fixed in luahl (next PR) 2020-09-10 06:50:04 +02:00
Thomas Vigouroux
82fb6a8818 fix lints 2020-09-09 21:22:21 +02:00
Björn Linse
bc86f76c0a api/buffer: add "on_bytes" callback to nvim_buf_attach
This implements byte-resolution updates of buffer changes.
Note: there is no promise that the buffer state is valid inside
the callback!
2020-09-09 21:22:21 +02:00
Thomas Vigouroux
1ff064126d treesitter: revert wrong optimization in highlights 2020-09-09 16:00:19 +02:00
Björn Linse
b397f31ede tests: update query.list_predicates() test 2020-09-06 10:33:13 +02:00
Thomas Vigouroux
dc579c420b treesitter: Use excplicit names in tests 2020-09-06 10:30:40 +02:00
Thomas Vigouroux
3fd6e3b923 treesitter: allow to list supported predicates 2020-09-04 15:24:23 +02:00
Thomas Vigouroux
4bcf54478a
Merge pull request #12814 from theHamsta/escape-queries
treesitter: avoid escaping complete query strings
2020-09-01 12:50:21 +02:00
Thomas Vigouroux
18217b987f treesitter: add node:field() to get field children 2020-09-01 08:57:55 +02:00
Stephan Seitz
b058c671d2 treesitter: avoid escaping complete query strings
Escape "\\" only for `vim-match?` not for `match?`
Fixes #12595
2020-08-31 17:24:38 +02:00
Thomas Vigouroux
e123fd0a5d treesitter: allow to iterate over node children 2020-08-31 13:42:30 +02:00
Thomas Vigouroux
24b5f69a49
fix(win): ignore closing wins in win_findbuf #12798
This caused segfaults when calling win_findbuf in an `on_detach`
callback, when the callback was triggered when closing the last window
containing the buffer.
2020-08-31 00:53:10 -07:00
TJ DeVries
3ccdbc570d
lua: add vim.register_keystroke_callback (#12536)
* feat: Add vim.register_keystroke_callback

* fixup: Forgot to remove mention of old option

* fixup: Answer jamessan comments

* fixup: Answer norcalli comments

* fixup: portability

* Update runtime/doc/lua.txt

Co-authored-by: Ashkan Kiani <ashkan.k.kiani@gmail.com>
2020-08-14 10:03:17 -04:00
Thomas Vigouroux
d7b12e58df treesitter: add and test vim-match? predicate 2020-08-13 20:30:15 +02:00
Thomas Vigouroux
58e37d7df8 treesitter: add contains? predicate 2020-08-13 20:30:15 +02:00
Thomas Vigouroux
613068071e treesitter: refactor and use lua regexes 2020-08-13 20:30:15 +02:00
Thomas Vigouroux
2c34780c32 buffer_updates: emit valid old_byte_size
Test this using treesitter highlighting, which is based on this
old_byte_size.
2020-07-21 19:18:04 +02:00
TJ DeVries
398201cfab
lua: Fix crash on unprotected lua errors (#12658)
Can be reproduced with a script like this:

-- in some lua file
vim.fn.timer_start(10, function() error("uh....") end)

-- will cause neovim to crash with the following error.
PANIC: unprotected error in call to Lua API
        (nlua_CFunction_func_call failed.)

After this, it will instead print the error message
from the top of the stack, like so.

tmp/error_nvim.lua:10: uh...

Also added an example test. Previously this test
caused the embedded nvim to panic.
2020-07-19 17:16:48 -04:00
TJ DeVries
6360cf7ce8 lua: Add ability to pass tables with __call
vim-patch:8.2.1054: not so easy to pass a lua function to Vim
vim-patch:8.2.1084: Lua: registering function has useless code

I think I have also opened up the possibility for people to use these
callbacks elsewhere, since I've added a new struct that we should be
able to use.

Also, this should allow us to determine what the state of a list is in
Lua or a dictionary in Lua, since we now can track the luaref as we go.
2020-07-10 20:23:12 -04:00
TJ DeVries
971a191c4d lua: Add ability to pass lua functions directly to vimL 2020-07-10 16:17:33 -04:00
Thomas Vigouroux
d19132ffd1 treesitter: update test to show overlapping works 2020-07-10 17:16:24 +02:00
Thomas Vigouroux
69816f5e13 treesitter: use single nodes in set_ranges
fixup! treesitter: fix lint
2020-06-29 23:32:49 +02:00
Thomas Vigouroux
66af35fc85 treesitter: separate tests into smaller pieces 2020-06-29 22:21:06 +02:00
Thomas Vigouroux
b652f74ca3 treesitter: use nodes to mark ranges 2020-06-29 22:21:06 +02:00
Thomas Vigouroux
ac18403d6e treesitter: test newly added set_included_ranges 2020-06-29 22:21:06 +02:00
Matthieu Coudron
dbc8ec9446
Merge pull request #12321 from vigoux/treesitter-runtime
treesitter: update runtime
2020-06-06 15:37:51 +02:00
TJ DeVries
d14298a1f0 test: remove flaky unhelpful test
vim.wait( sthg)
2020-06-06 01:11:12 +02:00
notomo
ac5a3f2c56
lua: fix behavior when split empty string (#12429)
* lua: fix behavior when split empty string

* test: lsp.util.apply_text_edits with an empty edit
2020-06-04 08:48:48 -04:00
Thomas Vigouroux
6a93077475 treesitter: fix tests 2020-06-03 19:58:02 +02:00
notomo
60c581b35d
lua: fix infinite loop for vim.split on empty string (#12420) 2020-06-02 19:31:43 -04:00
Thomas Vigouroux
8349192503 treesitter: update runtime
Since tree-sitter PR 615, predicates are not parsed the same.
"Old" way of writing predicates is still supported.
2020-06-02 21:19:07 +02:00
TJ DeVries
be662fe5c7 lua: vim.wait implementation 2020-05-30 12:01:32 -04:00
Mathias Fußenegger
04a0486c66
Change uri_to_fname to not convert non-file URIs (#12351)
* Change uri_to_fname to not convert non-file URIs

A URI with a scheme other than file doesn't have a local file path.

* fixup! Change uri_to_fname to not convert non-file URIs

* fixup! fixup! Change uri_to_fname to not convert non-file URIs
2020-05-22 01:17:21 +09:00
Hirokazu Hata
eabf1803cd
test: fix flaky vim.defer_fn test 2020-05-19 00:02:14 +09:00
Christian Clason
f2894bffb0
lua: Add highlight.on_yank (#12279)
* add lua function to highlight yanked region

* extract namespace, better naming, default values

* add default for event argument

* free timer

* factor out mark to position calculation

* d'oh

* make sure timer stops before callback (cf. luv example)

* factor out timer, more documentation

* fixup

* validate function argument for schedule

* fix block selection past eol

* correct handling of multibyte characters

* move arguments around, some cleanup

* move utility functions to vim.lua

* use anonymous namespaces, avoid local api

* rename function

* add test for schedule_fn

* fix indent

* turn hl-yank into proper (hightlight) module

* factor out position-to-region function

mark extraction now part of highlight.on_yank

* rename schedule_fn to defer_fn

* add test for vim.region

* todo: handle double-width characters

* remove debug printout

* do not shadow arguments

* defer also callable table

* whitespace change

* move highlight to vim/highlight.lua

* add documentation

* add @return documentation

* test: add check before vim.defer fires

* doc: fixup
2020-05-18 09:49:50 -04:00
Hirokazu Hata
ae5bd0454e
lua: add tbl_deep_extend (#11969) 2020-05-17 13:24:34 -04:00
TJ DeVries
1407899c32
lua: Add buffer, window and tab accessors (#12268)
* Add buffer, window and tab accessors

* Fix deletion and add tests
2020-05-07 15:22:24 -04:00
Mathias Fußenegger
2c40a38b39
LSP: Avoid URI-to-fname conversion for non-file URIs #12243
Fixes https://github.com/neovim/neovim/issues/12210
2020-05-04 20:06:40 -07:00
Tristan Konolige
bf0f745861
lua: allow deepcopy of functions (#12136) 2020-04-19 01:04:37 +02:00
Hirokazu Hata
4139678f97
vim.uri: fix uri_to_fname (#12059)
fix: #12056
If the colon of the drive letter of windows is URI encoded,
it doesn't match the expected pattern, so decode it first.
2020-03-30 14:30:24 +02:00
Hirokazu Hata
e35ff7371f
lua: add vim.tbl_len() #11889 2020-03-01 23:38:43 -08:00
Björn Linse
9c00fea585 lua: add regex support, and @match support in treesitter queries 2020-02-26 19:39:02 +01:00
Hirokazu Hata
e2ed8053bf
lua: move test helper function, map and filter, to vim.shared module 2020-02-18 17:43:10 +09:00
Björn Linse
dc0e534a91
Merge pull request #11864 from h-michael/deepcopy
lua: vim.deepcopy() and vim.tbl_extend() should preserve vim.empty_dict()
2020-02-15 18:10:48 +01:00
Hirokazu Hata
cdb729b746
lua: add vim.tbl_extend and vim.deepcopy test 2020-02-14 22:36:21 +09:00
Hirokazu Hata
417fc6ccf7
lua: vim.deepcopy uses empty_dict() instead of {} for empty_dict()
fix: https://github.com/neovim/nvim-lsp/issues/94
2020-02-13 11:55:43 +09:00
Hirokazu Hata
032ede0203
test: add json_encode test for vim.empty_dict() 2020-02-12 21:08:12 +09:00
Björn Linse
00c57c98df treesitter: add standard &rtp/parser/ search path for parsers 2020-02-07 09:22:55 +01:00
Hye Sung Jung
14a8b3b98c
doc: fix typos [ci skip] #11787 2020-01-30 22:56:34 -08:00
Axel Forsman
2538e61513
Fix shift change callbacks reading bad cursor (#11782)
Sloppy code inherited from Vim caused user scripts to be able
to observe the cursor line in an invalid intermediary state,
due to Neovim change callbacks being unbuffered unlike Vim listeners.

Manifested in Vimscript executed from the callback possibly erroring
when `:call`:ing any function,
due to the implicit range `curwin->w_cursor.lnum,curwin->w_cursor.lnum`
failing validation.

Fixed by deferring the call to `changed_lines()` until after
`curwin->w_cursor.lnum` gets its correct value.
2020-01-30 07:34:34 +01:00
Daniel Hahler
3d1531aee5
API: include invalid buffer/window/tabpage in error message (#11712) 2020-01-14 09:21:10 +01:00
Björn Linse
ea4127e9a7 lua: metatable for empty dict value 2020-01-01 19:26:29 +01:00
Björn Linse
440695c296 tree-sitter: implement query functionality and highlighting prototype [skip.lint] 2019-12-22 12:51:46 +01:00
Ashkan Kiani
0e6c6261e1
Fix access on vim.wo (#11517)
* Add more tests for vim.wo
2019-12-07 03:34:02 -08:00
Justin M. Keyes
a3b6c2a3dc API: rename nvim_execute_lua => nvim_exec_lua
- We already find ourselves renaming nvim_execute_lua in tests and
  scripts, which suggests "exec" is the verb we actually want.
- Add "exec" verb to `:help dev-api`.
2019-12-02 22:06:42 -08:00
Ashkan Kiani
70b6061666
Add vim.startswith and vim.endswith (#11248) 2019-12-01 05:32:55 -08:00
Ashkan Kiani
e6da21d128
Add vim.cmd as an alias for nvim_command (#11446) 2019-12-01 05:28:53 -08:00
Ashkan Kiani
edca84cfc9
Return nil instead of NIL for vim.env (#11486) 2019-12-01 05:04:57 -08:00
Björn Linse
a76a669ac2 lua: make vim.wo and vim.bo used nested indexing for specified handle
Also missing option should be an error. Options are functionality,
not arbitrary variable names (as for vim.g)
2019-11-26 18:44:36 +01:00
Ashkan Kiani
b78fdd7ce5 Merge branch 'master' into lsp-followup 2019-11-24 02:29:23 -08:00
Ashkan Kiani
d0d38fc36e Lua: vim.env, vim.{g,v,w,bo,wo} #11442
- Add vim variable meta accessors: vim.env, vim.{g,v,w,bo,wo}
- Redo gen_char_blob to generate multiple blobs instead of just one
  so that multiple Lua modules can be inlined.
- Reorder vim.lua inclusion so that it can use previously defined C
  functions and utility functions like vim.shared and vim.inspect things.
- Inline shared.lua into nvim, but also keep it available in runtime.
2019-11-24 02:28:48 -08:00
Ashkan Kiani
b984f613c1 Extend list_extend to take start/finish. 2019-11-20 17:09:21 -08:00
Björn Linse
dab40f43b1 Add v:lua.func() vimL syntax for calling lua
Also simplify error messages when calling lua from vimL.
2019-11-16 22:33:21 +01:00
Ashkan Kiani
00dc12c5d8 lua LSP client: initial implementation (#11336)
Mainly configuration and RPC infrastructure can be considered "done". Specific requests and their callbacks will be improved later (and also served by plugins). There are also some TODO:s for the client itself, like incremental updates.

Co-authored by at-tjdevries and at-h-michael, with many review/suggestion contributions.
2019-11-13 21:55:26 +01:00
Justin M. Keyes
a0d992785f Lua: Use vim.validate() instead of assert() 2019-11-10 23:43:49 -08:00
Justin M. Keyes
7aa4042d3b Lua: vim.validate() 2019-11-10 23:43:49 -08:00
Hirokazu Hata
678a51b1da Lua: vim.validate()
We often want to do type checking of public function arguments.

- test: Rename utility_function_spec.lua to vim_spec.lua
- .luacov: Map lua module names
2019-11-10 22:50:24 -08:00
Björn Linse
d200a818a7 tests: vim.rpcnotify test is flaky 2019-11-10 17:13:53 +01:00
Björn Linse
474d0bcbf7 lua: vim.rpcrequest, vim.rpcnotify, vim.NIL 2019-11-10 13:08:05 +01:00
Justin M. Keyes
9ef16a1628 doc: vim.fn, vim.call(), vim.api [ci skip] 2019-11-06 01:37:50 -08:00
Björn Linse
8ee7c94a92 lua: add vim.fn.{func} for direct access to vimL function
compared to vim.api.|nvim_call_function|, this fixes some typing issues
due to the indirect conversion via the API. float values are preserved
as such (fixes #9389) as well as empty dicts/arrays.

Ref https://github.com/norcalli/nvim.lua for the call syntax
2019-10-27 17:23:17 +01:00
Justin M. Keyes
316c29bbf3 test/pcall_err(): truncate full paths, omit linenr
ref #11271
2019-10-26 02:00:58 -07:00
Hirokazu Hata
996a057fb9 lua/stdlib: adjust some validation messages #11271
close #11271
2019-10-26 00:27:01 -07:00
Björn Linse
9fa850991d tree-sitter: improve and cleanup tests 2019-09-28 17:46:25 +02:00
Björn Linse
d5a69eb076 tree-sitter: handle node equality 2019-09-28 17:46:25 +02:00
Björn Linse
e0d6228978 tree-sitter: use "range" instead of "point_range" consistently in lua API 2019-09-28 17:46:25 +02:00
Björn Linse
06ee45b9b1 tree-sitter: fix lint, delete "demo" plugin (replaced by functional tests) 2019-09-28 17:46:25 +02:00
Björn Linse
167a1cfdef tree-sitter: improve parser API (shared parser between plugins) 2019-09-28 14:55:43 +02:00
Björn Linse
c8f861b739 tree-sitter: rename tree_sitter => treesitter for consistency 2019-09-28 14:55:43 +02:00
Björn Linse
4ea5e63aa8 tree-sitter: add basic testing on ci
build tree-sitter c parser on ci for testing purposes
2019-09-28 14:55:43 +02:00
Justin M. Keyes
af946046b9 test: Rename meth_pcall to pcall_err
- Rename `meth_pcall`.
- Make `pcall_err` raise an error if the function does not fail.
- Add `vim.pesc()` to treat a string as literal where a Lua pattern is
  expected.
2019-09-06 17:19:07 -07:00
Björn Linse
7e07efaff4 api: make try_end clean-up after an exception properly. Fixes #10809
Otherwise `force_abort` will cause an emsg() higher on the stack
to be converted to an exception, even though it is outside any
try/catch.
2019-09-02 23:01:16 +02:00
Björn Linse
1f54f68732 lua: minimal UTF-16 support needed for LSP 2019-08-08 20:10:14 +02:00
Björn Linse
c0993ed343 lua: support getting UTF-32 and UTF-16 sizes of replaced text 2019-08-06 20:24:36 +02:00
Björn Linse
b0e26199ec lua: add {old_byte_size} to on_lines buffer change event 2019-08-06 17:01:47 +02:00
Björn Linse
88938634e7 lua: add vim.in_fast_event() to check if we are in a luv callback 2019-08-05 13:57:24 +02:00
Björn Linse
e6d77993d1 lua: do not crash on syntax error in debug.debug() 2019-08-05 13:19:44 +02:00
Björn Linse
d3a7bdefb0 lua: immediate-callback safe print() 2019-08-05 13:19:44 +02:00
Daniel Hahler
68c594b10c
tests: loop_spec: retry (#10413)
Flaky test (osx):

    [  FAILED  ] ...is/build/neovim/neovim/test/functional/lua/loop_spec.lua @ 23: vim.loop timer
    ...is/build/neovim/neovim/test/functional/lua/loop_spec.lua:56: Expected objects to be the same.
    Passed in:
    (number) 0
    Expected:
    (number) 2
    stack traceback:
            ...is/build/neovim/neovim/test/functional/lua/loop_spec.lua:56: in function <...is/build/neovim/neovim/test/functional/lua/loop_spec.lua:23>

It was bumped from sleeping for 20ms to 50ms in d33aaa0f5f already.
2019-07-04 16:42:10 +02:00
Björn Linse
99f24dfbed make vim.loop == require'luv'
This avoids initializing libluv a second time if a plugin invokes
require'luv'. It is probably not an issue, but better to be safe.
2019-06-30 15:16:32 +02:00
Björn Linse
d33aaa0f5f libluv: use luv_set_callback to control callback execution
Disable the use of deferred API functions in a fast lua callback
Correctly display error messages from a fast lua callback
2019-06-30 13:13:08 +02:00
Björn Linse
64cdf9f78a api/lua: add on_detach to nvim_buf_attach 2019-06-15 13:19:12 +02:00
George Zhao
c83926cd0a lua: introduce vim.loop (expose libuv event-loop) #10123
Co-authored-by: Andrey Popp <8mayday@gmail.com>

closes #9546
closes #10084
2019-06-10 14:13:18 +02:00
Björn Linse
b684bd05b5 lua: docs and tests for vim.schedule 2019-06-05 10:46:22 +02:00
Justin M. Keyes
11a481f711 Merge #9686 'win/Lua: monkey-patch os.getenv()'
fixes #9681
2019-03-16 20:28:52 +01:00
erw7
c9264e6d52 Fix os.getenv of lua on Windows
Change to use os_getenv instead of getenv because environment variable
set by uv_os_setenv can not be get with getenv.
2019-03-07 13:49:02 +09:00
Björn Linse
f7b174eb71 tests/lua: test for multiline error messages in lua 2019-01-23 19:34:13 +01:00
Björn Linse
3a84e5be88 lua: expose full interface of vim.inspect and add test
Implement lazy loading for vim.submodule, this would be over-engineering
for inspect only, but we expect to use this solution also for more and
larger modules.
2019-01-14 20:12:57 +01:00
Justin M. Keyes
89d7e24891 Merge #9463 'Lua stdlib' 2019-01-14 02:25:45 +01:00
Justin M. Keyes
6c02ff4747 lua/stdlib: Load runtime modules on-demand
Instead of eager-loading during plugin/* sourcing, define runtime
modules such as `vim.inspect` as lazy builtins. Otherwise non-builtin
Lua modules such as `vim.inspect` would not be available during startup
(init.vim, `-c`, `--cmd`, …).

ref #6580
ref #8677
2019-01-14 02:22:16 +01:00
KillTheMule
bb3aa824b7 lua/stdlib: vim.inspect, string functions
ref #6580
ref #8677
2019-01-14 02:14:34 +01:00
Justin M. Keyes
c9f3174075 API: return non-generic VimL errors
- Return VimL errors instead of generic errors for:
  - nvim_call_function
  - nvim_call_dict_function
- Fix tests which were silently broken before this change.

This violates #6150 where we agreed not to translate API errors.  But
that can be fixed later.
2018-05-09 23:18:38 +02:00
Björn Linse
98e7112390 msg: do not scroll entire screen (#8088) 2018-03-31 11:12:27 +02:00
Justin M. Keyes
42b80c3acf Merge #7165 'lua: Move stricmp to vim module' 2017-10-22 16:29:36 +02:00
ZyX
b1a8dcefee lua/executor: Fix crash when first string contains NUL and second not 2017-08-15 17:18:05 +03:00
ZyX
93ef823f5e lua/executor: Move stricmp to vim “module” and document it 2017-08-15 16:34:51 +03:00
ZyX
96b1600bc8 functests: Add test for stricmp 2017-08-15 16:34:25 +03:00
Nikolai Aleksandrovich Pavlov
bf1b1ea6ee lua/executor: Fix crash when printing empty string (#7157) 2017-08-13 17:37:35 +02:00
ZyX
a409fa2b3f lua: Use automatic determining of suffixes only for package.cpath 2017-05-28 23:55:51 +03:00
ZyX
97602371e6 lua: Add paths from &runtimepath to package.path and package.cpath 2017-05-25 16:27:40 +03:00
ZyX
5b6d598ca8 functests: Fix tests 2017-05-08 21:21:03 +03:00
ZyX
09f849b600 Merge branch 'master' into luaviml'/lua 2017-05-08 15:43:45 +03:00
ZyX
78082e8d3e functests: Check whether it is a problem with an array 2017-04-11 11:05:19 +03:00
ZyX
acd9ed8d83 functests: Add another check for the similar transformation
Reasoning is majorly the same: check whether lua has bug or API function has 
bug, but on the other side: previous commit is checking whether similar bug when 
using API via msgpack RPC, this commit is checking whether another API function 
used via lua bindings triggers the same bug. Should additionally give a hint 
about which lua code contains a bug.
2017-04-11 02:32:13 +03:00
ZyX
9cad5155e3 functests: Make sure funcs.luaeval receives only one argument 2017-04-11 01:18:42 +03:00
ZyX
a40a969e9a api: Rename _vim_id functions to nvim__id 2017-04-08 20:33:48 +03:00
ZyX
a24e94215e eval,functests: Fix linter errors 2017-03-27 00:18:55 +03:00
ZyX
d13fdfd446 functests: Add test for debug.debug 2017-03-27 00:18:54 +03:00
ZyX
9fd2bf67aa executor,functests: Add print() tests, some fixes 2017-03-27 00:13:16 +03:00
ZyX
dcb992ab37 executor: Add :luafile command 2017-03-27 00:12:42 +03:00
ZyX
295e7607c4 executor: Fix some memory leaks 2017-03-27 00:12:42 +03:00
ZyX
e1bbaca7ac executor,functests: Add tests for :luado, also some fixes
Fixes:
1. Allocate space for the NUL byte.
2. Do not exclude last line from range.
3. Remove code for sandbox: it is handled earlier.
4. Fix index in new_line_transformed when converting NULs to NLs.
5. Always allocate new_line_transformed, but save allocated value.
2017-03-27 00:12:42 +03:00
ZyX
9114d9be77 executor: Add :luado command 2017-03-27 00:12:42 +03:00
ZyX
b4e2860c69 doc,functests: Add documentation
Missing: updates to various lists.
2017-03-27 00:12:42 +03:00
ZyX
7a5646d594 functests: Add tests for :lua 2017-03-27 00:12:42 +03:00
ZyX
666d85d3ce functests: Some more tests 2017-03-27 00:12:22 +03:00
ZyX
bca9c2f3c4 functests: Move existing tests from lua_spec to lua/*, fix them 2017-03-27 00:12:22 +03:00
ZyX
a3ea05c1e5 functests: Add some tests 2017-03-27 00:12:22 +03:00