mirror of
https://github.com/chylex/IntelliJ-IdeaVim.git
synced 2025-07-30 00:59:08 +02:00
Load extensions after vim script loading
This commit is contained in:
parent
5fdb817bfd
commit
c63a0200b3
src/com/maddyhome/idea/vim
@ -236,7 +236,13 @@ public class VimPlugin implements PersistentStateComponent<Element>, Disposable
|
||||
ideavimrcRegistered = true;
|
||||
|
||||
if (!ApplicationManager.getApplication().isUnitTestMode()) {
|
||||
executeIdeaVimRc();
|
||||
try {
|
||||
VimScriptParser.INSTANCE.setExecutingVimScript(true);
|
||||
executeIdeaVimRc();
|
||||
}
|
||||
finally {
|
||||
VimScriptParser.INSTANCE.setExecutingVimScript(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -359,6 +365,9 @@ public class VimPlugin implements PersistentStateComponent<Element>, Disposable
|
||||
// Execute ~/.ideavimrc
|
||||
registerIdeavimrc();
|
||||
|
||||
// Initialize extensions
|
||||
VimExtensionRegistrar.enableDelayedExtensions();
|
||||
|
||||
// Turing on should be performed after all commands registration
|
||||
getSearch().turnOn();
|
||||
VimListenerManager.INSTANCE.turnOn();
|
||||
|
@ -50,6 +50,8 @@ object VimScriptParser {
|
||||
// This is a pattern used in ideavimrc parsing for a long time. It removes all trailing/leading spaced and blank lines
|
||||
private val EOL_SPLIT_PATTERN = Pattern.compile(" *(\r\n|\n)+ *")
|
||||
|
||||
var executingVimScript = false
|
||||
|
||||
@JvmStatic
|
||||
fun findIdeaVimRc(): File? {
|
||||
val homeDirName = System.getProperty("user.home")
|
||||
|
@ -21,6 +21,7 @@ import com.intellij.openapi.diagnostic.logger
|
||||
import com.intellij.openapi.extensions.ExtensionPointListener
|
||||
import com.intellij.openapi.extensions.PluginDescriptor
|
||||
import com.maddyhome.idea.vim.VimPlugin
|
||||
import com.maddyhome.idea.vim.ex.vimscript.VimScriptParser
|
||||
import com.maddyhome.idea.vim.key.MappingOwner.Plugin.Companion.remove
|
||||
import com.maddyhome.idea.vim.option.OptionsManager
|
||||
import com.maddyhome.idea.vim.option.OptionsManager.addOption
|
||||
@ -34,6 +35,8 @@ object VimExtensionRegistrar {
|
||||
private var extensionRegistered = false
|
||||
private val logger = logger<VimExtensionRegistrar>()
|
||||
|
||||
private val delayedExtensionEnabling = mutableListOf<ExtensionBeanClass>()
|
||||
|
||||
@JvmStatic
|
||||
fun registerExtensions() {
|
||||
if (extensionRegistered) return
|
||||
@ -62,8 +65,7 @@ object VimExtensionRegistrar {
|
||||
val option = ToggleOption(name, name, false)
|
||||
option.addOptionChangeListener { _, _ ->
|
||||
if (isSet(name)) {
|
||||
extensionBean.instance.init()
|
||||
logger.info("IdeaVim extension '$name' initialized")
|
||||
initExtension(extensionBean, name)
|
||||
} else {
|
||||
extensionBean.instance.dispose()
|
||||
}
|
||||
@ -71,6 +73,24 @@ object VimExtensionRegistrar {
|
||||
addOption(option)
|
||||
}
|
||||
|
||||
private fun initExtension(extensionBean: ExtensionBeanClass, name: String) {
|
||||
if (VimScriptParser.executingVimScript) {
|
||||
delayedExtensionEnabling += extensionBean
|
||||
} else {
|
||||
extensionBean.instance.init()
|
||||
logger.info("IdeaVim extension '$name' initialized")
|
||||
}
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun enableDelayedExtensions() {
|
||||
delayedExtensionEnabling.forEach {
|
||||
it.instance.init()
|
||||
logger.info("IdeaVim extension '${it.name}' initialized")
|
||||
}
|
||||
delayedExtensionEnabling.clear()
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
private fun unregisterExtension(extension: ExtensionBeanClass) {
|
||||
val name = extension.name ?: extension.instance.name
|
||||
|
Loading…
Reference in New Issue
Block a user