mirror of
https://github.com/chylex/IntelliJ-IdeaVim.git
synced 2025-07-30 00:59:08 +02:00
Add name
and scope
fields to FunctionHandler
This commit is contained in:
parent
d98acd8c39
commit
5f15bca561
src/com/maddyhome/idea/vim/vimscript/model
@ -40,7 +40,7 @@ class CallCommand(val ranges: Ranges, val functionCall: FunctionCallExpression)
|
||||
val function = FunctionStorage.getFunctionHandlerOrNull(functionCall.scope, functionCall.functionName, parent)
|
||||
if (function != null) {
|
||||
function.ranges = ranges
|
||||
function.executeFunction(functionCall.functionName, functionCall.arguments, editor, context, this)
|
||||
function.executeFunction(functionCall.arguments, editor, context, this)
|
||||
return ExecutionResult.Success
|
||||
}
|
||||
|
||||
|
@ -15,7 +15,7 @@ data class FunctionCallExpression(val scope: Scope?, val functionName: String, v
|
||||
override fun evaluate(editor: Editor, context: DataContext, parent: Executable): VimDataType {
|
||||
val handler = FunctionStorage.getFunctionHandlerOrNull(scope, functionName, parent)
|
||||
if (handler != null) {
|
||||
return handler.executeFunction(this.functionName, this.arguments, editor, context, parent)
|
||||
return handler.executeFunction(this.arguments, editor, context, parent)
|
||||
}
|
||||
|
||||
val funcref = VariableService.getNullableVariableValue(Variable(scope, functionName), editor, context, parent)
|
||||
|
@ -38,10 +38,11 @@ import com.maddyhome.idea.vim.vimscript.model.statements.FunctionDeclaration
|
||||
import com.maddyhome.idea.vim.vimscript.model.statements.FunctionFlag
|
||||
import com.maddyhome.idea.vim.vimscript.services.VariableService
|
||||
|
||||
data class DefinedFunctionHandler(private val function: FunctionDeclaration) : FunctionHandler() {
|
||||
data class DefinedFunctionHandler(val function: FunctionDeclaration) : FunctionHandler() {
|
||||
|
||||
private val logger = logger<DefinedFunctionHandler>()
|
||||
|
||||
override val name = function.name
|
||||
override val scope = function.scope
|
||||
override val minimumNumberOfArguments = function.args.size
|
||||
override val maximumNumberOfArguments get() = if (function.hasOptionalArguments) null else function.args.size
|
||||
|
||||
|
@ -25,23 +25,26 @@ import com.maddyhome.idea.vim.ex.ranges.Ranges
|
||||
import com.maddyhome.idea.vim.vimscript.model.Executable
|
||||
import com.maddyhome.idea.vim.vimscript.model.datatypes.VimDataType
|
||||
import com.maddyhome.idea.vim.vimscript.model.expressions.Expression
|
||||
import com.maddyhome.idea.vim.vimscript.model.expressions.Scope
|
||||
|
||||
abstract class FunctionHandler {
|
||||
|
||||
abstract val name: String
|
||||
open val scope: Scope? = null
|
||||
abstract val minimumNumberOfArguments: Int?
|
||||
abstract val maximumNumberOfArguments: Int?
|
||||
var ranges: Ranges? = null
|
||||
|
||||
protected abstract fun doFunction(argumentValues: List<Expression>, editor: Editor, context: DataContext, parent: Executable): VimDataType
|
||||
|
||||
fun executeFunction(name: String, arguments: List<Expression>, editor: Editor, context: DataContext, parent: Executable): VimDataType {
|
||||
checkFunctionCall(name, arguments)
|
||||
fun executeFunction(arguments: List<Expression>, editor: Editor, context: DataContext, parent: Executable): VimDataType {
|
||||
checkFunctionCall(arguments)
|
||||
val result = doFunction(arguments, editor, context, parent)
|
||||
ranges = null
|
||||
return result
|
||||
}
|
||||
|
||||
private fun checkFunctionCall(name: String, arguments: List<Expression>) {
|
||||
private fun checkFunctionCall(arguments: List<Expression>) {
|
||||
if (minimumNumberOfArguments != null && arguments.size < minimumNumberOfArguments!!) {
|
||||
throw ExException("E119: Not enough arguments for function: $name")
|
||||
}
|
||||
|
@ -30,6 +30,7 @@ import kotlin.math.abs
|
||||
|
||||
object AbsFunctionHandler : FunctionHandler() {
|
||||
|
||||
override val name = "abs"
|
||||
override val minimumNumberOfArguments = 1
|
||||
override val maximumNumberOfArguments = 1
|
||||
|
||||
|
@ -38,6 +38,7 @@ import com.maddyhome.idea.vim.vimscript.model.functions.FunctionHandler
|
||||
// TODO: 03.08.2021 Support second parameter
|
||||
object LineFunctionHandler : FunctionHandler() {
|
||||
|
||||
override val name = "line"
|
||||
override val minimumNumberOfArguments = 1
|
||||
override val maximumNumberOfArguments = 2
|
||||
|
||||
@ -56,6 +57,7 @@ object LineFunctionHandler : FunctionHandler() {
|
||||
|
||||
object ColFunctionHandler : FunctionHandler() {
|
||||
|
||||
override val name = "col"
|
||||
override val minimumNumberOfArguments = 1
|
||||
override val maximumNumberOfArguments = 1
|
||||
|
||||
|
@ -36,6 +36,7 @@ import com.maddyhome.idea.vim.vimscript.model.functions.FunctionHandler
|
||||
|
||||
object EmptyFunctionHandler : FunctionHandler() {
|
||||
|
||||
override val name = "empty"
|
||||
override val minimumNumberOfArguments: Int = 1
|
||||
override val maximumNumberOfArguments: Int = 1
|
||||
|
||||
|
@ -33,6 +33,7 @@ import com.maddyhome.idea.vim.vimscript.parser.VimscriptParser
|
||||
|
||||
object ExistsFunctionHandler : FunctionHandler() {
|
||||
|
||||
override val name = "exists"
|
||||
override val minimumNumberOfArguments = 1
|
||||
override val maximumNumberOfArguments = 1
|
||||
|
||||
|
@ -34,6 +34,7 @@ import com.maddyhome.idea.vim.vimscript.model.functions.FunctionHandler
|
||||
|
||||
object LenFunctionHandler : FunctionHandler() {
|
||||
|
||||
override val name = "len"
|
||||
override val minimumNumberOfArguments = 1
|
||||
override val maximumNumberOfArguments = 1
|
||||
|
||||
|
@ -30,6 +30,7 @@ import kotlin.math.sin
|
||||
|
||||
object SinFunctionHandler : FunctionHandler() {
|
||||
|
||||
override val name = "sin"
|
||||
override val minimumNumberOfArguments = 1
|
||||
override val maximumNumberOfArguments = 1
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user