Skip to content

Commit

Permalink
Merge pull request #15
Browse files Browse the repository at this point in the history
1.5.2
  • Loading branch information
mdddj authored May 10, 2024
2 parents 7676831 + 59a5539 commit 3baed1f
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 21 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# Changelog


## [1.5.2] - 2024-05-10

- 修复struct属性为Option类型无法生成Typescript Interface字段的问题
- <p><b><a href="https://mdddj.github.io/SalvoRsToolDocument/changelog%E6%9B%B4%E6%96%B0%E6%97%A5%E5%BF%97.html#1-5-1">更新日志</a></b></p>

## [1.5.1] - 2024-05-08

- 适配RustRover2024.1.EAP
Expand Down
7 changes: 3 additions & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@ plugins {
}

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

repositories {
mavenCentral()
}

intellij {
version.set("LATEST-EAP-SNAPSHOT")
// localPath.set("/Users/ldd/Applications/RustRover.app/Contents")
// localSourcesPath.set("/Users/hlx/github/intellij-community")
type.set("RR")
plugins.set(listOf("com.jetbrains.rust","JavaScriptBase"))
}
Expand All @@ -26,9 +28,6 @@ tasks {
sourceCompatibility = "17"
targetCompatibility = "17"
}
withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
kotlinOptions.jvmTarget = "17"
}



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import com.intellij.openapi.project.Project
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiFile
import org.rust.lang.core.psi.impl.RsStructItemImpl
import shop.itbug.salvorstool.tool.antdTableColumnItem
import shop.itbug.salvorstool.tool.copy
import shop.itbug.salvorstool.tool.myManager

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import com.intellij.psi.util.PsiTreeUtil
import org.rust.lang.core.psi.RsMetaItem
import org.rust.lang.core.psi.RsNamedFieldDecl
import org.rust.lang.core.psi.RsOuterAttr
import org.rust.lang.core.psi.RsTypeArgumentList
import org.rust.lang.core.psi.ext.elementType
import org.rust.lang.core.psi.ext.stringValue
import org.rust.lang.core.psi.impl.RsNamedFieldDeclImpl
Expand Down Expand Up @@ -117,27 +116,24 @@ class MyFieldPsiElementManager(private val psiElement: RsNamedFieldDecl) {
///参数类型文本
val typeString: String?
get() {
println("${psiElement.text} is options? ${isOption}")
if (isOption) {
val typeList = typeArgumentList?.typeReferenceList
if (!typeList.isNullOrEmpty()) {
return null
} else if (typeList != null && typeList.size == 1) {
return typeList.first().text
}
return null
return extractTextBetweenBrackets(typePsiText?:"")
}
return psiElement.typeReference?.text
}


private val getPathTypeImpl = PsiTreeUtil.findChildOfType(
psiElement,
RsPathTypeImpl::class.java
)

private val typePsiText = getPathTypeImpl?.text

///判断是否为可空的属性,比如Option<i32> return true
private val isOption: Boolean get() = typeArgumentList != null
private val isOption: Boolean get() = typePsiText?.startsWith("Option<") == true && typePsiText.endsWith(">")

/// Option<i32> 获取 <i32>
private val typeArgumentList: RsTypeArgumentList?
get() = PsiTreeUtil.findChildOfType(
psiElement,
RsPathTypeImpl::class.java
)?.path?.typeArgumentList

///获取字段文本(除了宏以外)
val getSimpleText: String
Expand All @@ -153,6 +149,7 @@ class MyFieldPsiElementManager(private val psiElement: RsNamedFieldDecl) {
//获取JavaScript类型
private val javaScriptType: JavascriptType
get() {
println("type string is $typeString")
if (typeString == null) {
return JavascriptType.Unknown
}
Expand Down Expand Up @@ -231,6 +228,16 @@ class MyFieldPsiElementManager(private val psiElement: RsNamedFieldDecl) {
}
return JsModel(javaScriptType, name, comment = comment, isOption = isOption)
}

private fun extractTextBetweenBrackets(input: String): String? {
val regex = "<([^>]*)>".toRegex()
val matchResult = regex.find(input)
return if (matchResult != null) {
matchResult.groupValues[1]
} else {
null
}
}
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import com.intellij.icons.AllIcons
import com.intellij.ide.DataManager
import com.intellij.openapi.actionSystem.ActionManager
import com.intellij.openapi.actionSystem.DataKey
import com.intellij.openapi.actionSystem.DataProvider
import com.intellij.openapi.actionSystem.DefaultActionGroup
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.project.Project
Expand Down

0 comments on commit 3baed1f

Please sign in to comment.