Skip to content

[RFC] generate UI remote event wrappers #6618

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

Merged
merged 7 commits into from
May 10, 2017
Merged

Conversation

bfredl
Copy link
Member

@bfredl bfredl commented Apr 29, 2017

Remaining TODO:

  • add to metadata
    • versioning
  • finish refactor of UI_CALL wrappers
  • generate code for ui bridge?
  • fix memory leaks

@marvim marvim added the WIP label Apr 29, 2017
@bfredl
Copy link
Member Author

bfredl commented Apr 29, 2017

An open question is if it makes sense to version individual updates. Unlike API functions it seems not as critical as clients can ignore unsupported updates. So maybe its enough to version remote ui methods and ui options. OTOH there could be a situation where we want to expose an improved version of the same widget, and that could either be exposed a new option, or maybe just as new updates/fields, in case updates need to be versioned.

Also, it might sense later on to reuse parts of this for other remote builtin events (though those will be a lot simpler as there is no struct-of-fptrs and no bridge involved).

@justinmk
Copy link
Member

justinmk commented Apr 29, 2017

An open question is if it makes sense to version individual updates. Unlike API functions it seems not as critical as clients can ignore unsupported updates. So maybe its enough to version remote ui methods and ui options

By "version" you mean "note the API level where a function was introduced"? We probably should do that I guess.

OTOH there could be a situation where we want to expose an improved version of the same widget, and that could either be exposed a new option, or maybe just as new updates/fields, in case updates need to be versioned.

Just like with functions, we will have to name a new update type.

@bfredl
Copy link
Member Author

bfredl commented Apr 29, 2017

So If I understand you correctly, updates should be versioned?

@justinmk
Copy link
Member

I would think it will be helpful if they are included in the metadata with a FUNC_API_SINCE value. But the FUNC_API_SINCE value shouldn't be incremented if items are added to the UI event.

If UI event has 4 items but a previous Nvim release had 3 items in the same UI event, a UI that was implemented with the 4-item version may not be prepared to see the 3-item version. I think we need a field in the metadata that says how many items in a UI event are optional?

@bfredl
Copy link
Member Author

bfredl commented Apr 29, 2017

as parameters are tuples, we could add version levels to parameters. But maybe that just be a "if using master version ui, and stuff breaks, upgrade to nvim master" thing.

@bfredl
Copy link
Member Author

bfredl commented Apr 30, 2017

added metadata, but versioning is WIP.

@@ -0,0 +1,71 @@
lpeg = require('lpeg')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not like the idea of placing modules into scripts/, name of the directory implies that it contains scripts. So far such things were only in test/ and src/nvim/, but first is for tests and second only contains various lists (like list of commands) ATM, so if you think that e.g. src/nvim/api/ is not fine feel free to create some new directory.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed, somewhere in src/ would be good

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well it is a library used by scripts/ and unlike dispatch_deprecated.lua (which actually defines stuff exposed in the nvim binary, and thus belong in src/) it is not really api source. As you mention test/ contains not only tests but also libraries for tests, is this not analogous?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so maybe scripts/helpers.lua ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bfredl test/ contains libraries for tests and tests, but both can’t be run on their own (tests are only runnable by busted which is a whole bunch of other lua stuff). Also libraries for tests are named “smth.lua”, tests are named “smth_spec.lua”: easily distinguishable. And all are lua, non-lua things have separate directories.

