-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
[RDY] making the API callable from vimscript #4934
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
I think it's reasonable and even preferable that the API is a bit more rigid.
Can't think of a reason against. I can't shake the idea that it might be useful to somehow namespace the API functions:
Maybe it's not useful though, and it's better that they are treated as first-class VimL functions. After all, VimL is itself an implicit namespace. |
Is this the reason for replace int64 |
Not really, I replaced
I don't have any super strong opinion really, but for me |
You're probably right, I'm overthinking it. The API methods will tend to be very verbose, which is unlikely to conflict with future vim functions. No extra namespace ceremony needed.
👍 |
@bfredl
I would still go for
Also remember that new Vim functions are named like Also note that all variants listed after And you completely forgot about Regarding function table: I would really suggest to turn this into a hash. I even started doing something like this, but stopped at problem “how to keep khash (or hashtab) reimplementation in lua consistent with it in C code”. Patch is still available: 821958a. |
Good point.
Not completely, it is still For me names like |
I though of a hash too, but I thought instead of just initializing the hash with c code (then in principle we could modify |
@bfredl Currently all |
@bfredl I do not think this will bring significant cost to the startup, but neither I think that increasing time and memory usage while there is such an easy optimization available is a good idea. Only problem there was “rewriting khash.h in lua” vs “making cross-compiling impossible” vs “adding gperf as a dependency”. Do not remember why I did not post this as a PR with this question: probably 1 or 3 would be accepted. |
36aaf6a
to
f2cb981
Compare
@ZyX-I Ok, I went with Still a lot of expected warnings I hope to go though this weekend (mostly conversion and add dummy |
I currently do not know how to do this with cmake. Using |
Yes |
Couldn't we commit the result of gperf, instead of requiring gperf as a dependency? We could automate this in travis:
|
We could, but it seems to just be more complicated for the developer, for no real benifit. We are already requiring (host) lua to be present for building nvim, and building it and running it automatically for the developer, why can't we do the same with gperf? Now, I could imagine shipping the gperf output as part of release tarballs, as the expectaction there is that no modification will be made to the code. |
I don't feel strongly about it, but gperf is a bit more obscure, and our build stack already gets plenty of complaints. Lua doesn't seem comparable: we will eventually ship lua to the end user, so it's not only a build-time dependency. |
As I suggested neither would end user nor distro people (the ones mostly complaining of our build system, I would presume) need to have gperf if we ship the result as part of the release tarballs, so gperf won't either be a pure bulid-time dependency. So the situation do seem comparable with lua generation to me. It would only affect the developers situation, and having a small c utility built for you (after a bunch of other c dependencies) seems less burdensome to me than requesting the developer to copy some text from a gist for some reason or getting a weird error message suggesting the developer to build and run gperf themselves. |
I guess my main point is, the developer does not need to care at all about most of our auto-generating, say, for internal prototypes and the option table, but if the developer happens to change api prototypes now the developer is suddenly forced to care a lot of our process. At least to me this inconsistency would seem a bit odd and hard to explain. |
8900835
to
ac835b8
Compare
I made an attempt of building gperf only if it's needed. The generated hash could be shipped in a release tarball by |
The feature itself is more or less "done", so marking RFC.
|
Removes all kinds of problems with sorting, provides a ready-to-use function list representation for genvimvim.lua, does not require specifying function name twice (VimL function name (string) + f_ function name).
Problems: - Disables cross-compiling (alternative: keeps two hash implementations which need to be synchronized with each other). - Puts code-specific name literals into CMakeLists.txt. - Workaround for lua’s absence of bidirectional pipe communication is rather ugly.
…the header generator.
also allow handle==0 meaning curbuf/curwin/curtab
make api functions highlighted as builtins in vim.vim
Blacklist deprecated functions and functions depending on channel_id
This applies both to msgpack-rpc and eval.
Marking as RDY, if no more comments of the code I will merge this, as there are a few PRs wanting to add API functions. (docs I'm not happy with, but as said that will be another PR with auto generating docs for methods, which also will make it easier to reason the surrounding docs) |
# define kmalloc(Z) malloc(Z) | ||
# endif | ||
# ifndef krealloc | ||
# define krealloc(P,Z) realloc(P,Z) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As a note:
There is a difference in behavior for xrealloc(not NULL ,0)
and realloc(not NULL, 0)
.
realloc()
acts here as free()
, xrealloc()
will always allocate at least one byte.
Thanks for this, @bfredl |
FEATURES: 0b5a7e4 neovim#4432 API: external UIs can render custom popupmenu c6ac4f8 neovim#4934 API: call any API method from vimscript 31df051 neovim#4568 API: nvim_call_atomic(): multiple calls in a single request b268ba3 neovim#5424 API: nvim_win_get_number(), nvim_tabpage_get_number() e7e2844 has("nvim-1.2.3") checks for a specific Nvim version 522b885 neovim#5295, neovim#5493 `:CheckHealth` checks tmux, terminfo, performance 719dae2 neovim#5384 events: allow event processing in getchar() f25797f neovim#5386 API: metadata: Nvim version & API level 22dfe69 neovim#5389 API: metadata: "since", "deprecated_since" 605e743 Added QuickFixLine highlight group CHANGES: 4af6ec7 neovim#5253 perf: Disable clipboard in do_cmdline() 6e9f329 neovim#5299 perf: Skip foldUpdate() in insert-mode. 9d4fcec neovim#5426 perf: Do not auto-update folds for some foldmethods. eeec0ca neovim#5419 tui: Default to normal-mode cursor shape. FIXES: e838452 neovim#5436 tui: Fix "weird characters" / "bleeding termcodes" 10a54ad neovim#5243 signal_init: Always unblock SIGCHLD. bccb49b neovim#5316 eval.c: Fix memory leak for detached pty job 626065d neovim#5227 tchdir: New tab should inherit CWD. cd321b7 neovim#5292 getcwd(): Return empty string if CWD is invalid. 6127eae shada: Fix non-writeable ShaDa directory handling ca65514 neovim#2789 system(): Respect shellxescape, shellxquote 2daf54e neovim#4874 Restore vim-like tab dragging 0c536b5 neovim#5319 syntax.c: Support bg/fg special color-names. 3c53371 neovim#4972 from justinmk/schedule-ui_refresh 68bcb32 neovim#4789 tui.c: Do not wait for tui loop on teardown. c8b6ec2 neovim#5409 v:count broken in command-line window 6bc3bce neovim#5461 fix emoji display 51937e1 neovim#5470 fix :terminal with :argadd, :argu 79d77da neovim#5481 external UIs: opening multiple files from command-line 657ba62 neovim#5501 rplugin: resolve paths in manifest file 6a6f188 neovim#5502 system('foo &', 'bar'): Show error, don't crash. 1ff162c neovim#5515 os_nodetype: open fd with O_NONBLOCK 2a6c5bb neovim#5450 modeline: Handle version number overflow. 0ade1bb neovim#5225 CI tests now run against Windows!
FEATURES: 0b5a7e4 neovim#4432 API: external UIs can render custom popupmenu c6ac4f8 neovim#4934 API: call any API method from vimscript 31df051 neovim#4568 API: nvim_call_atomic(): multiple calls in a single request b268ba3 neovim#5424 API: nvim_win_get_number(), nvim_tabpage_get_number() e7e2844 has("nvim-1.2.3") checks for a specific Nvim version 522b885 neovim#5295, neovim#5493 `:CheckHealth` checks tmux, terminfo, performance 719dae2 neovim#5384 events: allow event processing in getchar() f25797f neovim#5386 API: metadata: Nvim version & API level 22dfe69 neovim#5389 API: metadata: "since", "deprecated_since" 605e743 Added QuickFixLine highlight group CHANGES: 4af6ec7 neovim#5253 perf: Disable clipboard in do_cmdline() 6e9f329 neovim#5299 perf: Skip foldUpdate() in insert-mode. 9d4fcec neovim#5426 perf: Do not auto-update folds for some foldmethods. eeec0ca neovim#5419 tui: Default to normal-mode cursor shape. FIXES: e838452 neovim#5436 tui: Fix "weird characters" / "bleeding termcodes" 10a54ad neovim#5243 signal_init: Always unblock SIGCHLD. bccb49b neovim#5316 eval.c: Fix memory leak for detached pty job 626065d neovim#5227 tchdir: New tab should inherit CWD. cd321b7 neovim#5292 getcwd(): Return empty string if CWD is invalid. 6127eae shada: Fix non-writeable ShaDa directory handling ca65514 neovim#2789 system(): Respect shellxescape, shellxquote 2daf54e neovim#4874 Restore vim-like tab dragging 0c536b5 neovim#5319 syntax.c: Support bg/fg special color-names. 3c53371 neovim#4972 from justinmk/schedule-ui_refresh 68bcb32 neovim#4789 tui.c: Do not wait for tui loop on teardown. c8b6ec2 neovim#5409 v:count broken in command-line window 6bc3bce neovim#5461 fix emoji display 51937e1 neovim#5470 fix :terminal with :argadd, :argu 79d77da neovim#5481 external UIs: opening multiple files from command-line 657ba62 neovim#5501 rplugin: resolve paths in manifest file 6a6f188 neovim#5502 system('foo &', 'bar'): Show error, don't crash. 1ff162c neovim#5515 os_nodetype: open fd with O_NONBLOCK 2a6c5bb neovim#5450 modeline: Handle version number overflow. 0ade1bb neovim#5225 CI tests now run against Windows!
ref #4091
Instead of generating a
f_
wrapper per function, this implements a singleapi_wrapper
function in analogy withfloat_op_wrapper
. Extend thefunctions
table to allow an extra argument to an implementation, this allows several builtin function to share a single implementation (as demonstrated this can be used in many cases forfloat_op_wrapper
as well).This reuses the handlers implemented for msgpack dispatch. This saves us from generating more code, but means the type checking will be more or less the same. A reason for generating separate
f_vim_...
wrappers could be to behave more like other builtins with automatic conversion to an int if an int is expected and such (so "somestring" becomes 0 without any error or warning). Though IMO this is not a problem as the names of these functions clearly stand out and hey proper typechecking is nice.Still the functions need to be inserted in to the table of builtins. We could use #3922 for this to autogenerate this and sort it into the table by lua code.
Arguably buffer nrs should be identified with buffer "handles", otherwise would be a disaster. (It seems reasonable a nvim session would only have
<2^31
buffer creation events but I could be wrong...) I would also suggest 0 being a special value always meaning curbuf/curwin etc so one don't need to dobuffer_...(bufnr(''), ...)
for a one-off api call.