diff --git a/CHANGELOG.md b/CHANGELOG.md index 453dd19..1be01e3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,11 @@ ## [1.1.2] **Full Changelog**: https://github.com/mdddj/SalvoRsTool/compare/1.1.1.7...1.1.2 +## [1.3.0] - 2024-04-23 + +- Add antd from form generation function +- 添加生成antd pro from表单功能 + ## [1.1.2] - 2024-04-19 - upload test diff --git a/build.gradle.kts b/build.gradle.kts index b190e81..51b52e7 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -5,17 +5,16 @@ plugins { } group = "shop.itbug" -version = "1.1.2" +version = "1.3.0" repositories { mavenCentral() } -// intellij { version.set("LATEST-EAP-SNAPSHOT") type.set("RR") - plugins.set(listOf("com.jetbrains.rust")) + plugins.set(listOf("com.jetbrains.rust","JavaScript")) } val pushToken: String? = System.getenv("PUBLISH_TOKEN") @@ -32,19 +31,9 @@ tasks { patchPluginXml { sinceBuild.set("232") untilBuild.set("242.*") - changeNotes.set(""" -
-

1.1.0

-

- Optimize the presentation of underlined database table names, which will be changed to camel case naming method -

-
- """.trimIndent()) } signPlugin { -// certificateChainFile.set(file("chain.crt")) -// privateKeyFile.set(file("private.key")) certificateChain.set(System.getenv("CERTIFICATE_CHAIN")) privateKey.set(System.getenv("PRIVATE_KEY")) password.set(System.getenv("PRIVATE_KEY_PASSWORD")) @@ -60,4 +49,8 @@ tasks { jvmArgs = listOf("-XX:+AllowEnhancedClassRedefinition") } + dependencies { + implementation("com.alibaba.fastjson2:fastjson2-kotlin:2.0.49") + implementation("cn.hutool:hutool-extra:5.8.27") + } } diff --git a/src/main/kotlin/shop/itbug/salvorstool/action/GenerateAntdFormAction.kt b/src/main/kotlin/shop/itbug/salvorstool/action/GenerateAntdFormAction.kt new file mode 100644 index 0000000..c3feda3 --- /dev/null +++ b/src/main/kotlin/shop/itbug/salvorstool/action/GenerateAntdFormAction.kt @@ -0,0 +1,26 @@ +package shop.itbug.salvorstool.action + +import com.intellij.openapi.actionSystem.ActionUpdateThread +import com.intellij.openapi.actionSystem.AnAction +import com.intellij.openapi.actionSystem.AnActionEvent +import shop.itbug.salvorstool.dialog.GenerateAntdFormDialog +import shop.itbug.salvorstool.tool.tryGetRsStructPsiElement + + +///生成antd表单 +class GenerateAntdFormAction : AnAction() { + override fun actionPerformed(e: AnActionEvent) { + e.tryGetRsStructPsiElement()?.let { + GenerateAntdFormDialog(e.project!!, it).show() + } + } + + override fun update(e: AnActionEvent) { + e.presentation.isVisible = e.tryGetRsStructPsiElement() != null + super.update(e) + } + + override fun getActionUpdateThread(): ActionUpdateThread { + return ActionUpdateThread.BGT + } +} diff --git a/src/main/kotlin/shop/itbug/salvorstool/action/GenerateDtoAction.kt b/src/main/kotlin/shop/itbug/salvorstool/action/GenerateDtoAction.kt index 538594e..4917824 100644 --- a/src/main/kotlin/shop/itbug/salvorstool/action/GenerateDtoAction.kt +++ b/src/main/kotlin/shop/itbug/salvorstool/action/GenerateDtoAction.kt @@ -3,21 +3,18 @@ package shop.itbug.salvorstool.action import com.intellij.openapi.actionSystem.ActionUpdateThread import com.intellij.openapi.actionSystem.AnAction import com.intellij.openapi.actionSystem.AnActionEvent -import com.intellij.openapi.actionSystem.CommonDataKeys -import org.rust.lang.core.psi.impl.RsStructItemImpl import shop.itbug.salvorstool.dialog.GenerateDtoDialog import shop.itbug.salvorstool.i18n.MyI18n -import shop.itbug.salvorstool.tool.myManager +import shop.itbug.salvorstool.tool.tryGetRsStructPsiElement class GenerateDtoAction : AnAction() { override fun actionPerformed(e: AnActionEvent) { - val psiElement = e.getData(CommonDataKeys.PSI_ELEMENT) - GenerateDtoDialog(e.project!!,psiElement as RsStructItemImpl).show() + e.tryGetRsStructPsiElement()?.let { + GenerateDtoDialog(e.project!!,it).show() + } } - override fun update(e: AnActionEvent) { - val psiElement = e.getData(CommonDataKeys.PSI_ELEMENT) - e.presentation.isVisible = e.project != null && psiElement != null && psiElement.myManager.isStruct + e.presentation.isVisible = e.project != null && e.tryGetRsStructPsiElement()!=null e.presentation.text = MyI18n.getMessage("g_dto") super.update(e) } diff --git a/src/main/kotlin/shop/itbug/salvorstool/action/GenerateRouterAction.kt b/src/main/kotlin/shop/itbug/salvorstool/action/GenerateRouterAction.kt index f6a86ab..b11e636 100644 --- a/src/main/kotlin/shop/itbug/salvorstool/action/GenerateRouterAction.kt +++ b/src/main/kotlin/shop/itbug/salvorstool/action/GenerateRouterAction.kt @@ -3,20 +3,20 @@ package shop.itbug.salvorstool.action import com.intellij.openapi.actionSystem.ActionUpdateThread import com.intellij.openapi.actionSystem.AnAction import com.intellij.openapi.actionSystem.AnActionEvent -import com.intellij.openapi.actionSystem.CommonDataKeys -import org.rust.lang.core.psi.impl.RsStructItemImpl import shop.itbug.salvorstool.dialog.GenerateRouterDialog import shop.itbug.salvorstool.i18n.MyI18n -import shop.itbug.salvorstool.tool.myManager +import shop.itbug.salvorstool.tool.tryGetRsStructPsiElement class GenerateRouterAction : AnAction() { override fun actionPerformed(e: AnActionEvent) { - GenerateRouterDialog(e.project!!,e.getData(CommonDataKeys.PSI_ELEMENT) as RsStructItemImpl).show() + e.tryGetRsStructPsiElement()?.let { + GenerateRouterDialog(e.project!!,it).show() + } + } override fun update(e: AnActionEvent) { - val psiElement = e.getData(CommonDataKeys.PSI_ELEMENT) - e.presentation.isVisible = e.project != null && psiElement != null && psiElement.myManager.isStruct + e.presentation.isVisible = e.project != null && e.tryGetRsStructPsiElement() != null e.presentation.text = MyI18n.getMessage("g_router") super.update(e) } diff --git a/src/main/kotlin/shop/itbug/salvorstool/action/GenerateServiceAction.kt b/src/main/kotlin/shop/itbug/salvorstool/action/GenerateServiceAction.kt index 4ae3026..fcfe369 100644 --- a/src/main/kotlin/shop/itbug/salvorstool/action/GenerateServiceAction.kt +++ b/src/main/kotlin/shop/itbug/salvorstool/action/GenerateServiceAction.kt @@ -3,21 +3,19 @@ package shop.itbug.salvorstool.action import com.intellij.openapi.actionSystem.ActionUpdateThread import com.intellij.openapi.actionSystem.AnAction import com.intellij.openapi.actionSystem.AnActionEvent -import com.intellij.openapi.actionSystem.CommonDataKeys -import org.rust.lang.core.psi.impl.RsStructItemImpl import shop.itbug.salvorstool.dialog.GenerateServiceDialog import shop.itbug.salvorstool.i18n.MyI18n -import shop.itbug.salvorstool.tool.myManager +import shop.itbug.salvorstool.tool.tryGetRsStructPsiElement class GenerateServiceAction : AnAction() { override fun actionPerformed(e: AnActionEvent) { - GenerateServiceDialog(e.project!!,e.getData(CommonDataKeys.PSI_ELEMENT) as RsStructItemImpl).show() + e.tryGetRsStructPsiElement()?.let { + GenerateServiceDialog(e.project!!, it).show() + } } - override fun update(e: AnActionEvent) { - val psiElement = e.getData(CommonDataKeys.PSI_ELEMENT) - e.presentation.isVisible = e.project != null && psiElement != null && psiElement.myManager.isStruct + e.presentation.isVisible = e.project != null && e.tryGetRsStructPsiElement() != null e.presentation.text = MyI18n.getMessage("g_service") super.update(e) } diff --git a/src/main/kotlin/shop/itbug/salvorstool/dialog/GenerateAntdFormDialog.kt b/src/main/kotlin/shop/itbug/salvorstool/dialog/GenerateAntdFormDialog.kt new file mode 100644 index 0000000..9bdcae8 --- /dev/null +++ b/src/main/kotlin/shop/itbug/salvorstool/dialog/GenerateAntdFormDialog.kt @@ -0,0 +1,35 @@ +package shop.itbug.salvorstool.dialog + +import com.intellij.openapi.project.Project +import com.intellij.openapi.ui.DialogWrapper +import com.intellij.ui.components.JBTabbedPane +import com.intellij.ui.dsl.builder.panel +import org.rust.lang.core.psi.impl.RsStructItemImpl +import shop.itbug.salvorstool.tool.AntdFactory +import shop.itbug.salvorstool.tool.MyFieldPsiElementManager +import shop.itbug.salvorstool.tool.myManager +import shop.itbug.salvorstool.widget.TypeJavaScriptEditor +import java.awt.Dimension +import javax.swing.JComponent + +///生成antd表单弹窗 +class GenerateAntdFormDialog(project: Project, psiElement: RsStructItemImpl) : DialogWrapper(project, true) { + + + private val tabview = JBTabbedPane() + + init { + super.init() + title = "Generate Antd Form" + + tabview.add("预览", TypeJavaScriptEditor(project, AntdFactory.generateAntdForm(psiElement))) + } + + override fun createCenterPanel(): JComponent { + return tabview + } + + override fun getPreferredSize(): Dimension { + return Dimension(500, super.getPreferredSize().height) + } +} \ No newline at end of file diff --git a/src/main/kotlin/shop/itbug/salvorstool/dialog/GenerateDtoDialog.kt b/src/main/kotlin/shop/itbug/salvorstool/dialog/GenerateDtoDialog.kt index b71a0d9..30d8ff1 100644 --- a/src/main/kotlin/shop/itbug/salvorstool/dialog/GenerateDtoDialog.kt +++ b/src/main/kotlin/shop/itbug/salvorstool/dialog/GenerateDtoDialog.kt @@ -107,7 +107,7 @@ fun GenerateDtoDialogParam.save(project: Project,psiElement: RsStructItemImpl) { ///生成dto对象 -class GenerateDtoDialog(private val project: Project,val psiElement: RsStructItemImpl) : DialogWrapper(project) { +class GenerateDtoDialog(private val project: Project, private val psiElement: RsStructItemImpl) : DialogWrapper(project) { private val model = GenerateDtoDialogParam( addRequestText = MyRsPsiFactory.generateDto(GenerateDtoDialogResultEnum.AddRequest, psiElement), diff --git a/src/main/kotlin/shop/itbug/salvorstool/tool/AntdFactory.kt b/src/main/kotlin/shop/itbug/salvorstool/tool/AntdFactory.kt new file mode 100644 index 0000000..83a5742 --- /dev/null +++ b/src/main/kotlin/shop/itbug/salvorstool/tool/AntdFactory.kt @@ -0,0 +1,112 @@ +package shop.itbug.salvorstool.tool + +import org.rust.lang.core.psi.impl.RsStructItemImpl + + +sealed class Rule +data class AntdRequiredRule(val message: String, val required: Boolean) : Rule() + +private fun Rule.generateString(): String { + return when (this) { + is AntdRequiredRule -> "{ message: '$message', required: ${if (required) "true" else "false"}}" + } +} + + +object AntdFactory { + + + ///生成form + fun generateAntdForm(psiElement: RsStructItemImpl): String { + val sb = StringBuilder() + val jsModels = psiElement.myManager.jsModelList + + //1.添加参数 + sb.appendLine( + """ + type Prop = { + trigger?: JSX.Element | undefined, + initValues?: PropInitValue | undefined + } + """.trimIndent() + ) + + //2.添加模型 + sb.appendLine("interface PropInitValue {") + jsModels.forEach { + sb.appendLine("\t\t${it.propTextString},") + } + sb.appendLine("}") + + //3.添加field + val fieldSb = StringBuilder() + + jsModels.forEach { + fieldSb.appendLine("\t\t" + generateFormItem(it)) + } + + //4.添加最外层的包装 + sb.appendLine(getTemp(fieldSb.toString())) + + return sb.toString() + } + + ///生成form item + fun generateFormItem(model: MyFieldPsiElementManager.JsModel): String { + val type = when (model.type) { + JavascriptType.Number -> "ProFormDigit" + JavascriptType.String -> "ProFormText" + JavascriptType.Bool -> "ProFormSwitch" + JavascriptType.Unknown -> "" + } + if (type.isEmpty()) { + return "" + } + + val rules = mutableListOf() + //添加rule + if (!model.isOption) { + rules.add(AntdRequiredRule(message = "请输入${model.comment ?: "内容"}", required = true)) + } + + return "<$type name='${model.fieldName}' label='${model.comment ?: ""}' ${generateRulesText(rules)} \t\t/>" + } + + ///生成规则 + private fun generateRulesText(rules: List): String { + if (rules.isEmpty()) { + return "" + } + val sb = StringBuilder() + sb.appendLine("rules={[") + rules.forEach { + sb.appendLine("\t\t\t\t\t" + it.generateString()) + } + sb.appendLine("\t\t\t]}") + return sb.toString() + } + +} + + +///模板引擎 +private fun getTemp(field: String): String = """ +const AddOrUpdateForm: React.FC = (props) => { + let isUpdate = props.initValues !== undefined + //提交数据 + const onFinish = async (values: PropInitValue) => { + if(isUpdate) { + // Todo! 修改 + }else{ + // ToDo! 新增 + } + return true + } + return ( + trigger={props.trigger} initialValues={props.initValues} onFinish={onFinish}> + $field + + ); +}; +export {AddOrUpdateForm} +""".trimIndent() \ No newline at end of file diff --git a/src/main/kotlin/shop/itbug/salvorstool/tool/ExtendedFuntions.kt b/src/main/kotlin/shop/itbug/salvorstool/tool/ExtendedFuntions.kt index 67f09c5..8fd5e2e 100644 --- a/src/main/kotlin/shop/itbug/salvorstool/tool/ExtendedFuntions.kt +++ b/src/main/kotlin/shop/itbug/salvorstool/tool/ExtendedFuntions.kt @@ -1,6 +1,8 @@ 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.psi.PsiElement import org.rust.lang.core.psi.RsNamedFieldDecl import org.rust.lang.core.psi.RsOuterAttr @@ -22,4 +24,14 @@ val String.underlineToCamel: String get() = underlineToCamel(this) ///将驼峰变成下划线 fun underlineToCamel(underlineString: String): String { return CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, underlineString) +} + + + +fun AnActionEvent.tryGetRsStructPsiElement(): RsStructItemImpl? { + val psiElement = this.getData(CommonDataKeys.PSI_ELEMENT) + if ( psiElement != null && psiElement.myManager.isStruct) { + return psiElement as? RsStructItemImpl + } + return null } \ 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 279c932..b3dca84 100644 --- a/src/main/kotlin/shop/itbug/salvorstool/tool/MyRsPsiElementManager.kt +++ b/src/main/kotlin/shop/itbug/salvorstool/tool/MyRsPsiElementManager.kt @@ -1,13 +1,34 @@ package shop.itbug.salvorstool.tool +import com.intellij.psi.PsiComment import com.intellij.psi.PsiElement +import com.intellij.psi.impl.source.tree.PsiCommentImpl +import com.intellij.psi.util.PsiTreeUtil +import com.intellij.psi.util.firstLeaf +import com.intellij.psi.util.lastLeaf +import org.rust.lang.core.parser.RustDocTestInjectableParserDefinition 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 +import org.rust.lang.core.psi.impl.RsPathTypeImpl import org.rust.lang.core.psi.impl.RsStructItemImpl +import org.rust.lang.doc.psi.RsDocTokenType +import org.rust.lang.doc.psi.impl.RsDocCommentImpl +val JavascriptType.typeScriptText get() = when (this) { + JavascriptType.Number -> "number" + JavascriptType.String -> "string" + JavascriptType.Bool -> "bool" + JavascriptType.Unknown -> "any" +} +//rs属性类型对应的js类型 +enum class JavascriptType { + Number, String, Bool, Unknown +} /// psi操作管理 class MyRsPsiElementManager(context: PsiElement) { @@ -27,33 +48,73 @@ class MyRsStructManager(private val psiElement: RsStructItemImpl) { val structName: String? = psiElement.name ///获取表明 - val getTableName : String? get() { - val outerAttr = psiElement.outerAttrList.find { it.myManager.getSeaOrmTabName != null } - ?: return null - val tabName = outerAttr.myManager.getSeaOrmTabName - return tabName - } + val getTableName: String? + get() { + val outerAttr = psiElement.outerAttrList.find { it.myManager.getSeaOrmTabName != null } + ?: return null + val tabName = outerAttr.myManager.getSeaOrmTabName + return tabName + } ///主键字段 val primaryField = fieldList.find { it.myManager.isPrimaryKey } -} + ///js 模型列表 + val jsModelList: List = + fieldList.mapNotNull { it.myManager.getJsModel } - -/// +} ///属性处理 class MyFieldPsiElementManager(private val psiElement: RsNamedFieldDecl) { - ///是否为主键的字段 val isPrimaryKey = hasMetaItem("sea_orm") { it.text == "primary_key" } ///参数字段 val name: String? = psiElement.name - val typeString: String? = psiElement.typeReference?.text + ///获取注释 + private val comment: String? + get() { + //判断// + val comm = PsiTreeUtil.getChildOfType(psiElement, PsiCommentImpl::class.java) + if (comm != null) { + return comm.text.replace("//","") + } + val docPsi = PsiTreeUtil.getChildOfType(psiElement, RsDocCommentImpl::class.java) + //判断/// + if (docPsi != null && docPsi.lastLeaf.elementType is RsDocTokenType) { + return docPsi.lastLeaf.text + } + return null + } + + ///参数类型文本 + val typeString: String? + get() { + 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 psiElement.typeReference?.text + } + + ///判断是否为可空的属性,比如Option return true + private val isOption: Boolean get() = typeArgumentList != null + + /// Option 获取 + private val typeArgumentList: RsTypeArgumentList? + get() = PsiTreeUtil.findChildOfType( + psiElement, + RsPathTypeImpl::class.java + )?.path?.typeArgumentList ///获取字段文本(除了宏以外) val getSimpleText: String @@ -66,6 +127,25 @@ class MyFieldPsiElementManager(private val psiElement: RsNamedFieldDecl) { return text } + //获取JavaScript类型 + private val javaScriptType: JavascriptType + get() { + if (typeString == null) { + return JavascriptType.Unknown + } + if (isIntegerType(typeString!!) == true) { + return JavascriptType.Number + } + if (isStringType(typeString!!) == true) { + return JavascriptType.String + } + if (typeString == "bool") { + return JavascriptType.Bool + } + return JavascriptType.Unknown + } + + ///查找meta fun hasMetaItem(filter: (item: RsMetaItem) -> Boolean): Boolean { val outerAttrList = psiElement.outerAttrList @@ -84,7 +164,7 @@ class MyFieldPsiElementManager(private val psiElement: RsNamedFieldDecl) { } ///查找meta,比较精确的查找 - fun hasMetaItem(name: String, filter: (item: RsMetaItem) -> Boolean): Boolean { + private fun hasMetaItem(name: String, filter: (item: RsMetaItem) -> Boolean): Boolean { val find = psiElement.outerAttrList.find { it.myManager.isMeta(name) } ?: return false val args = find.metaItem.metaItemArgs args?.metaItemList?.forEach { meta -> @@ -97,14 +177,54 @@ class MyFieldPsiElementManager(private val psiElement: RsNamedFieldDecl) { } return false } + + //判断是整形 + private fun isIntegerType(rustType: String): Boolean? { + val integerRegex = Regex("""^(i|u)\d+$""") + return if (rustType.matches(integerRegex)) { + true + } else { + null + } + } + + //判断是字符串 + private fun isStringType(rustType: String): Boolean? { + return if (rustType == "String" || rustType == "&str") { + true + } else { + null + } + } + + data class JsModel(val type: JavascriptType, val fieldName: String, val comment: String?,val isOption: Boolean) + + val getJsModel: JsModel? + get() { + if (javaScriptType == JavascriptType.Unknown) { + return null + } else if (name == null) { + return null + } + return JsModel(javaScriptType, name, comment = comment,isOption = isOption) + } } + +val MyFieldPsiElementManager.JsModel.propTextString : String get() { + if(this.isOption) { + return "${fieldName}: ${type.typeScriptText} | undefined" + } + return "${fieldName}: ${type.typeScriptText}" +} + + class MyRsOuterAttrPsiElementManager(private val psiElement: RsOuterAttr) { - val args = psiElement.metaItem.metaItemArgs - val argItems = args?.metaItemList ?: emptyList() - val getSeaOrmTabName = getArgString("sea_orm","table_name") + private val args = psiElement.metaItem.metaItemArgs + private val argItems = args?.metaItemList ?: emptyList() + val getSeaOrmTabName = getArgString("sea_orm", "table_name") ///判断是不是某个宏 fun isMeta(name: String): Boolean { @@ -113,7 +233,7 @@ class MyRsOuterAttrPsiElementManager(private val psiElement: RsOuterAttr) { ///查找meta,比较精确的查找 - fun hasMetaItem(name: String, filter: (item: RsMetaItem) -> Boolean): Boolean { + private fun hasMetaItem(name: String, filter: (item: RsMetaItem) -> Boolean): Boolean { if (!isMeta(name)) return false argItems.forEach { meta -> run { @@ -126,7 +246,7 @@ class MyRsOuterAttrPsiElementManager(private val psiElement: RsOuterAttr) { return false } - fun getArgPsiElement(name: String, attr: String): RsMetaItem? { + private fun getArgPsiElement(name: String, attr: String): RsMetaItem? { if (!hasMetaItem(name) { it.path?.text == attr }) return null argItems.forEach { if (it.path?.text == attr) { @@ -143,7 +263,7 @@ class MyRsOuterAttrPsiElementManager(private val psiElement: RsOuterAttr) { * 传参: "sea_orm","table_name" * 返回: "users" */ - fun getArgString(name: String, attr: String): String? { + private fun getArgString(name: String, attr: String): String? { val psi = getArgPsiElement(name, attr) if (psi != null) { return psi.litExpr?.stringValue diff --git a/src/main/kotlin/shop/itbug/salvorstool/widget/RsEditor.kt b/src/main/kotlin/shop/itbug/salvorstool/widget/RsEditor.kt index 387ed89..77fe09c 100644 --- a/src/main/kotlin/shop/itbug/salvorstool/widget/RsEditor.kt +++ b/src/main/kotlin/shop/itbug/salvorstool/widget/RsEditor.kt @@ -8,16 +8,13 @@ import org.rust.lang.RsLanguage import javax.swing.BorderFactory class RsEditor(project: Project, initText: String) : LanguageTextField(Language.findInstance(RsLanguage::class.java),project,initText,false) { - init { - border = BorderFactory.createEmptyBorder(0, 0, 0, 0) - } override fun createEditor(): EditorEx { return myCreateEditor(super.createEditor()) } } -private fun myCreateEditor(ex: EditorEx): EditorEx { + fun myCreateEditor(ex: EditorEx): EditorEx { ex.setVerticalScrollbarVisible(true) ex.setHorizontalScrollbarVisible(true) ex.setBorder(null) diff --git a/src/main/kotlin/shop/itbug/salvorstool/widget/TypeJavaScriptEditor.kt b/src/main/kotlin/shop/itbug/salvorstool/widget/TypeJavaScriptEditor.kt new file mode 100644 index 0000000..f88b79d --- /dev/null +++ b/src/main/kotlin/shop/itbug/salvorstool/widget/TypeJavaScriptEditor.kt @@ -0,0 +1,16 @@ +package shop.itbug.salvorstool.widget + +import com.intellij.lang.Language +import com.intellij.lang.javascript.dialects.TypeScriptJSXLanguageDialect +import com.intellij.openapi.editor.ex.EditorEx +import com.intellij.openapi.project.Project +import com.intellij.ui.LanguageTextField +import org.rust.lang.RsLanguage + +/// type script 编辑器 +class TypeJavaScriptEditor(project: Project,initText: String) : LanguageTextField(Language.findInstance( + TypeScriptJSXLanguageDialect::class.java),project,initText,false) { + override fun createEditor(): EditorEx { + return myCreateEditor(super.createEditor()) + } +} diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index 558d7ee..98da810 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -7,6 +7,7 @@ ]]> com.intellij.modules.platform com.jetbrains.rust + JavaScript messages.pluginBundle @@ -21,5 +22,9 @@ + + + \ No newline at end of file