-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Fix E523 on asynchronous truncated echo with getchar() #1987
Conversation
I can't quite explain why |
autoload/ale/cursor.vim
Outdated
@@ -26,7 +26,7 @@ function! ale#cursor#TruncatedEcho(original_message) abort | |||
|
|||
" The message is truncated and saved to the history. | |||
setlocal shortmess+=T | |||
exec "norm! :echomsg l:message\n" | |||
echomsg l:message |
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.
Write execute 'echomsg l:message'
here instead. One of the things the script tests for is people leaving stray echo lines lying around, and you can silence the warning by doing that.
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.
ok, I'll update. Thank you for explanation.
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.
I'm not fully understanding why the trailing \n
is added. If execute "echomsg l:message\n"
is better, please let me know.
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.
For future reference:
Quote: https://vim.fandom.com/wiki/Get_shortened_messages_from_using_echomsg
The second step is tricky. :echo does not shorten long messages. :echomsg, by itself, does not shorten long messages. Only when :echomsg is used under :norm, are long messages truncated. And don't forget trailing \n when using :exe norm.
Removing this has resulted in many people complaining about "Press ENTER" messages on long diagnostic messages: #4141
ca8ee57
to
577241e
Compare
Thank you for your review. I addressed it at 577241e.
Sure. Please feel free to revert this commit if some issue occurs. |
Hmm... Workers on Travis CI seem not working:
|
b4fce91
to
2cc2dac
Compare
51dd007
to
577241e
Compare
I understood that
I guess, some unit test hits |
1345f07
to
952a15f
Compare
I completely understood what happens on
|
Aha, I knew there was some reason for it, but I forgot what it was. Maybe the safest thing to do is just catch |
952a15f
to
17b02c7
Compare
I tried to change the implementation of unite.vim does the similar thing: https://github.com/Shougo/unite.vim/blob/e68ccde4192b3faa3717897e65dc7dd8ab87524a/autoload/unite/view.vim#L992-L1017 |
I'm not sure. I trust Vim to truncate messages accurately, but not any Vim script code. I prefer to avoid writing any code for truncating characters if possible. |
I agree with you. I also think using How about catching error? I think it's better than showing error message. try
exec "norm! :echomsg l:message\n"
catch /^Vim\%((\a\+)\)\=:E523/
" Should we fallback into manual truncate?
endtry |
Yeah, that's what I was suggesting. I think that's a much safer option. The error will be hidden in the minority of cases where it happens, and we know it won't break anything for anyone. I suppose we could fall back to manually truncating the text there too. Then a fallback that will work in the majority of cases will only be tried in a small minority of cases. |
17b02c7
to
5966b0e
Compare
I fixed my patch at 8272eea. Could you review again? |
17aa436
to
8272eea
Compare
Yep, that'll work. Cheers! 🍻 |
When a linting message is echoed in the command line, mode change was happening due to the use of ':' (see :help <Cmd>), triggering autocmd events such as CmdlineEnter and CmdlineLeave. To avoid that, we can use <Cmd> instead of ':' to avoid mode change. Reference: dense-analysis#1987
Problem
I have a mapping in my vimrc as follows:
The simple mapping gets one character from user with
getchar()
and put it to buffer. However, it seems that, when using this mapping at the same timing as ALE tries to echo linter warning, it sometimes causes an error as follows:The similar issue was reported to my clever-f.vim plugin.
rhysd/clever-f.vim#38
Investigation
I did not know when
E523
occurs. So I dug Vim source code and found the line causing the error:https://github.com/vim/vim/blob/b9464821901623f983528acaed9e4dc2cea7387b/src/normal.c#L799
This is a part of
:normal
command implementation.:normal
command shows the error message (text_locked_msg()
does) when it is executed while editing cmdline. (getchar()
gets user's input via cmdline)This was usually not a problem since Vim script is a synchronous language.
:normal
command was executed from insert mode or normal mode generally. While getting user input withgetchar()
, Vim script could do nothing since it's blocking.However, situation was changed by asynchronous features such as job or channel. Asynchronous callback is run at arbitrary timing, even while blocking operation such as calling
getchar()
.So what happens would be:
getchar()
getchar()
waits user input with blockingale#cursor#TruncatedEcho()
:normal
and causesE523
Fix
It seems that only
ale#cursor#TruncatedEcho
causes this issue. And I could not got whyTruncatedEcho
uses:normal
here. It seems that removingnormal
(Does the last\n
do something?). Executingechomsg
directly looks working on my environment.And after this fix, I haven't seen the
E523
error any more.