Skip to content

Commit

Permalink
Merge pull request #13
Browse files Browse the repository at this point in the history
1.5.1
  • Loading branch information
mdddj authored May 8, 2024
2 parents 6c7ea84 + 4655adb commit 7676831
Show file tree
Hide file tree
Showing 27 changed files with 309 additions and 49 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# Changelog


## [1.5.1] - 2024-05-08

- 适配RustRover2024.1.EAP
- 添加api右键菜单相关功能
- <p><b><a href="https://mdddj.github.io/SalvoRsToolDocument/changelog%E6%9B%B4%E6%96%B0%E6%97%A5%E5%BF%97.html">更新日志</a></b></p>

## [1.5.0] - 2024-04-28

- 添加salvo api 接口搜索功能
Expand Down
30 changes: 30 additions & 0 deletions DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<p><b>SalvoRsTool</b></p>
<br/>
<p>
<b>
<a href="https://mdddj.github.io/SalvoRsToolDocument">Document</a> |
<a href="https://github.com/mdddj/SalvoRsTool">Github</a> |
<a href="https://mdddj.github.io/SalvoRsToolDocument/default-topic.html">Get Started</a> |
<a href="https://mdddj.github.io/SalvoRsToolDocument/changelog%E6%9B%B4%E6%96%B0%E6%97%A5%E5%BF%97.html">Changelog</a> |
<a href="https://mdddj.github.io/SalvoRsToolDocument/%E6%89%93%E8%B5%8F%E5%92%8C%E8%81%94%E7%B3%BB.html">Donate</a>
</b>
</p>
<br/>
<h2>Features</h2>
<ul>
<li>Salvo
<ul>
<li>Generate DTO</li>
<li>Generate Router</li>
<li>Generate Service</li>
<li>Salvo Api Window</li>
</ul>
</li>
<li>Antd
<ul>
<li>Struct generate Form</li>
<li>Struct generate Table column properties</li>
<li>Struct generate typescript interface</li>
</ul>
</li>
</ul>
9 changes: 7 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ plugins {
}

group = "shop.itbug"
version = "1.5.0"
version = "1.5.1"