Neither distinguishable naming nor grouping by “scripts are lua and library for scripts is lua” applies here. Last, but not least: I would not expect directory named scripts/ contain any non-scripts, just like bin/ containing something which is not runnable from the command-line, not even any directory with some stuff; ls -lA {,/usr{,/local}}/bin/*(ND-^*) shows that Gentoo maintainers agree with me here: found only .keep and a bunch of broken symlinks.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bfredl I do not like the idea of invoking anything with top-level Makefile, especially since now even make clint is going to pull in dependencies. And if I am debugging e.g. declarations generator I would not want to run it on all files, so gen_xx is immediately out even if available from build/Makefile, defined in src/nvim/CMakeLists.txt and only proxied from top-level Makefile like most other its targets are. Additionally where generated files are placed is much of a tab-completion waste then extra bin: Vim :e is nearly not as good at completion as zsh, manually specifying the target file to a reachable location is better.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm talking about sensible defaults; how these commands normally are invoked, it doesn't prohibit anyone in an edge case to construct​ the cmdline themselves (possibly by modifying one from verbose make gen_xx, if from top-level or build/ is always up to the individual developer and completely besides the point)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe that's better, but wouldn't paths.lua then be need to be found by some mechanism? At which point the mechanism can be used to find the paths directly...

This is more about how many data would be fine to pass through that mechanism. E.g. better make user specify one path to build/ then both path to build/ and pass to source.

I guess I'm too used to languages where including code from the same directory as the code is a thing you just do...

Do not remember using such languages in Neovim, or them being common in my experience:

  • Python is directed by sys.path for which you need things like pip install --editable . (or $PYTHONPATH). There is from .foo import smth, but this is only going to work in imported modules which requires them being in sys.path.
  • Shell requires hacks with $0, $_ or $BASH_SOURCE.
  • lua needs to adjust package.path and package.cpath via e.g. $LUA_INIT (and it is really the worst: most verbose, needs escaping, inconsistent with others which have $*PATH).
  • C needs supplying -I or -isystem argument to compiler. Did not really do modules with Perl, but AFAIK it has . in @INC, but not something to run from the codes directory and not current. @INC may be adjusted with -I argument.
  • CMake includes only from CMAKE_MODULE_PATH, though it is the closest: you may alternatively use include(cmake/Foo.cmake) and it would be relative to where CMakeLists.txt is located (including when you use include() from cmake/Foo.cmake, so it is not “including code from the same directory as the code is”).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm talking about sensible defaults; how these commands normally are invoked, it doesn't prohibit anyone in an edge case to construct​ the cmdline themselves (possibly by modifying one from verbose make gen_xx, if from top-level or build/ is always up to the individual developer and completely besides the point)

I have no idea why I would need to invoke generators separately from the build if not for debugging them. But for debugging this is not really needed because CMake puts generated files first, so one make and I see bugs in generators and need to run them manually. And also CMake is nice enough to know (because generators are specified in DEPENDS) when generators need to be rerun, so this covers “generator is in any case invoked only once” case where there is no difference in amount of waiting done in manually vs via cmake cases.

And top-level or build/ is not besides the point, getting actual commands out of the generated Makefile is harder then from top-level which is written by developers. And they tend to be overly verbose: after make VERBOSE=1 output between highlighted “Generating” and highlighted “Scanning dependencies of target nvim” is unhighlighted, wrapped by the terminal and is literally this:

cd /home/zyx/a.a/Proj/c/neovim/build/src/nvim && /usr/bin/clang /home/zyx/a.a/Proj/c/neovim/src/nvim/fileio.c -E -o /home/zyx/a.a/Proj/c/neovim/build/src/nvim/auto/fileio.i -D_GNU_SOURCE -DMIN_LOG_LEVEL=0 -DDO_NOT_DEFINE_EMPTY_ATTRIBUTES -DEXITFREE -I/home/zyx/a.a/Proj/c/neovim/build/config -I/home/zyx/a.a/Proj/c/neovim/src -I/usr/include -I/home/zyx/a.a/Proj/c/neovim/build/src/nvim/auto -I/home/zyx/a.a/Proj/c/neovim/build/include -g -O0 -g -DEXITFREE -Wconversion -O0 -g -DEXITFREE -Wconversion
cd /home/zyx/a.a/Proj/c/neovim/build/src/nvim && /home/zyx/.local-luajit/bin/luajit /home/zyx/a.a/Proj/c/neovim/scripts/gendeclarations.lua /home/zyx/a.a/Proj/c/neovim/src/nvim/fileio.c /home/zyx/a.a/Proj/c/neovim/build/src/nvim/auto/fileio.c.generated.h /home/zyx/a.a/Proj/c/neovim/build/include/fileio.h.generated.h /home/zyx/a.a/Proj/c/neovim/build/src/nvim/auto/fileio.i
cd /home/zyx/a.a/Proj/c/neovim/build && /home/zyx/.local-cmake-v2.8.7/bin/cmake -E cmake_depends "Unix Makefiles" /home/zyx/a.a/Proj/c/neovim /home/zyx/a.a/Proj/c/neovim/src/nvim /home/zyx/a.a/Proj/c/neovim/build /home/zyx/a.a/Proj/c/neovim/build/src/nvim /home/zyx/a.a/Proj/c/neovim/build/src/nvim/CMakeFiles/nvim.dir/DependInfo.cmake --color=
Dependee "/home/zyx/a.a/Proj/c/neovim/src/nvim/fileio.c" is newer than depender "src/nvim/CMakeFiles/nvim.dir/fileio.c.o".
Clearing dependencies in "/home/zyx/a.a/Proj/c/neovim/build/src/nvim/CMakeFiles/nvim.dir/depend.make".

Try to find generator invocation here. It is, of course, possible, but if that was written in top-level (not proxied) it would miss cd and use relative paths which cuts down text a lot. Though you would have troubles telling CMake invoke it, so such entry point would be for debugging purposes only.

Copy link
Member Author

@bfredl bfredl May 2, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just meant when debugging, the starting point would be to invoke exactly the same way as the build files does.

And they tend to be overly verbose: after make VERBOSE=1 output

Hmm, I litteraly get 6 short lines before entering build/ (of course more if cmake needed rerun), zero lines after. And grepping for gendispactch gives:

[102/260] cd /home/bjorn/dev/neovim/build/src/nvim && /home/bjorn/dev/neovim/.deps/usr/bin/luajit /home/bjorn/dev/neovim/scripts/gendispatch.lua /home/bjorn/dev/neovim/src/nvim /home/bjorn/dev/neovim/src/nvim/api/buffer.h /home/bjorn/dev/neovim/src/nvim/api/tabpage.h /home/bjorn/dev/neovim/src/nvim/api/ui.h /home/bjorn/dev/neovim/src/nvim/api/vim.h /home/bjorn/dev/neovim/src/nvim/api/window.h /home/bjorn/dev/neovim/build/include/api/buffer.h.generated.h /home/bjorn/dev/neovim/build/include/api/tabpage.h.generated.h /home/bjorn/dev/neovim/build/include/api/ui.h.generated.h /home/bjorn/dev/neovim/build/include/api/vim.h.generated.h /home/bjorn/dev/neovim/build/include/api/window.h.generated.h /home/bjorn/dev/neovim/build/src/nvim/auto/api/private/dispatch_wrappers.generated.h /home/bjorn/dev/neovim/build/src/nvim/auto/api/private/funcs_metadata.generated.h /home/bjorn/dev/neovim/build/api_metadata.mpack

it seems readable enough, I don't see how it should be more or less verbose. But yeah individual make gen_xx would probably be overblow, make gen or make generators is probably enough. Generators depend on each other anyway, and rerunning just the needed generators will be alot faster than also rerunnning gcc (which could be a lot due to header dependencies). I find it rerunning cmake when needed practical, but again, no one is forced to use top-level short-cuts just because they exist.

@ZyX-I
Copy link
Contributor

ZyX-I commented May 1, 2017

@justinmk By the way, why clint.py is in src/. It appeared there in f421757 which is not shown as a part of some PR (GH states “pull request search timed out).

@jamessan
Copy link
Member

jamessan commented May 1, 2017

By the way, why clint.py is in src/

#4871

@ZyX-I
Copy link
Contributor

ZyX-I commented May 1, 2017

@jamessan Still no explanations.

@bfredl
Copy link
Member Author

bfredl commented May 2, 2017

While we are discussing paths and files, what do people think about the faux header file ui_events.h ? I guess it should be in api/ at least as it does define api events, but it is not really a header file as it is never included, it is just that C declarations is the best DSL for C declarations. Maybe it should have a different suffix?

@bfredl bfredl force-pushed the ui_event branch 3 times, most recently from 0d74799 to e6041f7 Compare May 2, 2017 11:10
@bfredl
Copy link
Member Author

bfredl commented May 2, 2017

Done versioning. I'll fix the generators location once #4411 is merged, to not unnecessary conflicts of changes to CMakeLists.txt.

@bfredl bfredl force-pushed the ui_event branch 6 times, most recently from e8875ea to c37e096 Compare May 2, 2017 12:19
@bfredl bfredl changed the title [WIP] generate UI remote event wrappers [RFC] generate UI remote event wrappers May 2, 2017
@marvim marvim added RFC and removed WIP labels May 2, 2017
@bfredl bfredl force-pushed the ui_event branch 2 times, most recently from df027b6 to 0ef56ef Compare May 9, 2017 09:34
@bfredl
Copy link
Member Author

bfredl commented May 9, 2017

Now has moved the generators to src/nvim/generators/

@@ -0,0 +1,49 @@
lpeg = require('lpeg')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is still in scripts.

justinmk added a commit to justinmk/neovim that referenced this pull request May 10, 2017
@bfredl
Copy link
Member Author

bfredl commented May 10, 2017

did some further small cleanups, will merge after tests if no more comments.

@bfredl bfredl merged commit 031756c into neovim:master May 10, 2017
@jszakmeister jszakmeister removed the RFC label May 10, 2017
justinmk added a commit to justinmk/neovim that referenced this pull request May 10, 2017
justinmk added a commit to justinmk/neovim that referenced this pull request May 10, 2017
justinmk added a commit to justinmk/neovim that referenced this pull request May 10, 2017
@justinmk justinmk mentioned this pull request May 11, 2017
justinmk added a commit to justinmk/neovim that referenced this pull request Feb 6, 2018
justinmk added a commit to justinmk/neovim that referenced this pull request Feb 6, 2018
Closes neovim#5442
Closes neovim#4142
References neovim#6618
References neovim#4376
References neovim#7844
justinmk added a commit to justinmk/neovim that referenced this pull request Feb 7, 2018
justinmk added a commit to justinmk/neovim that referenced this pull request Feb 7, 2018
justinmk added a commit to justinmk/neovim that referenced this pull request Feb 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants