) : List
fun GenerateDtoDialogResultEnum.preview(field: RsNamedFieldDecl) : String? {
return when (this) {
GenerateDtoDialogResultEnum.UpdateRequest -> {
- if(field.myManager.isPrimaryKey){
+ if(field.namedFieldManager.isPrimaryKey){
return " #[salvo(extract(source(from = \"param\")))]"
}
return null
@@ -99,13 +96,13 @@ class GenerateDtoDialog(private val project: Project, private val psiElement: R
private val model = GenerateDtoDialogParam(
addRequestText = MyRsPsiFactory.generateDto(GenerateDtoDialogResultEnum.AddRequest, psiElement),
- addRequestName = GenerateDtoDialogResultEnum.AddRequest.getStructName(psiElement.myManager.getTableName ?: ""),
+ addRequestName = GenerateDtoDialogResultEnum.AddRequest.getStructName(psiElement.structItemManager.getTableName ?: ""),
updateRequestText = MyRsPsiFactory.generateDto(GenerateDtoDialogResultEnum.UpdateRequest,psiElement),
- updateRequestName = GenerateDtoDialogResultEnum.UpdateRequest.getStructName(psiElement.myManager.getTableName ?: ""),
+ updateRequestName = GenerateDtoDialogResultEnum.UpdateRequest.getStructName(psiElement.structItemManager.getTableName ?: ""),
responseText = MyRsPsiFactory.generateDto(GenerateDtoDialogResultEnum.Response,psiElement),
- responseName = GenerateDtoDialogResultEnum.Response.getStructName(psiElement.myManager.getTableName ?: ""),
+ responseName = GenerateDtoDialogResultEnum.Response.getStructName(psiElement.structItemManager.getTableName ?: ""),
saveTo = Tools.getDtoFolder(project)?.path ?: "",
- fileName = (psiElement.myManager.getTableName?:"root")
+ fileName = (psiElement.structItemManager.getTableName?:"root")
)
private val tabView = JBTabbedPane()
diff --git a/src/main/kotlin/shop/itbug/salvorstool/dialog/GenerateRouterDialog.kt b/src/main/kotlin/shop/itbug/salvorstool/dialog/GenerateRouterDialog.kt
index 4e1a0d9..c7e57c5 100644
--- a/src/main/kotlin/shop/itbug/salvorstool/dialog/GenerateRouterDialog.kt
+++ b/src/main/kotlin/shop/itbug/salvorstool/dialog/GenerateRouterDialog.kt
@@ -13,6 +13,7 @@ import shop.itbug.salvorstool.i18n.MyI18n
import shop.itbug.salvorstool.tool.MyRsPsiFactory
import shop.itbug.salvorstool.tool.Tools
import shop.itbug.salvorstool.tool.myManager
+import shop.itbug.salvorstool.tool.structItemManager
import shop.itbug.salvorstool.widget.RsEditor
import java.awt.Dimension
import javax.swing.JComponent
@@ -30,7 +31,7 @@ class GenerateRouterDialog(private val project: Project, psiElement: RsStructIte
private val model = GenerateRouterDialogModel(
text = MyRsPsiFactory.generateRouterFile(psiElement),
saveTo = Tools.getRouterFolder(project)?.path ?: "",
- fileName = (psiElement.myManager.getTableName ?: "root")
+ fileName = (psiElement.structItemManager.getTableName ?: "root")
)
init {
diff --git a/src/main/kotlin/shop/itbug/salvorstool/dialog/GenerateServiceDialog.kt b/src/main/kotlin/shop/itbug/salvorstool/dialog/GenerateServiceDialog.kt
index 97ae5d5..e06e077 100644
--- a/src/main/kotlin/shop/itbug/salvorstool/dialog/GenerateServiceDialog.kt
+++ b/src/main/kotlin/shop/itbug/salvorstool/dialog/GenerateServiceDialog.kt
@@ -14,6 +14,7 @@ import shop.itbug.salvorstool.i18n.MyI18n
import shop.itbug.salvorstool.tool.MyRsPsiFactory
import shop.itbug.salvorstool.tool.Tools
import shop.itbug.salvorstool.tool.myManager
+import shop.itbug.salvorstool.tool.structItemManager
import shop.itbug.salvorstool.widget.RsEditor
import java.awt.Dimension
import javax.swing.JComponent
@@ -57,7 +58,7 @@ class GenerateServiceDialog(private val project: Project, private val psiElement
deleteText = MyRsPsiFactory.generateServiceByDelete(psiElement),
findAllText = MyRsPsiFactory.generateServiceByAll(psiElement),
saveTo = Tools.getServiceFolder(project)?.path ?: "",
- fileName = (psiElement.myManager.getTableName?:"root")
+ fileName = (psiElement.structItemManager.getTableName?:"root")
)
init {
diff --git a/src/main/kotlin/shop/itbug/salvorstool/intention/CopyAntdTableColumnAction.kt b/src/main/kotlin/shop/itbug/salvorstool/intention/CopyAntdTableColumnAction.kt
index b1305ab..3771f08 100644
--- a/src/main/kotlin/shop/itbug/salvorstool/intention/CopyAntdTableColumnAction.kt
+++ b/src/main/kotlin/shop/itbug/salvorstool/intention/CopyAntdTableColumnAction.kt
@@ -10,11 +10,14 @@ import com.intellij.psi.PsiFile
import org.rust.lang.core.psi.impl.RsStructItemImpl
import shop.itbug.salvorstool.tool.copy
import shop.itbug.salvorstool.tool.myManager
+import shop.itbug.salvorstool.tool.structItemManager
+
+///
class CopyAntdTableColumnAction : PsiElementBaseIntentionAction(), IntentionAction {
override fun getFamilyName(): String {
- return "SalvoRsTool: Copy Antd Table Column"
+ return "RustX: Copy Antd Table Column"
}
override fun getText(): String {
@@ -27,13 +30,13 @@ class CopyAntdTableColumnAction : PsiElementBaseIntentionAction(), IntentionActi
override fun invoke(project: Project, editor: Editor?, element: PsiElement) {
val rs = element.parent as? RsStructItemImpl ?: return
- rs.myManager.getAntdTableColumnDefine.copy()
+ rs.structItemManager.getAntdTableColumnDefine.copy()
}
override fun generatePreview(project: Project, editor: Editor, file: PsiFile): IntentionPreviewInfo {
val rsPsi = getElement(editor, file)?.parent as? RsStructItemImpl
rsPsi?.let {
- return IntentionPreviewInfo.Html("""${rsPsi.myManager.getAntdTableColumnDefine}
""".trimIndent())
+ return IntentionPreviewInfo.Html("""${rsPsi.structItemManager.getAntdTableColumnDefine}
""".trimIndent())
}
return IntentionPreviewInfo.EMPTY
}
diff --git a/src/main/kotlin/shop/itbug/salvorstool/intention/CopyTSInterfaceAction.kt b/src/main/kotlin/shop/itbug/salvorstool/intention/CopyTSInterfaceAction.kt
index 561730c..60b7bbe 100644
--- a/src/main/kotlin/shop/itbug/salvorstool/intention/CopyTSInterfaceAction.kt
+++ b/src/main/kotlin/shop/itbug/salvorstool/intention/CopyTSInterfaceAction.kt
@@ -9,11 +9,12 @@ import com.intellij.psi.PsiElement
import com.intellij.psi.PsiFile
import org.rust.lang.core.psi.impl.RsStructItemImpl
import shop.itbug.salvorstool.tool.copy
-import shop.itbug.salvorstool.tool.myManager
+import shop.itbug.salvorstool.tool.structItemManager
+///
class CopyTSInterfaceAction: PsiElementBaseIntentionAction(),IntentionAction {
override fun getFamilyName(): String {
- return "SalvoRsTool: Copy TS interface"
+ return "RustX: Copy TS interface"
}
override fun getText(): String {
@@ -23,16 +24,17 @@ class CopyTSInterfaceAction: PsiElementBaseIntentionAction(),IntentionAction {
override fun isAvailable(project: Project, editor: Editor?, element: PsiElement): Boolean {
return element.parent is RsStructItemImpl
}
+
override fun invoke(project: Project, editor: Editor?, element: PsiElement) {
val rs = element.parent as? RsStructItemImpl ?: return
- rs.myManager.getTSInterface.copy()
+ rs.structItemManager.getTSInterface.copy()
}
override fun generatePreview(project: Project, editor: Editor, file: PsiFile): IntentionPreviewInfo {
var preview = IntentionPreviewInfo.Html("")
val psiElement = getElement(editor,file)?.parent as? RsStructItemImpl
psiElement?.let {
- preview = IntentionPreviewInfo.Html("${it.myManager.getTSInterface}
")
+ preview = IntentionPreviewInfo.Html("${it.structItemManager.getTSInterface}
")
}
return preview
}
diff --git a/src/main/kotlin/shop/itbug/salvorstool/model/SalvoApiItem.kt b/src/main/kotlin/shop/itbug/salvorstool/model/SalvoApiItem.kt
index 07f7a53..98c3663 100644
--- a/src/main/kotlin/shop/itbug/salvorstool/model/SalvoApiItem.kt
+++ b/src/main/kotlin/shop/itbug/salvorstool/model/SalvoApiItem.kt
@@ -1,11 +1,7 @@
package shop.itbug.salvorstool.model
-import com.intellij.openapi.application.ApplicationManager
-import com.intellij.openapi.fileEditor.FileEditorManager
-import com.intellij.openapi.project.Project
-import com.intellij.pom.Navigatable
-import com.intellij.psi.search.searches.ReferencesSearch
import org.rust.lang.core.psi.RsMethodCall
+import org.rust.lang.core.psi.impl.RsPathImpl
import shop.itbug.salvorstool.tool.*
import java.util.*
@@ -15,9 +11,13 @@ enum class SalvoApiItemMethod {
Post,
Update,
Delete,
- Put
+ Put,
+ Patch,
+ Unknown
}
+data class SalvoApiItemFunction(val method: SalvoApiItemMethod,val element: RsMethodCall)
+
data class SalvoApiItem(val api: String,val method: SalvoApiItemMethod,val rsMethodPsiElement: RsMethodCall){
override fun toString(): String {
return "\n${api} - $method"
@@ -89,14 +89,16 @@ data class SalvoApiItem(val api: String,val method: SalvoApiItemMethod,val rsMet
/**
* 跳到代码位置
*/
- fun navTo(project: Project) {
- val navigationElement = rsMethodPsiElement.navigationElement
- ApplicationManager.getApplication().invokeLater {
- if (navigationElement != null && navigationElement is Navigatable && (navigationElement as Navigatable).canNavigate()) {
- (navigationElement as Navigatable).navigate(true)
- }else{
- FileEditorManager.getInstance(project).openFile(rsMethodPsiElement.containingFile.virtualFile)
- }
- }
+ fun navTo() {
+ rsMethodPsiElement.tryNavTo()
+ }
+
+ /**
+ * 跳转到service实现
+ */
+ fun navToRouterImpl(){
+ rsMethodPsiElement.findFirstChild()?.let { rxPath ->
+ rxPath.reference?.resolve()?.tryNavTo()
+ }
}
}
diff --git a/src/main/kotlin/shop/itbug/salvorstool/searcheverywhere/SalvoSearchApi.kt b/src/main/kotlin/shop/itbug/salvorstool/searcheverywhere/SalvoSearchApi.kt
index 3e0ae6b..7cc28fb 100644
--- a/src/main/kotlin/shop/itbug/salvorstool/searcheverywhere/SalvoSearchApi.kt
+++ b/src/main/kotlin/shop/itbug/salvorstool/searcheverywhere/SalvoSearchApi.kt
@@ -51,7 +51,7 @@ class SalvoSearchApi : SearchEverywhereContributorFactory {
}
override fun processSelectedItem(selected: SalvoApiItem, modifiers: Int, searchText: String): Boolean {
- selected.navTo(project)
+ selected.navTo()
return true
}
diff --git a/src/main/kotlin/shop/itbug/salvorstool/service/RustProjectService.kt b/src/main/kotlin/shop/itbug/salvorstool/service/RustProjectService.kt
new file mode 100644
index 0000000..64a1833
--- /dev/null
+++ b/src/main/kotlin/shop/itbug/salvorstool/service/RustProjectService.kt
@@ -0,0 +1,31 @@
+package shop.itbug.salvorstool.service
+
+import com.intellij.openapi.components.Service
+import com.intellij.openapi.project.Project
+import com.intellij.openapi.vfs.LocalFileSystem
+import com.intellij.openapi.vfs.VirtualFile
+import com.intellij.psi.PsiManager
+import org.toml.lang.psi.TomlFile
+import org.toml.lang.psi.TomlKeyValue
+import shop.itbug.salvorstool.tool.filterByType
+import java.io.File
+
+@Service(Service.Level.PROJECT)
+class RustProjectService (val project: Project){
+
+
+ /**
+ * 是否使用了salvo的依赖
+ */
+ fun hasSalvoDependencies() : Boolean {
+ val tomlFilePath = project.basePath + File.separator + "Cargo.toml"
+ val tomlFile: VirtualFile = LocalFileSystem.getInstance().findFileByPath(tomlFilePath) ?: return false
+ val file = PsiManager.getInstance(project).findFile(tomlFile) as? TomlFile ?: return false
+ val keyValues = file.filterByType()
+ return keyValues.any { it.key.text == "salvo" }
+ }
+
+ companion object {
+ fun getInstance(project: Project): RustProjectService = project.getService(RustProjectService::class.java)
+ }
+}
\ No newline at end of file
diff --git a/src/main/kotlin/shop/itbug/salvorstool/service/SalvoApiService.kt b/src/main/kotlin/shop/itbug/salvorstool/service/SalvoApiService.kt
index f080799..cfc49c5 100644
--- a/src/main/kotlin/shop/itbug/salvorstool/service/SalvoApiService.kt
+++ b/src/main/kotlin/shop/itbug/salvorstool/service/SalvoApiService.kt
@@ -19,15 +19,15 @@ import shop.itbug.salvorstool.messageing.ApiScanMessaging
import shop.itbug.salvorstool.model.SalvoApiItem
import shop.itbug.salvorstool.tool.myManager
import shop.itbug.salvorstool.tool.rsFileType
+import shop.itbug.salvorstool.tool.rsLetDeclImplManager
@Service(Service.Level.PROJECT)
class SalvoApiService(val project: Project) {
-
private var projectApiList = mutableListOf()
init {
- project.messageBus.connect().subscribe(DumbService.DUMB_MODE, object : DumbService.DumbModeListener {
+ project.messageBus.connect().subscribe(DumbService.DUMB_MODE, object : DumbService.DumbModeListener {
override fun exitDumbMode() {
startScan()
super.exitDumbMode()
@@ -35,8 +35,7 @@ class SalvoApiService(val project: Project) {
})
}
-
- fun getApiList() : List {
+ fun getApiList(): List {
return projectApiList
}
@@ -46,27 +45,30 @@ class SalvoApiService(val project: Project) {
@OptIn(DelicateCoroutinesApi::class)
private fun startScan() {
+
ApplicationManager.getApplication().invokeLater {
- GlobalScope.launch(Dispatchers.Default) {
- var files = emptyList()
- readAction {
- files = FileTypeIndex.getFiles(rsFileType, SalvoSearchGlobal(project)).toList()
- }
- val tasks = files.map { file ->
- GlobalScope.async {
- findRouterRsFunction(file)
+ val hasSalvoDeps = RustProjectService.getInstance(project).hasSalvoDependencies()
+ if (hasSalvoDeps) {
+ GlobalScope.launch(Dispatchers.Default) {
+ var files = emptyList()
+ readAction {
+ files = FileTypeIndex.getFiles(rsFileType, SalvoSearchGlobal(project)).toList()
}
- }
- val result = tasks.awaitAll().flatten()
- val apis = mutableListOf()
- result.forEach { r ->
- ApplicationManager.getApplication().runReadAction {
- val api = r.myManager.allLet.map { let -> let.myManager.apiList }
- apis.addAll(api.flatten())
+ val tasks = files.map { file ->
+ GlobalScope.async {
+ findRouterRsFunction(file)
+ }
+ }
+ val result = tasks.awaitAll().flatten()
+ val apis = mutableListOf()
+ result.forEach { r: RsFunctionImpl ->
+ ApplicationManager.getApplication().runReadAction {
+ r.myManager.allLet.map { let -> apis.addAll(let.rsLetDeclImplManager.allApi) }
+ }
}
+ projectApiList = apis
+ project.messageBus.syncPublisher(ApiScanMessaging.TOPIC).apiScanEed(apis)
}
- projectApiList = apis
- project.messageBus.syncPublisher(ApiScanMessaging.TOPIC).apiScanEed(apis)
}
}
@@ -81,6 +83,7 @@ class SalvoApiService(val project: Project) {
return@readAction find
}
}
+
companion object {
fun getInstance(project: Project): SalvoApiService {
diff --git a/src/main/kotlin/shop/itbug/salvorstool/tool/AntdFactory.kt b/src/main/kotlin/shop/itbug/salvorstool/tool/AntdFactory.kt
index 0eb27ff..833b254 100644
--- a/src/main/kotlin/shop/itbug/salvorstool/tool/AntdFactory.kt
+++ b/src/main/kotlin/shop/itbug/salvorstool/tool/AntdFactory.kt
@@ -19,7 +19,7 @@ object AntdFactory {
///生成form
fun generateAntdForm(psiElement: RsStructItemImpl): String {
val sb = StringBuilder()
- val manager = psiElement.myManager
+ val manager = psiElement.structItemManager
val jsModels = manager.jsModelList
//1.添加参数
@@ -49,7 +49,7 @@ object AntdFactory {
}
///生成form item
- fun generateFormItem(model: MyFieldPsiElementManager.JsModel): String {
+ private fun generateFormItem(model: MyFieldPsiElementManager.JsModel): String {
val type = when (model.type) {
JavascriptType.Number -> "ProFormDigit"
JavascriptType.String -> "ProFormText"
diff --git a/src/main/kotlin/shop/itbug/salvorstool/tool/ExtendedFuntions.kt b/src/main/kotlin/shop/itbug/salvorstool/tool/ExtendedFuntions.kt
index cad8326..eae2eff 100644
--- a/src/main/kotlin/shop/itbug/salvorstool/tool/ExtendedFuntions.kt
+++ b/src/main/kotlin/shop/itbug/salvorstool/tool/ExtendedFuntions.kt
@@ -3,10 +3,19 @@ package shop.itbug.salvorstool.tool
import com.google.common.base.CaseFormat
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.actionSystem.CommonDataKeys
+import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.diagnostic.Logger
+import com.intellij.openapi.fileEditor.FileEditorManager
import com.intellij.openapi.fileTypes.FileTypeManager
import com.intellij.openapi.ide.CopyPasteManager
+import com.intellij.pom.Navigatable
import com.intellij.psi.PsiElement
+import com.intellij.psi.PsiFile
+import com.intellij.psi.PsiReference
+import com.intellij.psi.impl.source.tree.LeafPsiElement
+import com.intellij.psi.search.LocalSearchScope
+import com.intellij.psi.search.searches.ReferencesSearch
+import com.intellij.psi.util.PsiTreeUtil
import org.rust.lang.core.psi.RsNamedFieldDecl
import org.rust.lang.core.psi.RsOuterAttr
import org.rust.lang.core.psi.impl.RsStructItemImpl
@@ -17,11 +26,9 @@ import javax.swing.JPanel
import javax.swing.JScrollPane
val rsFileType = FileTypeManager.getInstance().getFileTypeByExtension("rs")
-val PsiElement.myManager get() = MyRsPsiElementManager(this)
-val RsStructItemImpl.myManager get() = MyRsStructManager(this)
-val RsNamedFieldDecl.myManager get() = MyFieldPsiElementManager(this)
-val RsOuterAttr.myManager get() = MyRsOuterAttrPsiElementManager(this)
-fun T.logger() = Logger.getInstance(this::class.java)
+val RsStructItemImpl.structItemManager get() = MyRsStructManager(this)
+val RsNamedFieldDecl.namedFieldManager get() = MyFieldPsiElementManager(this)
+val RsOuterAttr.outerAttrManager get() = MyRsOuterAttrPsiElementManager(this)
val JScrollPane.removeBorder get() = this.apply { this.border = BorderFactory.createEmptyBorder(0, 0, 0, 0) }
val JPanel.padding get() = this.apply { this.border = BorderFactory.createEmptyBorder(12, 12, 12, 12) }
val JPanel.vertical get() = this.apply { this.border = BorderFactory.createEmptyBorder(12, 0, 12, 0) }
@@ -53,14 +60,69 @@ fun firstCharToLowercase(input: String): String {
}
}
+///尝试获取Rs struct 模型
fun AnActionEvent.tryGetRsStructPsiElement(): RsStructItemImpl? {
val psiElement = this.getData(CommonDataKeys.PSI_ELEMENT)
- if (psiElement != null && psiElement.myManager.isStruct) {
- return psiElement as? RsStructItemImpl
+ if(psiElement is RsStructItemImpl){
+ return psiElement
}
- return null
+ val firstParent = PsiTreeUtil.findFirstParent(psiElement){it is RsStructItemImpl}
+ return firstParent as? RsStructItemImpl
}
fun String.copy() {
CopyPasteManager.getInstance().setContents(StringSelection(this))
+}
+
+inline fun PsiElement.filterByType(): List {
+ return PsiTreeUtil.findChildrenOfAnyType(this, T::class.java).toList()
+}
+
+inline fun PsiElement.findByTypeAndText(text: String): T? {
+ return filterByType().find { it.text == text }
+}
+
+/**
+ * 递归查找符合[T]类型的第一个元素
+ */
+inline fun PsiElement.findFirstChild(): T? {
+ try {
+ return PsiTreeUtil.findChildOfType(this, T::class.java)
+ } catch (e: Exception) {
+ return null
+ }
+}
+
+fun PsiElement.findLastLeafChild(): PsiElement? {
+ return filterByType().lastOrNull()
+}
+
+
+/**
+ * 查找第一个匹配的[T]父元素
+ */
+inline fun PsiElement.findFirstParentChild(): PsiElement? {
+ return PsiTreeUtil.findFirstParent(this){
+ return@findFirstParent it is T
+ }
+}
+
+/**
+ * 查找[element]在文件中的引用列表
+ */
+fun PsiFile.getUseAge(element: PsiElement) : List {
+ return ReferencesSearch.search(element, LocalSearchScope(this)).findAll().toList()
+}
+
+/**
+ * 尝试跳转到代码为止
+ */
+fun PsiElement.tryNavTo() {
+ ApplicationManager.getApplication().invokeLater {
+ if (navigationElement != null && navigationElement is Navigatable && (navigationElement as Navigatable).canNavigate()) {
+ (navigationElement as Navigatable).navigate(true)
+ }else{
+ FileEditorManager.getInstance(project).openFile(this.containingFile.virtualFile)
+ }
+ }
}
\ No newline at end of file
diff --git a/src/main/kotlin/shop/itbug/salvorstool/tool/MyRsPsiElementManager.kt b/src/main/kotlin/shop/itbug/salvorstool/tool/MyRsPsiElementManager.kt
index e0e99b4..f9bdc77 100644
--- a/src/main/kotlin/shop/itbug/salvorstool/tool/MyRsPsiElementManager.kt
+++ b/src/main/kotlin/shop/itbug/salvorstool/tool/MyRsPsiElementManager.kt
@@ -27,10 +27,6 @@ enum class JavascriptType {
Number, String, Bool, Unknown
}
-/// psi操作管理
-class MyRsPsiElementManager(context: PsiElement) {
- val isStruct = context is RsStructItemImpl
-}
/// struct操作管理
class MyRsStructManager(private val psiElement: RsStructItemImpl) {
@@ -47,18 +43,18 @@ class MyRsStructManager(private val psiElement: RsStructItemImpl) {
///获取表名
val getTableName: String?
get() {
- val outerAttr = psiElement.outerAttrList.find { it.myManager.getSeaOrmTabName != null }
+ val outerAttr = psiElement.outerAttrList.find { it.outerAttrManager.getSeaOrmTabName != null }
?: return null
- val tabName = outerAttr.myManager.getSeaOrmTabName
+ val tabName = outerAttr.outerAttrManager.getSeaOrmTabName
return tabName
}
///主键字段
- val primaryField = fieldList.find { it.myManager.isPrimaryKey }
+ val primaryField = fieldList.find { it.namedFieldManager.isPrimaryKey }
///js 模型列表
val jsModelList: List =
- fieldList.mapNotNull { it.myManager.getJsModel }
+ fieldList.mapNotNull { it.namedFieldManager.getJsModel }
///获取ts模型
val getTSInterface: String get() {
@@ -193,7 +189,7 @@ class MyFieldPsiElementManager(private val psiElement: RsNamedFieldDecl) {
///查找meta,比较精确的查找
private fun hasMetaItem(name: String, filter: (item: RsMetaItem) -> Boolean): Boolean {
- val find = psiElement.outerAttrList.find { it.myManager.isMeta(name) } ?: return false
+ val find = psiElement.outerAttrList.find { it.outerAttrManager.isMeta(name) } ?: return false
val args = find.metaItem.metaItemArgs
args?.metaItemList?.forEach { meta ->
run {
diff --git a/src/main/kotlin/shop/itbug/salvorstool/tool/MyRsPsiFactory.kt b/src/main/kotlin/shop/itbug/salvorstool/tool/MyRsPsiFactory.kt
index 669ae4d..501a6b8 100644
--- a/src/main/kotlin/shop/itbug/salvorstool/tool/MyRsPsiFactory.kt
+++ b/src/main/kotlin/shop/itbug/salvorstool/tool/MyRsPsiFactory.kt
@@ -11,22 +11,22 @@ object MyRsPsiFactory {
///生成对象
fun generateDto(type: GenerateDtoDialogResultEnum, psiElement: RsStructItemImpl): String {
- psiElement.myManager.structName ?: throw MyRsPsiFactoryError("获取名称失败")
- val tabName = psiElement.myManager.getTableName ?: throw MyRsPsiFactoryError("获取表明失败")
+ psiElement.structItemManager.structName ?: throw MyRsPsiFactoryError("获取名称失败")
+ val tabName = psiElement.structItemManager.getTableName ?: throw MyRsPsiFactoryError("获取表明失败")
val generateStructName = type.getStructName(tabName)
val outer = type.getOuterAttr()
///组装
val sb = StringBuilder()
sb.appendLine(outer)
sb.appendLine("pub struct $generateStructName {")
- var fields = psiElement.myManager.fieldList
+ var fields = psiElement.structItemManager.fieldList
fields = type.getFields(fields)
fields.forEach { field ->
val pre = type.preview(field)
if (pre != null) {
sb.appendLine(pre)
}
- sb.appendLine(" " + field.myManager.getSimpleText + if (field == fields.lastOrNull()) "" else ",")
+ sb.appendLine(" " + field.namedFieldManager.getSimpleText + if (field == fields.lastOrNull()) "" else ",")
}
sb.appendLine("}")
return sb.toString()
@@ -40,17 +40,17 @@ object MyRsPsiFactory {
fun generateServiceWithAdd(psiElement: RsStructItemImpl): String {
val type = GenerateDtoDialogResultEnum.AddRequest
val typeResponse = GenerateDtoDialogResultEnum.Response
- val tabName = psiElement.myManager.getTableName ?: throw MyRsPsiFactoryError("获取表名失败")
+ val tabName = psiElement.structItemManager.getTableName ?: throw MyRsPsiFactoryError("获取表名失败")
val structName = type.getStructName(tabName)
val responseName = typeResponse.getStructName(tabName)
///生成字段
val sb = StringBuilder()
- val fs = psiElement.myManager.fieldList
+ val fs = psiElement.structItemManager.fieldList
fs.forEach { field ->
run {
- val manager = field.myManager
+ val manager = field.namedFieldManager
if (manager.isPrimaryKey) {
sb.appendLine("\t\t\t${manager.name}: NotSet,")
} else {
@@ -65,15 +65,15 @@ object MyRsPsiFactory {
}
///获取主键字段
- val primaryField = psiElement.myManager.fieldList.find { it.myManager.isPrimaryKey }
+ val primaryField = psiElement.structItemManager.fieldList.find { it.namedFieldManager.isPrimaryKey }
?: throw MyRsPsiFactoryError("获取主键字段失败")
///获取除主键以外的其他字段
- val fields = psiElement.myManager.fieldList.filter { !it.myManager.isPrimaryKey }
+ val fields = psiElement.structItemManager.fieldList.filter { !it.namedFieldManager.isPrimaryKey }
val fsb = StringBuilder()
fields.forEach { field -> run {
- val m = field.myManager
+ val m = field.namedFieldManager
if(fields.lastOrNull() == field){
fsb.append("\t\t${m.name}: req.${m.name}")
}else{
@@ -94,7 +94,7 @@ $sb
};
let result = ${tabName.underlineToCamel.capitalizeFirstLetter()}::insert(model).exec(db).await?;
Ok($responseName {
- ${primaryField.myManager.name}: result.last_insert_id,
+ ${primaryField.namedFieldManager.name}: result.last_insert_id,
$fsb
})
}""".trimIndent()
@@ -107,27 +107,27 @@ $fsb
fun generateServiceByUpdate(psiElement: RsStructItemImpl): String {
val type = GenerateDtoDialogResultEnum.UpdateRequest
val typeResponse = GenerateDtoDialogResultEnum.Response
- val tabName = psiElement.myManager.getTableName ?: throw MyRsPsiFactoryError("获取表名失败")
+ val tabName = psiElement.structItemManager.getTableName ?: throw MyRsPsiFactoryError("获取表名失败")
val structName = type.getStructName(tabName)
val responseName = typeResponse.getStructName(tabName)
///获取主键字段
- val primaryField = psiElement.myManager.fieldList.find { it.myManager.isPrimaryKey }
+ val primaryField = psiElement.structItemManager.fieldList.find { it.namedFieldManager.isPrimaryKey }
?: throw MyRsPsiFactoryError("获取主键字段失败")
- val fields = psiElement.myManager.fieldList.filter { !it.myManager.isPrimaryKey }
+ val fields = psiElement.structItemManager.fieldList.filter { !it.namedFieldManager.isPrimaryKey }
val sb = StringBuilder()
fields.forEach {
- val m = it.myManager
+ val m = it.namedFieldManager
sb.appendLine("\tmodel.${m.name} = Set(req.${it.name});")
}
- val responseFields = typeResponse.getFields(psiElement.myManager.fieldList)
+ val responseFields = typeResponse.getFields(psiElement.structItemManager.fieldList)
val fsb = StringBuilder()
responseFields.forEach {
- val f = it.myManager.name
+ val f = it.namedFieldManager.name
fsb.appendLine("\t\t$f: result.${f},")
}
@@ -138,7 +138,7 @@ pub async fn update_$tabName(req: $structName) -> AppResult<$responseName> {
.get()
.ok_or(anyhow::anyhow!("Database connection failed."))?;
- let find = ${tabName.underlineToCamel.capitalizeFirstLetter()}::find_by_id(req.${primaryField.myManager.name}).one(db).await?;
+ let find = ${tabName.underlineToCamel.capitalizeFirstLetter()}::find_by_id(req.${primaryField.namedFieldManager.name}).one(db).await?;
if find.is_none() {
return Err(anyhow::anyhow!("${tabName.underlineToCamel.capitalizeFirstLetter()} does not exist.").into());
}
@@ -161,15 +161,15 @@ $fsb
*/
fun generateServiceByDelete(psiElement: RsStructItemImpl): String {
- val primaryField = psiElement.myManager.fieldList.find { it.myManager.isPrimaryKey }
+ val primaryField = psiElement.structItemManager.fieldList.find { it.namedFieldManager.isPrimaryKey }
?: throw MyRsPsiFactoryError("获取主键字段失败")
- val tabName = psiElement.myManager.getTableName ?: throw MyRsPsiFactoryError("获取表名失败")
+ val tabName = psiElement.structItemManager.getTableName ?: throw MyRsPsiFactoryError("获取表名失败")
val text = """
- pub async fn delete_$tabName(${primaryField.myManager.name}: ${primaryField.myManager.typeString}) -> AppResult<()> {
+ pub async fn delete_$tabName(${primaryField.namedFieldManager.name}: ${primaryField.namedFieldManager.typeString}) -> AppResult<()> {
let db = DB
.get()
.ok_or(anyhow::anyhow!("Database connection failed."))?;
- ${tabName.underlineToCamel.capitalizeFirstLetter()}::delete_by_id(${primaryField.myManager.name}).exec(db).await?;
+ ${tabName.underlineToCamel.capitalizeFirstLetter()}::delete_by_id(${primaryField.namedFieldManager.name}).exec(db).await?;
Ok(())
}
""".trimIndent()
@@ -181,13 +181,13 @@ $fsb
* 获取列表
*/
fun generateServiceByAll(psiElement: RsStructItemImpl): String {
- val tabName = psiElement.myManager.getTableName ?: throw MyRsPsiFactoryError("获取表名失败")
+ val tabName = psiElement.structItemManager.getTableName ?: throw MyRsPsiFactoryError("获取表名失败")
val typeResponse = GenerateDtoDialogResultEnum.Response
val typeStructName = typeResponse.getStructName(tabName)
- val responseFields = typeResponse.getFields(psiElement.myManager.fieldList)
+ val responseFields = typeResponse.getFields(psiElement.structItemManager.fieldList)
val fsb = StringBuilder()
responseFields.forEach {
- val f = it.myManager.name
+ val f = it.namedFieldManager.name
fsb.appendLine("\t\t\t$f: r.${f},")
}
val text = """
@@ -213,11 +213,11 @@ $fsb
* 获取路由
*/
fun generateRouterFile(psiElement: RsStructItemImpl): String {
- val tabName = psiElement.myManager.getTableName ?: throw MyRsPsiFactoryError("获取表名失败")
+ val tabName = psiElement.structItemManager.getTableName ?: throw MyRsPsiFactoryError("获取表名失败")
val addReq = GenerateDtoDialogResultEnum.AddRequest.getStructName(tabName)
val response = GenerateDtoDialogResultEnum.Response.getStructName(tabName)
val updateReq = GenerateDtoDialogResultEnum.UpdateRequest.getStructName(tabName)
- val primaryField = psiElement.myManager.primaryField ?: throw MyRsPsiFactoryError("获取主键失败")
+ val primaryField = psiElement.structItemManager.primaryField ?: throw MyRsPsiFactoryError("获取主键失败")
val text = """
use crate::{
app_writer::{AppResult, AppWriter},
@@ -231,7 +231,7 @@ $fsb
Request,
};
- //Router::with_path("/api/$tabName").get(get_${tabName}_all).post(post_add_$tabName).push(Router::with_path("<${primaryField.myManager.name}>").put(put_update_$tabName).delete(delete_$tabName))
+ //Router::with_path("/api/$tabName").get(get_${tabName}_all).post(post_add_$tabName).push(Router::with_path("<${primaryField.namedFieldManager.name}>").put(put_update_$tabName).delete(delete_$tabName))
#[endpoint(tags("$tabName"))]
pub async fn post_add_$tabName(new_$tabName: JsonBody<$addReq>) -> AppWriter<$response> {
@@ -247,8 +247,8 @@ $fsb
}
#[endpoint(tags("$tabName"))]
- pub async fn delete_$tabName(${primaryField.myManager.name}: PathParam<${primaryField.myManager.typeString}>) -> AppWriter<()> {
- let result = $tabName::delete_$tabName(${primaryField.myManager.name}.0).await;
+ pub async fn delete_$tabName(${primaryField.namedFieldManager.name}: PathParam<${primaryField.namedFieldManager.typeString}>) -> AppWriter<()> {
+ let result = $tabName::delete_$tabName(${primaryField.namedFieldManager.name}.0).await;
AppWriter(result)
}
diff --git a/src/main/kotlin/shop/itbug/salvorstool/tool/RsDotExprManager.kt b/src/main/kotlin/shop/itbug/salvorstool/tool/RsDotExprManager.kt
index 9cff52d..21f99d0 100644
--- a/src/main/kotlin/shop/itbug/salvorstool/tool/RsDotExprManager.kt
+++ b/src/main/kotlin/shop/itbug/salvorstool/tool/RsDotExprManager.kt
@@ -1,78 +1,3 @@
package shop.itbug.salvorstool.tool
-import com.intellij.psi.PsiElement
-import com.intellij.psi.util.PsiTreeUtil
-import com.intellij.util.containers.toMutableSmartList
-import org.rust.lang.core.psi.RsDotExpr
-import org.rust.lang.core.psi.ext.stringValue
-import org.rust.lang.core.psi.impl.RsCallExprImpl
-import org.rust.lang.core.psi.impl.RsDotExprImpl
-import org.rust.lang.core.psi.impl.RsLitExprImpl
-import org.rust.lang.core.psi.impl.RsMethodCallImpl
-import org.rust.lang.core.psi.impl.RsPathExprImpl
-import shop.itbug.salvorstool.model.SalvoApiItem
-import shop.itbug.salvorstool.model.SalvoApiItemMethod
-
-val RsDotExprImpl.myManager: DotExprManager get() = DotExprManager(this)
-
-//表达式
-class DotExprManager(private val dotExpr: RsDotExprImpl) {
-
- ///常见函数
- private val salvoMethod: SalvoApiItemMethod? get() {
- return dotExpr.methodCall?.methodManager?.myApiMethod
- }
-
- private val isPushDot: Boolean
- get() {
- return dotExpr.methodCall?.identifier?.text == "push"
- }
-
- //是否为路由请求path
- val isRouterWith: Boolean
- get() {
- val call = rsCallExpr ?: return false
- return PsiTreeUtil.findChildOfType(call, RsPathExprImpl::class.java)?.text == "Router::with_path"
- }
-
- //获取api
- val startApi: String?
- get() {
- if (isRouterWith.not()) return null
- if (rsCallExpr == null) return null
- val arg = rsCallExpr!!.valueArgumentList
- val lit = PsiTreeUtil.findChildOfType(arg, RsLitExprImpl::class.java) ?: return null
- return lit.stringValue
- }
-
- private val rsCallExpr: RsCallExprImpl?
- get() {
- return PsiTreeUtil.findChildOfType(getFinalDotExpr, RsCallExprImpl::class.java)
- }
-
- private val getFinalDotExpr: RsDotExprImpl
- get() {
- val find = PsiTreeUtil.findChildOfType(dotExpr, RsDotExprImpl::class.java)
- return find ?: dotExpr
- }
-
- private val getPushDotExpr: RsDotExprImpl?
- get() {
- val arg = dotExpr.methodCall?.valueArgumentList ?: return null
- return PsiTreeUtil.findChildrenOfType(arg, RsDotExprImpl::class.java).firstOrNull()
- }
-
-
- fun getApiItemList(): List {
- return getSimpleApiItemList()
- }
-
-
- private fun getSimpleApiItemList(): List {
- val list = PsiTreeUtil.findChildrenOfType(dotExpr, RsMethodCallImpl::class.java)
- .filter { it.methodManager.myApiMethod != null }.mapNotNull { it.methodManager.getApiItem() }.toList()
- return list
- }
-
-}
diff --git a/src/main/kotlin/shop/itbug/salvorstool/tool/RsLetDeclManager.kt b/src/main/kotlin/shop/itbug/salvorstool/tool/RsLetDeclManager.kt
index 47ba381..9c57078 100644
--- a/src/main/kotlin/shop/itbug/salvorstool/tool/RsLetDeclManager.kt
+++ b/src/main/kotlin/shop/itbug/salvorstool/tool/RsLetDeclManager.kt
@@ -1,42 +1,80 @@
package shop.itbug.salvorstool.tool
+import com.intellij.openapi.project.Project
import com.intellij.psi.util.PsiTreeUtil
-import org.rust.lang.core.psi.RsCallExpr
-import org.rust.lang.core.psi.RsDotExpr
-import org.rust.lang.core.psi.ext.stringValue
-import org.rust.lang.core.psi.impl.RsCallExprImpl
-import org.rust.lang.core.psi.impl.RsDotExprImpl
-import org.rust.lang.core.psi.impl.RsLetDeclImpl
-import org.rust.lang.core.psi.impl.RsLitExprImpl
-import org.rust.lang.core.psi.impl.RsPathExprImpl
-import org.rust.lang.core.psi.impl.RsPathImpl
+import org.rust.lang.core.psi.impl.*
import shop.itbug.salvorstool.model.SalvoApiItem
-val RsLetDeclImpl.myManager get() = RsLetDeclManager(this)
+val RsLetDeclImpl.rsLetDeclImplManager get() = RsLetDeclManager(this)
+
+/**
+ * let 表达式
+ * 例子:
+ * let product_router = Router::with_path("/api/product").get(get_product_all)
+ * .post(post_add_product)
+ * .push(
+ * Router::with_path("")
+ * .put(put_update_product)
+ * .delete(delete_product),
+ * );
+ */
+
+
+data class LetModel(
+ ///表达式名称 -> product_router
+ val letName: String? = null
+)
+
-//let表达式相关操作
class RsLetDeclManager(val psi: RsLetDeclImpl) {
- //api
- val apiStartString: String?
+ val project: Project = psi.project
+ val getModel: LetModel
get() {
- val dot = firstDotExprImpl ?: return null
- return DotExprManager(dot).startApi
+ return LetModel(letName = psi.pat?.text)
}
- // first dot
- private val firstDotExprImpl: RsDotExprImpl?
- get() {
- return PsiTreeUtil.findChildrenOfAnyType(psi, RsDotExprImpl::class.java).firstOrNull() as? RsDotExprImpl
- }
+ /// 获取root ele 节点
+ private val rootMethodExpr: RsMethodCallExprImpl? get() {
+ val root = PsiTreeUtil.findChildOfType(psi, RsMethodCallExprImpl::class.java)
+ return PsiTreeUtil.findChildOfType(root, RsMethodCallExprImpl::class.java) ?: root
+ }
+
- // api list
- val apiList: List
+ ///获取所有的api列表
+ val allApi: List
get() {
- val dot = firstDotExprImpl ?: return emptyList()
- val list = dot.myManager.getApiItemList()
-// println("\n$list\n")
- return list
+ val result = mutableListOf()
+ val root = rootMethodExpr ?: return emptyList()
+ val rootManager = root.methodCallExprManager()
+ val rootApi = rootManager.rootApiPath ?: return emptyList()
+ val rootMethods = rootManager.getAllApiMethods
+ //添加root path
+ rootMethods.forEach {
+ result.add(SalvoApiItem(rootApi,it.method,it.element))
+ }
+
+ // 添加子URL
+ allPushMethodCall.forEach {
+ val manager = it.methodCallManager
+ val methods = manager.allMethods
+ methods.forEach { methodFun ->
+ val api = rootApi + "/"+ manager.withPathString
+ result.add(SalvoApiItem(api,methodFun.method,methodFun.element))
+ }
+ }
+ return result.toList()
}
+
+ ///全部带有push的节点
+ val allPushMethodCall: List get() {
+ val allPushPsiElement = PsiTreeUtil.findChildrenOfType(psi, RsMethodCallImpl::class.java).filter { it.methodCallManager.isPushMethodCall }
+ return allPushPsiElement
+ }
+
+
+
+
+
}
diff --git a/src/main/kotlin/shop/itbug/salvorstool/tool/RsMethodCallExprImplManager.kt b/src/main/kotlin/shop/itbug/salvorstool/tool/RsMethodCallExprImplManager.kt
new file mode 100644
index 0000000..0f471be
--- /dev/null
+++ b/src/main/kotlin/shop/itbug/salvorstool/tool/RsMethodCallExprImplManager.kt
@@ -0,0 +1,64 @@
+package shop.itbug.salvorstool.tool
+
+import com.intellij.psi.PsiElement
+import com.intellij.psi.util.PsiTreeUtil
+import org.rust.lang.core.psi.RsExpr
+import org.rust.lang.core.psi.impl.*
+import shop.itbug.salvorstool.model.SalvoApiItemFunction
+import shop.itbug.salvorstool.model.SalvoApiItemMethod
+
+fun RsMethodCallExprImpl.methodCallExprManager() = RsMethodCallExprImplFactory(this)
+
+ class RsMethodCallExprImplFactory(private val methodPsiElement: RsMethodCallExprImpl) {
+
+
+ ///获取接口路径
+ val rootApiPath: String?
+ get() {
+ val rec: RsCallExprImpl? = PsiTreeUtil.findChildOfType(methodPsiElement,RsCallExprImpl::class.java)
+ if (rec != null) {
+ val exCall = rec
+ if (exCall.firstChild is RsPathExprImpl && exCall.firstChild.text == "Router::with_path") {
+ var apiText = (exCall.valueArgumentList.exprList.first() as? RsLitExprImpl)?.stringLiteral?.text ?: ""
+ if (apiText.startsWith("\"")) {
+ apiText = apiText.removePrefix("\"")
+ }
+ if (apiText.endsWith("\"")) {
+ apiText = apiText.removeSuffix("\"")
+ }
+ return apiText
+ }
+ }
+ return null
+ }
+
+
+ val getAllApiMethods: List
+ get() {
+ val list = mutableListOf()
+ val children = PsiTreeUtil.findChildrenOfAnyType(methodPsiElement, RsMethodCallImpl::class.java)
+ children.forEach {
+ val manager = RsMethodCallImplFactory(it)
+ val methodType = manager.getApiType
+ list.add(SalvoApiItemFunction(methodType,it))
+ }
+ return list.filter { it.method != SalvoApiItemMethod.Unknown }
+ }
+
+
+ private class RsMethodCallImplFactory(private val methodCallPsiElement: RsMethodCallImpl) {
+ val getApiType: SalvoApiItemMethod
+ get() {
+ return when (methodCallPsiElement.identifier.text) {
+ "put" -> SalvoApiItemMethod.Put
+ "get" -> SalvoApiItemMethod.Get
+ "delete" -> SalvoApiItemMethod.Delete
+ "post" -> SalvoApiItemMethod.Post
+ "update" -> SalvoApiItemMethod.Update
+ "patch" -> SalvoApiItemMethod.Patch
+ else -> SalvoApiItemMethod.Unknown
+ }
+ }
+ }
+
+}
\ No newline at end of file
diff --git a/src/main/kotlin/shop/itbug/salvorstool/tool/RsMethodCallManager.kt b/src/main/kotlin/shop/itbug/salvorstool/tool/RsMethodCallManager.kt
index a6321ec..07458d4 100644
--- a/src/main/kotlin/shop/itbug/salvorstool/tool/RsMethodCallManager.kt
+++ b/src/main/kotlin/shop/itbug/salvorstool/tool/RsMethodCallManager.kt
@@ -1,66 +1,52 @@
package shop.itbug.salvorstool.tool
-import com.intellij.psi.PsiElement
import com.intellij.psi.util.PsiTreeUtil
import org.rust.lang.core.psi.RsMethodCall
-import org.rust.lang.core.psi.impl.RsDotExprImpl
-import org.rust.lang.core.psi.impl.RsLetDeclImpl
+import org.rust.lang.core.psi.impl.RsCallExprImpl
+import org.rust.lang.core.psi.impl.RsLitExprImpl
+import org.rust.lang.core.psi.impl.RsMethodCallExprImpl
import org.rust.lang.core.psi.impl.RsPathExprImpl
-import shop.itbug.salvorstool.model.SalvoApiItem
-import shop.itbug.salvorstool.model.SalvoApiItemMethod
-import java.util.*
+import shop.itbug.salvorstool.model.SalvoApiItemFunction
-val RsMethodCall.methodManager: RsMethodCallManager get() = RsMethodCallManager(this)
+val RsMethodCall.methodCallManager: RsMethodCallManager get() = RsMethodCallManager(this)
-/// method call
-class RsMethodCallManager(val psiElement: RsMethodCall) {
+/**
+ *
+ * push(
+ * Router::with_path("")
+ * .put(put_update_post)
+ * .delete(delete_post)
+ * .get(get_post_by_id),
+ * )
+ */
- private val myIdText: String get() = psiElement.identifier.text
- //是否有push函数
- private val hasPush: Boolean get() = dtoChild != null
+class RsMethodCallManager(val psiElement: RsMethodCall) {
- //找到dot
- private val dtoChild: RsDotExprImpl?
- get() {
- val va = psiElement.valueArgumentList
- return PsiTreeUtil.findChildOfType(va, RsDotExprImpl::class.java)
- }
+ ///返回 push
+ private val myIdText: String get() = psiElement.identifier.text
- // rsPath
- val rsPathChild: RsPathExprImpl?
- get() {
- val va = psiElement.valueArgumentList
- return PsiTreeUtil.findChildOfType(va, RsPathExprImpl::class.java)
- }
+ ///是否 .push
+ val isPushMethodCall: Boolean get() = myIdText == "push"
- // method
- val myApiMethod: SalvoApiItemMethod?
- get() {
- return SalvoApiItemMethod.entries.find { it.name.lowercase(Locale.getDefault()) == myIdText.lowercase(Locale.getDefault()) }
+ /// 返回
+ val withPathString : String get() {
+ val eles = PsiTreeUtil.findChildrenOfType(psiElement.valueArgumentList,RsCallExprImpl::class.java).filter { it.firstChild is RsPathExprImpl && it.firstChild.text == "Router::with_path" }
+ if(eles.isNotEmpty()){
+ val first = eles.first()
+ val lit = first.valueArgumentList.exprList.firstOrNull() as? RsLitExprImpl
+ return lit?.stringLiteral?.text?.replace("\"","") ?: ""
}
-
-
- // 生成item
- fun getApiItem(): SalvoApiItem? {
- val m = myApiMethod ?: return null
- val dots = getParentList(psiElement).reversed()
- val finalUrl = dots.map { it.myManager.startApi }.joinToString("/")
- return SalvoApiItem(finalUrl, m,psiElement)
+ return ""
}
-}
-private fun getParentList(element: RsMethodCall): List {
- val parentList = mutableListOf()
- var currentElement: PsiElement? = element.parent
- while (currentElement != null) {
- if (currentElement is RsDotExprImpl && currentElement.myManager.startApi != null && currentElement.myManager.isRouterWith && parentList.find { it.myManager.startApi == (currentElement as RsDotExprImpl).myManager.startApi } == null) {
- parentList.add(currentElement)
- }
- currentElement = currentElement.parent
- if (currentElement is RsLetDeclImpl) {
- break
+ /// 获取全部的get,post....
+ val allMethods : List get() {
+ val expr: RsMethodCallExprImpl? = psiElement.valueArgumentList.exprList.firstOrNull() as? RsMethodCallExprImpl
+ if(expr != null){
+ return expr.methodCallExprManager().getAllApiMethods
}
+ return emptyList()
}
- return parentList
-}
\ No newline at end of file
+
+}
diff --git a/src/main/kotlin/shop/itbug/salvorstool/tool/Tools.kt b/src/main/kotlin/shop/itbug/salvorstool/tool/Tools.kt
index d25f03d..01c577b 100644
--- a/src/main/kotlin/shop/itbug/salvorstool/tool/Tools.kt
+++ b/src/main/kotlin/shop/itbug/salvorstool/tool/Tools.kt
@@ -78,7 +78,7 @@ object Tools {
}
fun getServiceImportPackages(psiElement: RsStructItemImpl) : String {
- val tabName = psiElement.myManager.getTableName ?: throw MyRsPsiFactoryError("获取表名失败")
+ val tabName = psiElement.structItemManager.getTableName ?: throw MyRsPsiFactoryError("获取表名失败")
return """
use crate::{
app_writer::AppResult,
diff --git a/src/main/kotlin/shop/itbug/salvorstool/window/ApiScanWindow.kt b/src/main/kotlin/shop/itbug/salvorstool/window/ApiScanWindow.kt
index d9cd5a8..221d787 100644
--- a/src/main/kotlin/shop/itbug/salvorstool/window/ApiScanWindow.kt
+++ b/src/main/kotlin/shop/itbug/salvorstool/window/ApiScanWindow.kt
@@ -85,7 +85,7 @@ class ApiScanWindow(private val myProject: Project, toolWindow: ToolWindow) : Bo
if (!it.valueIsAdjusting) {
val selectedIndex = list.selectedIndex
if (selectedIndex != -1) {
- list.selectedValue.navTo(myProject)
+ list.selectedValue.navTo()
}
}
}
diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml
index 69ab6ed..ee987c0 100644
--- a/src/main/resources/META-INF/plugin.xml
+++ b/src/main/resources/META-INF/plugin.xml
@@ -5,6 +5,7 @@
com.intellij.modules.platform
com.jetbrains.rust
JavaScriptBase
+ org.toml.lang
messages.pluginBundle
@@ -20,7 +21,7 @@
-
+
@@ -46,10 +47,18 @@
+
+
+
+
@@ -65,8 +74,9 @@
-
+ text="Sea Orm Commands" popup="true"
+ class="shop.itbug.salvorstool.action.seaorm.SeamOrmCommandActionGroup">
+
@@ -90,6 +100,5 @@
-
\ No newline at end of file
diff --git a/src/main/resources/messages/pluginBundle.properties b/src/main/resources/messages/pluginBundle.properties
index 26176c4..fe42155 100644
--- a/src/main/resources/messages/pluginBundle.properties
+++ b/src/main/resources/messages/pluginBundle.properties
@@ -26,3 +26,5 @@ valid_failed=数据验证失败
sea_orm_json_tips=输入json字符串,只支持简单的对象,不支持嵌套对象和数组
run=运行
+
+nav_to_psi=跳转到
diff --git a/src/main/resources/messages/pluginBundle_ar.properties b/src/main/resources/messages/pluginBundle_ar.properties
index 47dc19a..47cbad2 100644
--- a/src/main/resources/messages/pluginBundle_ar.properties
+++ b/src/main/resources/messages/pluginBundle_ar.properties
@@ -26,3 +26,5 @@ valid_failed=فشل التحقق من البيانات
sea_orm_json_tips=أدخل جسون سلسلة ، فقط دعم الكائنات البسيطة ، لا تدعم الكائنات المتداخلة والمصفوفات
run=تشغيل .
+
+nav_to_psi=القفز
diff --git a/src/main/resources/messages/pluginBundle_de.properties b/src/main/resources/messages/pluginBundle_de.properties
index d6c9af9..6b500dc 100644
--- a/src/main/resources/messages/pluginBundle_de.properties
+++ b/src/main/resources/messages/pluginBundle_de.properties
@@ -26,3 +26,5 @@ valid_failed=Datenvalidierung fehlgeschlagen
sea_orm_json_tips=JSON-Zeichenfolge eingeben, unterstützt nur einfache Objekte, unterstützt keine verschachtelten Objekte und Arrays
run=Funktion
+
+nav_to_psi=Springen zu
diff --git a/src/main/resources/messages/pluginBundle_en.properties b/src/main/resources/messages/pluginBundle_en.properties
index b1cce6e..e114eba 100644
--- a/src/main/resources/messages/pluginBundle_en.properties
+++ b/src/main/resources/messages/pluginBundle_en.properties
@@ -26,3 +26,5 @@ valid_failed=Data validation failed
sea_orm_json_tips=Input JSON string, only supports simple objects, does not support nested objects and arrays
run=function
+
+nav_to_psi=Jump to
diff --git a/src/main/resources/messages/pluginBundle_fr.properties b/src/main/resources/messages/pluginBundle_fr.properties
index 708dc18..b2c42e1 100644
--- a/src/main/resources/messages/pluginBundle_fr.properties
+++ b/src/main/resources/messages/pluginBundle_fr.properties
@@ -26,3 +26,5 @@ valid_failed=Échec de la validation des données
sea_orm_json_tips=Entrez une chaîne json, seuls les objets simples sont pris en charge, pas les objets imbriqués et les tableaux
run=Fonctionnement
+
+nav_to_psi=Sauter à
diff --git a/src/main/resources/messages/pluginBundle_hk.properties b/src/main/resources/messages/pluginBundle_hk.properties
index e2267a3..aed2143 100644
--- a/src/main/resources/messages/pluginBundle_hk.properties
+++ b/src/main/resources/messages/pluginBundle_hk.properties
@@ -24,3 +24,5 @@ preview-the-code=程式碼預覽
sea_orm_json_tips=輸入json字串,只支持簡單的對象,不支持嵌套對象和數組
run=運行
+
+nav_to_psi=跳轉到
diff --git a/src/main/resources/messages/pluginBundle_it.properties b/src/main/resources/messages/pluginBundle_it.properties
index 1f278ef..4604abf 100644
--- a/src/main/resources/messages/pluginBundle_it.properties
+++ b/src/main/resources/messages/pluginBundle_it.properties
@@ -26,3 +26,5 @@ valid_failed=Validazione dei dati non riuscita
sea_orm_json_tips=Stringa JSON di input, supporta solo oggetti semplici, non supporta oggetti nidificati e array
run=funzione
+
+nav_to_psi=Vai a
diff --git a/src/main/resources/messages/pluginBundle_ja.properties b/src/main/resources/messages/pluginBundle_ja.properties
index e5a7f69..d4291b0 100644
--- a/src/main/resources/messages/pluginBundle_ja.properties
+++ b/src/main/resources/messages/pluginBundle_ja.properties
@@ -26,3 +26,5 @@ valid_failed=データ検証に失敗しました
sea_orm_json_tips=単純なオブジェクトのみをサポートし、ネストされたオブジェクトや配列はサポートしないjson文字列を入力します
run=うんてん
+
+nav_to_psi=ジャンプ先
diff --git a/src/main/resources/messages/pluginBundle_ko.properties b/src/main/resources/messages/pluginBundle_ko.properties
index a57f142..a631223 100644
--- a/src/main/resources/messages/pluginBundle_ko.properties
+++ b/src/main/resources/messages/pluginBundle_ko.properties
@@ -26,3 +26,5 @@ valid_failed=데이터 검증 실패
sea_orm_json_tips=json 문자열을 입력하십시오. 간단한 객체만 지원하고 중첩된 객체와 배열은 지원되지 않습니다.
run=실행
+
+nav_to_psi=다음으로 이동
diff --git a/src/main/resources/messages/pluginBundle_nl.properties b/src/main/resources/messages/pluginBundle_nl.properties
index 2618146..c78fba8 100644
--- a/src/main/resources/messages/pluginBundle_nl.properties
+++ b/src/main/resources/messages/pluginBundle_nl.properties
@@ -26,3 +26,5 @@ valid_failed=Gegevensvalidatie mislukt
sea_orm_json_tips=JSON-tekenreeks invoeren, ondersteunt alleen eenvoudige objecten, ondersteunt geen geneste objecten en arrays
run=functie
+
+nav_to_psi=Ga naar
diff --git a/src/main/resources/messages/pluginBundle_pl.properties b/src/main/resources/messages/pluginBundle_pl.properties
index 48f3f01..9b56073 100644
--- a/src/main/resources/messages/pluginBundle_pl.properties
+++ b/src/main/resources/messages/pluginBundle_pl.properties
@@ -26,3 +26,5 @@ valid_failed=Niepowodzenie walidacji danych
sea_orm_json_tips=Wprowadzanie łańcucha JSON, obsługuje tylko proste obiekty, nie obsługuje zagnieżdżonych obiektów i tablic
run=funkcja
+
+nav_to_psi=Przejdź do
diff --git a/src/main/resources/messages/pluginBundle_pt.properties b/src/main/resources/messages/pluginBundle_pt.properties
index 7d3cd0d..eaa6328 100644
--- a/src/main/resources/messages/pluginBundle_pt.properties
+++ b/src/main/resources/messages/pluginBundle_pt.properties
@@ -26,3 +26,5 @@ valid_failed=A validação dos dados falhou
sea_orm_json_tips=Entrada JSON string, suporta apenas objetos simples, não suporta objetos aninhados e arrays
run=função
+
+nav_to_psi=Saltar para
diff --git a/src/main/resources/messages/pluginBundle_ru.properties b/src/main/resources/messages/pluginBundle_ru.properties
index 3fa6e3d..f292fff 100644
--- a/src/main/resources/messages/pluginBundle_ru.properties
+++ b/src/main/resources/messages/pluginBundle_ru.properties
@@ -26,3 +26,5 @@ valid_failed=Ошибка проверки данных
sea_orm_json_tips=Введите строку json, которая поддерживает только простые объекты, а не встроенные объекты и массивы
run=Запуск
+
+nav_to_psi=Перейти на
From 721414ab7aef3eaabc2d996a02d6f20cec99833e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E6=A2=81=E5=85=B8=E5=85=B8?= <413153189@qq.com>
Date: Fri, 19 Jul 2024 15:09:46 +0800
Subject: [PATCH 2/2] release 2.0.0
---
CHANGELOG.md | 6 ++++
build.gradle.kts | 2 +-
.../action/GenerateHookFormAction.kt | 4 +--
src/main/resources/META-INF/plugin.xml | 36 +++++++++++--------
4 files changed, 31 insertions(+), 17 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 90fe37c..8e14d7b 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,12 @@
## Unreleased
+## [2.0.0] -2024-07-19
+
+- Completely rewritten `salvo api` scanning implementation
+- Added right-click menu operation function to jump to `salvo router handle`
+- Group `salvo` Code generate function operations
+- [changelog](https://mdddj.github.io/SalvoRsToolDocument/changelog%E6%9B%B4%E6%96%B0%E6%97%A5%E5%BF%97.html)
## [1.9.0] -2024-07-04
diff --git a/build.gradle.kts b/build.gradle.kts
index c71f786..2396cd4 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -11,7 +11,7 @@ plugins {
}
group = "shop.itbug"
-version = "1.9.0"
+version = "2.0.0"
repositories {
mavenCentral()
diff --git a/src/main/kotlin/shop/itbug/salvorstool/action/GenerateHookFormAction.kt b/src/main/kotlin/shop/itbug/salvorstool/action/GenerateHookFormAction.kt
index 6581178..f19485a 100644
--- a/src/main/kotlin/shop/itbug/salvorstool/action/GenerateHookFormAction.kt
+++ b/src/main/kotlin/shop/itbug/salvorstool/action/GenerateHookFormAction.kt
@@ -5,11 +5,10 @@ import com.intellij.openapi.actionSystem.AnAction
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.project.Project
import com.intellij.openapi.ui.DialogWrapper
+import com.intellij.ui.components.JBLabel
import com.intellij.ui.components.JBTabbedPane
import org.rust.lang.core.psi.impl.RsStructItemImpl
-import shop.itbug.salvorstool.tool.myManager
import shop.itbug.salvorstool.tool.tryGetRsStructPsiElement
-import shop.itbug.salvorstool.widget.TypeJavaScriptEditor
import javax.swing.JComponent
class GenerateHookFormAction : AnAction() {
@@ -31,6 +30,7 @@ class GenerateHookFormAction : AnAction() {
private val tab = JBTabbedPane()
init {
+ tab.add(JBLabel("Removed!"))
super.init()
}
diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml
index ee987c0..30de41a 100644
--- a/src/main/resources/META-INF/plugin.xml
+++ b/src/main/resources/META-INF/plugin.xml
@@ -24,28 +24,41 @@
+
+
-
-
-
+
+
+
+
+ text="Generate Antd From"/>
+
+
+
+
+
+
+
+
+
+
-
+
+
-
+
@@ -57,16 +70,11 @@
-
-
+
+
-
-
-
-
-