IDEA插件开发

要求要把论文的算法实现为一个IDEA插件,网络资料很少,记录下来以后方便查看。写完一个插件,最基本的写法倒是都包括了。(未仔细研究原理细节了,毕竟就是为了快速完成一个可用插件)

插件开发的环境配置❗❗

(使用gradle的话,要选择jdk11,在src以下的包右键找有action)

(1)配置sdk
Project Structure->SDKs->Add XXX(选择IDEA文件夹即可)
Project Structure->Projects(SDK匹配)

(2)新建插件项目
在这里插入图片描述
(3)右键src文件夹创建action
之后生成java文件,run “Plugin”,IDEA会开启一个新的窗口,edit下找到插件就可以调试了
img

img

(一)获取选中的文本,所在行号,文件

 //获取用户所在的编辑器对象(就是界面)
    Editor editor=e.getData(PlatformDataKeys.EDITOR);
    //通过编辑器获取选中对象
    SelectionModel model=editor.getSelectionModel();
    //获取模型中的文本
    String selectedText=model.getSelectedText();
    VisualPosition position=model.getSelectionStartPosition();
    if(StringUtils.isEmpty(selectedText)){
       return;
    }
    System.out.println("选中文本:"+selectedText+",位置:"+position.getLine());
}

(二)构成git命令,运行git命令

1. 上面获取了方法的基本信息,使用git log命令就可以获取这个函数在commit history中的变化(注意:这样的git log可以获取完整的函数)

【命令】git log -L:funcname:file可以获取这个函数在所有commit里面的变化,当然我们只需要最新的就可以了

(1)首先配置

在项目的根目录下直接随便复制一个.gitattributes

增加*.java diff=java就可以了

# The default behavior, which overrides 'core.autocrlf', is to use Git's
# built-in heuristics to determine whether a particular file is text or binary.
# Text files are automatically normalized to the user's platforms.
* text=auto

# Explicitly declare text files that should always be normalized and converted
# to native line endings.
.gitattributes text
.gitignore text
LICENSE text
Dockerfile text
*.avsc text
*.go text
*.html text
*.java text
*.md text
*.properties text
*.proto text
*.py text
*.sh text
*.xml text
*.yml text
*.java diff=java

# Declare files that will always have CRLF line endings on checkout.
# *.sln text eol=crlf

# Explicitly denote all files that are truly binary and should not be modified.
# *.jpg binary

# Declare files that should be ignored when creating an archive of the
# git repository
.gitignore export-ignore
.gitattributes export-ignore
/gradlew* export-ignore
/gradle export-ignore

2.收集模型输入数据,远程调用训练好的模型给出预测。
在这里插入图片描述

(三)调用模型(协议的方式)

使用httpURLConnection连接,具体在《模型部署》
https://blog.csdn.net/qq_36975499/article/details/121082440

(四)给出结果/提示

黄色高亮:需要重命名

public static RangeHighlighter highlightMatch(@NotNull Editor editor, int start, int end) {
        TextAttributes color = editor.getColorsScheme().getAttributes(EditorColors.TEXT_SEARCH_RESULT_ATTRIBUTES);
        return editor.getMarkupModel().addRangeHighlighter(start, end, HighlighterLayer.ADDITIONAL_SYNTAX + 1,
                color, HighlighterTargetArea.EXACT_RANGE);
    }

右下角的提示框(代码+):

Project project = e.getData(PlatformDataKeys.PROJECT);
//.....
NotificationGroup notify = new NotificationGroup("com.yatoufang.notify", NotificationDisplayType.BALLOON, true);
notify.createNotification("方法名检测完成,双击选中已标记为需校正的方法名确认继续进行重构。", NotificationType.INFORMATION).notify(project);

plugin.xml

  <extensions defaultExtensionNs="com.intellij">
        <!-- Add your extensions here -->
        <notificationGroup id="Custom Notification Group" displayType="BALLOON" key="notification.group.name"/>
    </extensions>

(五)部署

Q:如何使得插件满足所有版本的IDEA

build.gradle

intellij {
    version '2020.3'
    updateSinceUntilBuild=false

}
patchPluginXml {
    version project.version

}

plugin.xml

<idea-plugin>
    <idea-version since-build="3000"/>

部署流程:
buildPlugin,无错误之后在build/distributions下生成可安装jar包
在这里插入图片描述

安装流程:
Settings->Plugin->Install From Disk

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值