jetbrain插件开发
定义文件模板
1. 打开设置:
Windows/Linux:
File > Settings > Editor > File and Code Templates
macOS:
GoLand > Preferences > Editor > File and Code Templates
2. 新建模板:
选择 Files 标签页。
点击右上角的 + 添加新模板。
Name: 比如叫
Go File With Main
或Custom Go File
3. 使用模板
在文件夹右键 → new → 选择自己的模板→ 输入文件名→创建文件
文件模板导出和分享
导出
路径:file→manage→export settings 然后选择需要导出的配置,选择File Templates 导出为一个zip文件
导入
路径:file-manege- import settings
然后选择要导入的zip,导入即可; 重启更新即可使用文件模板
插件开发(External tool)
例如:
1. 打开 External Tools 设置
File > Settings (Preferences on macOS)
左侧导航栏中找到:
Tools > External Tools
点击右侧的
+
添加新项
2. 配置 External Tool
3. 创建 JS 文件(如果你还没有)
在项目目录下新建 scripts/test.js
:
js
复制编辑
// scripts/test.js
console.log("Hello from Node script!");
4. 运行方式
在菜单中点击:
Tools > External Tools > Run Node Script
或右键文件夹 → External Tools → Run Node Script
你会在下方的 Run 窗口看到输出:
bash
复制编辑
Hello from Node script!
5. 导出
同上的导出导入
插件开发(可发布插件)
✅ 前置准备
安装 IntelliJ IDEA(推荐最新版)
确保你已安装插件开发相关组件:
打开 Settings > Plugins
确保已安装插件:
Java
和Gradle
安装官方插件:
IntelliJ Platform Plugin
🚀 创建插件项目步骤
1. 新建项目
打开 IntelliJ IDEA,点击:
arduino 复制编辑 File > New > Project
在左侧选择:
IntelliJ Platform Plugin
设置项目名,比如:
NodeScriptPlugin
建议选择语言:Kotlin 或 Java
2. 配置项目结构
IDE 会自动生成一个 Gradle 项目,核心结构如下:
css
复制编辑
NodeScriptPlugin/
├── build.gradle.kts
├── settings.gradle.kts
├── src/main/kotlin/com/yourpkg/YourAction.kt
├── src/main/resources/META-INF/plugin.xml
3. 编辑 plugin.xml
这是插件的“清单”,放在 resources/META-INF/plugin.xml
中:
xml
复制编辑
<idea-plugin>
<id>com.example.nodescriptplugin</id>
<name>Node Script Runner</name>
<version>1.0</version>
<vendor>your name</vendor>
<description>Run a Node.js script from the menu</description>
<actions>
<action id="RunNodeScriptAction"
class="com.example.RunNodeScriptAction"
text="Run Node Script"
description="Run a Node.js script">
<add-to-group group-id="MainMenu" anchor="last"/>
</action>
</actions>
</idea-plugin>
4. 编写菜单行为(Kotlin 示例)
新建文件 RunNodeScriptAction.kt
:
kotlin
复制编辑
package com.example
import com.intellij.openapi.actionSystem.AnAction
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.ui.Messages
import java.io.BufferedReader
import java.io.InputStreamReader
class RunNodeScriptAction : AnAction() {
override fun actionPerformed(e: AnActionEvent) {
try {
val process = ProcessBuilder("node", "scripts/test.js")
.redirectErrorStream(true)
.start()
val reader = BufferedReader(InputStreamReader(process.inputStream))
val output = reader.readText()
process.waitFor()
Messages.showInfoMessage(output, "Node Output")
} catch (ex: Exception) {
Messages.showErrorDialog("Error: ${ex.message}", "Node Error")
}
}
}
5. 放你的脚本
例如在插件项目根目录创建:
bash
复制编辑
scripts/test.js
内容随便写个:
js
复制编辑
console.log("Hello from plugin Node script!");
🧪 测试插件
点击顶部工具栏:
mathematica 复制编辑 Run > Run 'Plugin'
会启动一个新的 IDE 实例(沙盒)
在新 IDE 中顶部菜单栏可见:
mathematica 复制编辑 Run Node Script
点击后,会执行你的 JS 脚本
注意事项
大大受到gw的影响