Fix(VIM-2933): Reloading/sourcing .ideavimrc does not initialize new plugins #736
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Found two issues related to VIM-2933:
Clicking the Reload button did not call
VimExtensionRegistrar.enableDelayedExtensions()
, so new extensions were not getting initialized.At this point, there are 3 places in the code that follow the pattern of setting the
vimscriptExecutor.executingVimscript
flag, executing a script, and then initializing new extensions. On the other hand, the:source
command does not appear to do this at all, it just executes the script and initializes extensions immediately.I don't know why extensions have to be delayed, but it seems like the inconsistency and duplication of this behavior should be refactored. If this behavior exists at all, isn't it always necessary? - In which case the delayed initialization + setting of the flag should perhaps be done directly in
Executor.execute
, rather than having to remember to do it manually anywhere scripts are being executed.It was possible to edit
.ideavimrc
and run:source ~/.ideavimrc
before the file was actually saved. The Reload button ensures the file is saved first, but:source
does not.This PR ensures that, before executing any script file, if the script file is currently opened in an editor and dirty, it will be saved first. This also means the Reload button itself doesn't need to save the file anymore.
As I said earlier,
:source
does (eagerly) initialize new extensions, so this is a slightly different issue. I'm guessing the author of VIM-2933 edited the file, tried sourcing it, and it did not initialize new extensions just because IntelliJ hadn't saved the file yet, so they assumed the initialization was broken entirely; that's what happened to me while I was trying to reproduce the issue.Since this fix affects all script file executions, let me know if you'd like me to separate it into 2 commits and/or PRs.