Skip to content

Conversation

bfredl
Copy link
Member

@bfredl bfredl commented Jul 17, 2018

This allows to properly handle first buffer swap message, as well as
errors in startup files and --cmd commands in an external UI starting nvim as a child, just by using --embed-ui option instead of --embed

Note: this does nothing that a rpcrequest() in a --cmd and a corresponding handler in the UI client cannot do. But I think default matters, making a UI that has non-racy startup should be simple out of the box, rather than the UI needing to know details of the nvim startup process and event handling model even if it only ever wants to use nvim_ui_attach and nvim_input.

@bfredl
Copy link
Member Author

bfredl commented Jul 17, 2018

Also, later on nvim_ui_attach should be made non-deferred, but it might require some refactors, for instance in a wait-return state it cannot redraw the screen, it should rather just retransmit the screen (or even just fake the message if the new client wants to be narrower than the current message displayed before the wait-return prompt). That will now however only affect connecting to running instance, this PR handles the start-up case.

@marvim marvim added the RFC label Jul 17, 2018
Copy link
Member

@jamessan jamessan left a comment

Choose a reason for hiding this comment

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

LGTM other than the lint warning

src/nvim/main.c Outdated
@@ -819,6 +829,14 @@ static void command_line_scan(mparm_T *parmp)
mch_exit(0);
} else if (STRICMP(argv[0] + argv_idx, "headless") == 0) {
headless_mode = true;
} else if (STRICMP(argv[0] + argv_idx, "embed-ui") == 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Will this option (later) be added to nvim --help and the internal help?

Copy link
Member Author

Choose a reason for hiding this comment

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

It will be added now.

@bfredl
Copy link
Member Author

bfredl commented Jul 17, 2018

Yes, I will add some docs and test also :)

@bfredl
Copy link
Member Author

bfredl commented Jul 17, 2018

Messages sometimes get truncated, so this needs some more work.

@bfredl
Copy link
Member Author

bfredl commented Jul 17, 2018

After some discussion with @justinmk I think we could use the following rule to avoid adding more an option:

with --embed nvim always waits for any request on channel 1 before continuing with startup, this will break some clients but not all non-ui --embed-ers as using --embed-ui as --embed would. The old behavior can still be recovered with nvim --headless --cmd "call stdioopen({'rpc': v:true})"

@bfredl bfredl force-pushed the embed_ui branch 3 times, most recently from 8e1a1ef to a4653be Compare July 24, 2018 15:08
@bfredl bfredl force-pushed the embed_ui branch 2 times, most recently from 4a75398 to 89fb426 Compare September 4, 2018 12:19
@bfredl bfredl changed the title [RFC] main: add --embed-ui allow to wait for embedding UI to connect [RFC] main: make --embed wait for first request so embedding UI can display startup messages Sep 4, 2018
@bfredl
Copy link
Member Author

bfredl commented Sep 4, 2018

Update: now handles messages more consistently with TUI (never show more than one "press RETURN" prompt, unless the screen is really full or something). Note: unlike early TUI early messages can here be affected by colors loaded by vimrc. Which means if one message was displayed before :color and one after, the first will appear with builtin colors and the second with user colors. I think this is better than (1) wiping away the earliest message before it can be seen or (2) showing two "press RETURN" prompts just to not mix messages with different color schemes. Anyway this situation should be pretty rare. (swap messages, which should be the most common, will be shown with the user colors, just like TUI).

@@ -362,6 +362,7 @@ local function clear(...)
table.insert(args, arg)
end
set_session(spawn(args, nil, env))
session:request('nvim_eval', "0")
Copy link
Member

Choose a reason for hiding this comment

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

How about a comment:

-- Dummy request so that --embed starts the UI. 

@@ -128,6 +128,7 @@ for i,f in ipairs(shallowcopy(functions)) do
end
newf.impl_name = f.name
newf.remote_only = true
newf.async = f.async
Copy link
Member

Choose a reason for hiding this comment

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

Does this affect behavior somewhere or only api_info metadata ?

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 must have forgotten to remove this line, shallowcopy(f) already handles this...

@bfredl
Copy link
Member Author

bfredl commented Sep 18, 2018

Updated with a note in starting.txt, I will add a test or two also.

@bfredl
Copy link
Member Author

bfredl commented Sep 18, 2018

Added tests.

@@ -40,6 +40,8 @@
static PMap(cstr_t) *event_strings = NULL;
static msgpack_sbuffer out_buffer;

static bool seen_stdio_request = false;
Copy link
Member

Choose a reason for hiding this comment

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

got_stdio_request is more common convention.

Give embeders a chance to set up nvim, by processing a request before
startup. This allows an external UI to show messages and prompts from
--cmd and buffer loading (e.g. swap files)
@bfredl bfredl merged commit 809fff9 into neovim:master Sep 18, 2018
@justinmk justinmk removed the RFC label Sep 18, 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.

5 participants