mirror of
https://github.com/chylex/IntelliJ-IdeaVim.git
synced 2025-08-16 22:31:47 +02:00
.github
.idea
.teamcity
assets
doc
gradle
resources
src
com
maddyhome
idea
vim
action
command
common
config
ex
extension
group
handler
helper
key
listener
option
regexp
ui
vimscript
model
commands
datatypes
expressions
functions
statements
loops
FunctionDeclaration.kt
IfStatement.kt
ReturnStatement.kt
ThrowStatement.kt
TryStatement.kt
Executable.kt
ExecutionResult.kt
Script.kt
parser
services
Executor.kt
DynamicLoaderStopper.kt
EventFacade.java
KeyHandler.java
PluginStartup.kt
RegisterActions.java
VimBundledDictionaryProvider.kt
VimPlugin.java
VimProjectService.kt
VimTypedActionHandler.kt
package-info.java
icons
main
test
vimscript-info
.editorconfig
.gitignore
.gitmodules
AUTHORS.md
CHANGES.md
CODE_OF_CONDUCT.md
CONTRIBUTING.md
LICENSE.txt
README.md
build.gradle.kts
gradle.properties
gradlew
gradlew.bat
qodana.yaml
settings.gradle
54 lines
1.7 KiB
Kotlin
54 lines
1.7 KiB
Kotlin
package com.maddyhome.idea.vim.vimscript.model.statements
|
|
|
|
import com.intellij.openapi.actionSystem.DataContext
|
|
import com.intellij.openapi.editor.Editor
|
|
import com.maddyhome.idea.vim.ex.ExException
|
|
import com.maddyhome.idea.vim.vimscript.model.Executable
|
|
import com.maddyhome.idea.vim.vimscript.model.ExecutionResult
|
|
import com.maddyhome.idea.vim.vimscript.model.datatypes.VimDataType
|
|
import com.maddyhome.idea.vim.vimscript.model.expressions.Scope
|
|
import com.maddyhome.idea.vim.vimscript.services.FunctionStorage
|
|
|
|
data class FunctionDeclaration(
|
|
val scope: Scope?,
|
|
val name: String,
|
|
val args: List<String>,
|
|
val body: List<Executable>,
|
|
val replaceExisting: Boolean,
|
|
val flags: Set<FunctionFlag>,
|
|
val hasOptionalArguments: Boolean,
|
|
) : Executable() {
|
|
|
|
/**
|
|
* we store the "a:" and "l:" scope variables here
|
|
* see ":h scope"
|
|
*/
|
|
val functionVariables: MutableMap<String, VimDataType> = mutableMapOf()
|
|
val localVariables: MutableMap<String, VimDataType> = mutableMapOf()
|
|
|
|
override fun execute(editor: Editor, context: DataContext): ExecutionResult {
|
|
val forbiddenArgumentNames = setOf("firstline", "lastline")
|
|
val forbiddenArgument = args.firstOrNull { forbiddenArgumentNames.contains(it) }
|
|
if (forbiddenArgument != null) {
|
|
throw ExException("E125: Illegal argument: $forbiddenArgument")
|
|
}
|
|
|
|
body.forEach { it.parent = this }
|
|
FunctionStorage.storeFunction(this)
|
|
return ExecutionResult.Success
|
|
}
|
|
}
|
|
|
|
enum class FunctionFlag(val abbrev: String) {
|
|
RANGE("range"),
|
|
ABORT("abort"),
|
|
DICT("dict"),
|
|
CLOSURE("closure");
|
|
|
|
companion object {
|
|
fun getByName(abbrev: String): FunctionFlag? {
|
|
return values().firstOrNull { it.abbrev == abbrev }
|
|
}
|
|
}
|
|
}
|