要求要把论文的算法实现为一个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下找到插件就可以调试了
(一)获取选中的文本,所在行号,文件
//获取用户所在的编辑器对象(就是界面)
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