diff --git a/src/main/java/com/maddyhome/idea/vim/vimscript/model/functions/handlers/RenamingFunctionHandler.kt b/src/main/java/com/maddyhome/idea/vim/vimscript/model/functions/handlers/RenamingFunctionHandler.kt new file mode 100644 index 000000000..38ed930bc --- /dev/null +++ b/src/main/java/com/maddyhome/idea/vim/vimscript/model/functions/handlers/RenamingFunctionHandler.kt @@ -0,0 +1,48 @@ +/* + * IdeaVim - Vim emulator for IDEs based on the IntelliJ platform + * Copyright (C) 2003-2021 The IdeaVim authors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +package com.maddyhome.idea.vim.vimscript.model.functions.handlers + +import com.intellij.refactoring.rename.inplace.InplaceRefactoring +import com.maddyhome.idea.vim.api.ExecutionContext +import com.maddyhome.idea.vim.api.VimEditor +import com.maddyhome.idea.vim.newapi.ij +import com.maddyhome.idea.vim.vimscript.model.VimLContext +import com.maddyhome.idea.vim.vimscript.model.datatypes.VimDataType +import com.maddyhome.idea.vim.vimscript.model.datatypes.VimInt +import com.maddyhome.idea.vim.vimscript.model.expressions.Expression +import com.maddyhome.idea.vim.vimscript.model.functions.FunctionHandler + +object RenamingFunctionHandler : FunctionHandler() { + + override val name = "renaming" + override val minimumNumberOfArguments = 0 + override val maximumNumberOfArguments = 0 + + override fun doFunction( + argumentValues: List<Expression>, + editor: VimEditor, + context: ExecutionContext, + vimContext: VimLContext, + ): VimDataType { + return if (InplaceRefactoring.getActiveInplaceRenamer(editor.ij) == null) + VimInt.ZERO + else + VimInt.ONE + } +} diff --git a/src/main/resources/META-INF/includes/VimLibraryFunctions.xml b/src/main/resources/META-INF/includes/VimLibraryFunctions.xml index 5814d234f..12153a7ef 100644 --- a/src/main/resources/META-INF/includes/VimLibraryFunctions.xml +++ b/src/main/resources/META-INF/includes/VimLibraryFunctions.xml @@ -22,5 +22,6 @@ <vimLibraryFunction implementation="com.maddyhome.idea.vim.vimscript.model.functions.handlers.TolowerFunctionHandler" name="tolower"/> <vimLibraryFunction implementation="com.maddyhome.idea.vim.vimscript.model.functions.handlers.ToupperFunctionHandler" name="toupper"/> <vimLibraryFunction implementation="com.maddyhome.idea.vim.vimscript.model.functions.handlers.JoinFunctionHandler" name="join"/> + <vimLibraryFunction implementation="com.maddyhome.idea.vim.vimscript.model.functions.handlers.RenamingFunctionHandler" name="renaming"/> </extensions> -</idea-plugin> \ No newline at end of file +</idea-plugin>