mirror of
https://github.com/chylex/IntelliJ-IdeaVim.git
synced 2025-05-07 21:34:09 +02:00
Add ExCommand annotation
This commit is contained in:
parent
9707704f57
commit
ff945e7b8a
annotation-processors/src/main
kotlin/com/intellij/vim
resources/META-INF/services
vim-engine
@ -0,0 +1,16 @@
|
||||
/*
|
||||
* Copyright 2003-2023 The IdeaVim authors
|
||||
*
|
||||
* Use of this source code is governed by an MIT-style
|
||||
* license that can be found in the LICENSE.txt file or at
|
||||
* https://opensource.org/licenses/MIT.
|
||||
*/
|
||||
|
||||
package com.intellij.vim.annotations
|
||||
|
||||
/**
|
||||
* [command] is formatted the same way it is formatted in Vim (with optional part in square brackets).
|
||||
*/
|
||||
@Target(AnnotationTarget.CLASS)
|
||||
@Retention(AnnotationRetention.SOURCE)
|
||||
annotation class ExCommand(val command: String)
|
@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright 2003-2023 The IdeaVim authors
|
||||
*
|
||||
* Use of this source code is governed by an MIT-style
|
||||
* license that can be found in the LICENSE.txt file or at
|
||||
* https://opensource.org/licenses/MIT.
|
||||
*/
|
||||
|
||||
package com.intellij.vim.processors
|
||||
|
||||
import com.google.devtools.ksp.KspExperimental
|
||||
import com.google.devtools.ksp.getAnnotationsByType
|
||||
import com.google.devtools.ksp.processing.Resolver
|
||||
import com.google.devtools.ksp.processing.SymbolProcessor
|
||||
import com.google.devtools.ksp.processing.SymbolProcessorEnvironment
|
||||
import com.google.devtools.ksp.symbol.KSAnnotated
|
||||
import com.google.devtools.ksp.symbol.KSClassDeclaration
|
||||
import com.google.devtools.ksp.symbol.KSFile
|
||||
import com.google.devtools.ksp.symbol.KSVisitorVoid
|
||||
import com.intellij.vim.FileWriter
|
||||
import com.intellij.vim.annotations.ExCommand
|
||||
|
||||
class ExCommandProcessor(private val environment: SymbolProcessorEnvironment): SymbolProcessor {
|
||||
companion object {
|
||||
const val comment = """# This file was automatically generated by [com.intellij.vim.processor.EXCommandProcessor].
|
||||
# If you are going to change it, you are probably doing something wrong, as your changes will be overridden by the next `gradle kspKotlin` run.
|
||||
|
||||
"""
|
||||
}
|
||||
private val visitor = EXCommandVisitor()
|
||||
private val writer = FileWriter()
|
||||
private val commandToClass = mutableMapOf<String, String>()
|
||||
|
||||
override fun process(resolver: Resolver): List<KSAnnotated> {
|
||||
resolver.getAllFiles().forEach { it.accept(visitor, Unit) }
|
||||
val filePath = environment.options["generated_directory"]!! + "/" + environment.options["ex_commands_file"]!!
|
||||
writer.writeFile(filePath, writer.getYAML(comment, commandToClass))
|
||||
return emptyList()
|
||||
}
|
||||
|
||||
private inner class EXCommandVisitor : KSVisitorVoid() {
|
||||
@OptIn(KspExperimental::class)
|
||||
override fun visitClassDeclaration(classDeclaration: KSClassDeclaration, data: Unit) {
|
||||
val exCommandAnnotation = classDeclaration.getAnnotationsByType(ExCommand::class).firstOrNull() ?: return
|
||||
commandToClass[exCommandAnnotation.command] = classDeclaration.qualifiedName!!.asString()
|
||||
}
|
||||
|
||||
override fun visitFile(file: KSFile, data: Unit) {
|
||||
file.declarations.forEach { it.accept(this, Unit) }
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
/*
|
||||
* Copyright 2003-2023 The IdeaVim authors
|
||||
*
|
||||
* Use of this source code is governed by an MIT-style
|
||||
* license that can be found in the LICENSE.txt file or at
|
||||
* https://opensource.org/licenses/MIT.
|
||||
*/
|
||||
|
||||
package com.intellij.vim.providers
|
||||
|
||||
import com.google.devtools.ksp.processing.SymbolProcessor
|
||||
import com.google.devtools.ksp.processing.SymbolProcessorEnvironment
|
||||
import com.google.devtools.ksp.processing.SymbolProcessorProvider
|
||||
import com.intellij.vim.processors.ExCommandProcessor
|
||||
|
||||
class ExCommandProcessorProvider : SymbolProcessorProvider {
|
||||
override fun create(environment: SymbolProcessorEnvironment): SymbolProcessor {
|
||||
return ExCommandProcessor(environment)
|
||||
}
|
||||
}
|
@ -0,0 +1 @@
|
||||
com.intellij.vim.providers.ExCommandProcessorProvider
|
@ -81,6 +81,7 @@ plugins {
|
||||
ksp {
|
||||
arg("generated_directory", "$projectDir/src/main/resources")
|
||||
arg("vimscript_functions_file", "intellij_vimscript_functions.yaml")
|
||||
arg("ex_commands_file", "intellij_ex_commands.yaml")
|
||||
}
|
||||
|
||||
afterEvaluate {
|
||||
|
@ -23,6 +23,7 @@ repositories {
|
||||
ksp {
|
||||
arg("generated_directory", "$projectDir/src/main/resources")
|
||||
arg("vimscript_functions_file", "engine_vimscript_functions.yaml")
|
||||
arg("ex_commands_file", "engine_ex_commands.yaml")
|
||||
}
|
||||
|
||||
dependencies {
|
||||
|
Loading…
Reference in New Issue
Block a user