repositories {
mavenCentral()
Expand All @@ -16,7 +16,7 @@ repositories {
intellij {
version.set("LATEST-EAP-SNAPSHOT")
type.set("RR")
plugins.set(listOf("com.jetbrains.rust","JavaScript"))
plugins.set(listOf("com.jetbrains.rust","JavaScriptBase"))
}

val pushToken: String? = System.getenv("PUBLISH_TOKEN")
Expand All @@ -42,10 +42,15 @@ tasks {
)
}

val descText = projectDir.resolve("DESCRIPTION.md").readText()

println(descText)

patchPluginXml {
sinceBuild.set("232")
untilBuild.set("242.*")
changeNotes.set(myChangeLog)
pluginDescription.set(descText)
}

signPlugin {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package shop.itbug.salvorstool.action.rightmenu

import com.intellij.icons.AllIcons
import com.intellij.openapi.actionSystem.ActionUpdateThread
import com.intellij.openapi.actionSystem.AnAction
import com.intellij.openapi.actionSystem.AnActionEvent
import shop.itbug.salvorstool.i18n.MyI18n
import shop.itbug.salvorstool.tool.copy
import shop.itbug.salvorstool.window.ApiScanWindow.Companion.JListSelectItemDataKey

/**
* 拷贝antd request 请求
*/
class AntdRequestCopyAction : AnAction() {
override fun actionPerformed(e: AnActionEvent) {
val item = e.getData(JListSelectItemDataKey)!!
val str = item.generateAntdRequest()
str.copy()
}

override fun update(e: AnActionEvent) {
super.update(e)
e.presentation.text = "${MyI18n.getMessage("copy")} Antd Request"
e.presentation.icon = AllIcons.Actions.Copy
e.presentation.isEnabled = e.getData(JListSelectItemDataKey) != null
}

override fun getActionUpdateThread(): ActionUpdateThread {
return ActionUpdateThread.BGT
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package shop.itbug.salvorstool.action.rightmenu

import com.intellij.icons.AllIcons
import com.intellij.openapi.actionSystem.ActionUpdateThread
import com.intellij.openapi.actionSystem.AnAction
import com.intellij.openapi.actionSystem.AnActionEvent
import shop.itbug.salvorstool.i18n.MyI18n
import shop.itbug.salvorstool.tool.copy
import shop.itbug.salvorstool.window.ApiScanWindow.Companion.JListSelectItemDataKey

class CopyUrlAction : AnAction() {

override fun actionPerformed(e: AnActionEvent) {
val item = e.getData(JListSelectItemDataKey)!!
item.api.copy()
}

override fun update(e: AnActionEvent) {
with(e.presentation) {
isEnabled = e.getData(JListSelectItemDataKey) != null
text = "${MyI18n.getMessage("copy")} URL"
icon = AllIcons.Actions.Copy
}
super.update(e)
}

override fun getActionUpdateThread(): ActionUpdateThread {
return ActionUpdateThread.BGT
}
}
89 changes: 78 additions & 11 deletions src/main/kotlin/shop/itbug/salvorstool/model/SalvoApiItem.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ 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 shop.itbug.salvorstool.tool.*
import java.util.*


enum class SalvoApiItemMethod {
Expand All @@ -21,15 +22,81 @@ data class SalvoApiItem(val api: String,val method: SalvoApiItemMethod,val rsMet
override fun toString(): String {
return "\n${api} - $method"
}
}

fun SalvoApiItem.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)
/**
* 生成antd request
*/
fun generateAntdRequest(): String {
val sb = StringBuilder()
sb.appendLine("export async function ${generateRequestName()}(${generateFunctionParams()}) : Promise<any>{")
sb.appendLine("\treturn request(`${replaceAngleBracketsWithDollarCurlyBrackets(api)}`,{")
sb.appendLine("\t\tmethod: '${method.name.uppercase(Locale.getDefault())}',")
sb.appendLine("\t})")
sb.appendLine("}")
return sb.toString()
}

/**
* 函数名称
*/
private fun generateRequestName(): String {
val name = removeIdWithSlash(api).replace("/","_").underlineToCamel.capitalizeFirstLetter()
return firstCharToLowercase(name)
}


/**
* 去除/<id>这种文本
*/
private fun removeIdWithSlash(input: String): String {
val pattern = """\/<[^>]+>""".toRegex()
return pattern.replace(input, "")
}

/**
* 获取url参数
*/
private fun extractBracketContents(input: String): List<String> {
val pattern = """<([^>]+)>""".toRegex()
return pattern.findAll(input).map { it.groupValues[1] }.toList()
}


/**
* 替换<id>->${id}
*/
private fun replaceAngleBracketsWithDollarCurlyBrackets(input: String): String {
val angleBracketsContentPattern = """<([^>]+)>""".toRegex()
return angleBracketsContentPattern.replace(input) { "\${${it.groupValues[1]}}" }
}

/**
* 生成参数列表
*/
private fun generateFunctionParams() : String {
val params = extractBracketContents(api)
if(params.isNotEmpty()){
val sb = StringBuilder()
params.forEach {
sb.append("${it}: string,")
}
return sb.toString().removeSuffix(",")
}
return ""
}
}


/**
* 跳到代码位置
*/
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)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import com.intellij.openapi.progress.ProgressIndicator
import com.intellij.openapi.project.Project
import com.intellij.util.Processor
import shop.itbug.salvorstool.model.SalvoApiItem
import shop.itbug.salvorstool.model.navTo
import shop.itbug.salvorstool.service.SalvoApiService
import shop.itbug.salvorstool.window.SalvoApiItemRender
import javax.swing.ListCellRenderer
Expand Down
16 changes: 13 additions & 3 deletions src/main/kotlin/shop/itbug/salvorstool/tool/ExtendedFuntions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,30 @@ 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 String.capitalizeFirstLetter(): String {
if (isEmpty()) {
return this
}
return substring(0, 1).uppercase(Locale.getDefault()) + substring(1)
}
///
///下划线变驼峰
val String.underlineToCamel: String get() = underlineToCamel(this)
///将驼峰变成下划线
fun underlineToCamel(underlineString: String): String {
return CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, underlineString)
}


///首字母变小写
fun firstCharToLowercase(input: String): String {
if (input.isEmpty() || input.length == 1) return input
val firstChar = input[0]
return if (firstChar.isUpperCase()) {
firstChar.lowercase() + input.substring(1)
} else {
input
}
}

fun AnActionEvent.tryGetRsStructPsiElement(): RsStructItemImpl? {
val psiElement = this.getData(CommonDataKeys.PSI_ELEMENT)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package shop.itbug.salvorstool.tool
import com.intellij.psi.PsiElement
import com.intellij.psi.impl.source.tree.PsiCommentImpl
import com.intellij.psi.util.PsiTreeUtil
import com.intellij.psi.util.lastLeaf
import org.rust.lang.core.psi.RsMetaItem
import org.rust.lang.core.psi.RsNamedFieldDecl
import org.rust.lang.core.psi.RsOuterAttr
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,16 @@ package shop.itbug.salvorstool.tool
import com.intellij.psi.util.PsiTreeUtil
import org.rust.lang.core.psi.RsTypeReference
import org.rust.lang.core.psi.ext.block
import org.rust.lang.core.psi.ext.leftLeaves
import org.rust.lang.core.psi.impl.RsFunctionImpl
import org.rust.lang.core.psi.impl.RsLetDeclImpl
import org.rust.lang.core.psi.impl.RsPathTypeImpl

val RsFunctionImpl.myManager: RsFunctionManager get() = RsFunctionManager(this)

///rs fun tool
class RsFunctionManager(val rsFunction: RsFunctionImpl) {
class RsFunctionManager(private val rsFunction: RsFunctionImpl) {

//获取返回类型
fun getReturnType() : RsTypeReference? {
private fun getReturnType() : RsTypeReference? {
val returnType = rsFunction.retType ?: return null
return returnType.typeReference
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ 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.RsMethodCallImpl
import org.rust.lang.core.psi.impl.RsPathExprImpl
import shop.itbug.salvorstool.model.SalvoApiItem
import shop.itbug.salvorstool.model.SalvoApiItemMethod
import java.util.*
Expand All @@ -15,7 +15,6 @@ val RsMethodCall.methodManager: RsMethodCallManager get() = RsMethodCallManager(
/// method call
class RsMethodCallManager(val psiElement: RsMethodCall) {


private val myIdText: String get() = psiElement.identifier.text

//是否有push函数
Expand All @@ -28,6 +27,13 @@ class RsMethodCallManager(val psiElement: RsMethodCall) {
return PsiTreeUtil.findChildOfType(va, RsDotExprImpl::class.java)
}

// rsPath
val rsPathChild: RsPathExprImpl?
get() {
val va = psiElement.valueArgumentList
return PsiTreeUtil.findChildOfType(va, RsPathExprImpl::class.java)
}

// method
val myApiMethod: SalvoApiItemMethod?
get() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
package shop.itbug.salvorstool.widget

import com.intellij.ide.ui.UITheme
import com.intellij.lang.Language
import com.intellij.lang.javascript.dialects.TypeScriptJSXLanguageDialect
import com.intellij.openapi.editor.colors.EditorColorsManager
import com.intellij.openapi.editor.colors.EditorFontType
import com.intellij.openapi.editor.ex.EditorEx
import com.intellij.openapi.fileEditor.FileEditorManager
import com.intellij.openapi.project.Project
import com.intellij.ui.LanguageTextField
import com.intellij.util.ui.JBFont
import org.rust.lang.RsLanguage
import java.awt.Font
import javax.swing.BorderFactory
import javax.swing.border.Border
Expand Down
Loading

0 comments on commit 7676831

Please sign in to comment.