当前位置:网站首页>让live-templet活起来
让live-templet活起来
2022-08-05 18:55:00 【黄希彤】
众所周知Jetbrains的代码片段live-templet其实并不怎么live,编写完了以后就一直放在那儿,直到下次更新它。
虽然官方说可以用“Add Read-Only source”功能让live-templet与远程的只读源同步,实际上只读源的功能一直都不稳定,官方论坛吐槽也很多,然后file-templet和live-templet的远程同步功能似乎也并不可用。
所以如果需要一个可以更服务器同步,团队内组织内共享的活的live-templet库,要么去买一些收费的插件比如cacher,要么就要自己通过Completion Contributor来模拟lve-templet。扒拉了一下文档,简单来说大概要这么做:
1 到github上下载插件模板工程到本地,用IDEA打开。readme里面要求安装的plugins也都安装上。
2 在src/main/kotlin下面创建自己的package和kotlin class,比如 com.github.myname.myplugin.completion.contributors 和 MyCompletionContributor.kt
3 到 src/main/resources/META-INF/plugin.xml 里的extensions里面添加completion.contributor段,把上一步的class注册到IDE里面,比如
<completion.contributor language="any" implementationClass="com.github.myname.myplugin.completion.contributors.MyCompletionContributor"></completion.contributor>4 在MyCompletionContributor里面override 掉 fillCompletionVariants 方法,大概像这样
package com.github.myname.myplugin.completion.contributors
import com.intellij.codeInsight.completion.*
import com.intellij.codeInsight.lookup.LookupElementBuilder
open class MyCompletionContributor() : CompletionContributor() {
override fun fillCompletionVariants(parameters: CompletionParameters, result: CompletionResultSet) {
println(parameters.editor.document.text)
result.addElement(LookupElementBuilder.create("random suggestion1 " + Math.random().toString()))
result.addElement(LookupElementBuilder.create("random suggestion2 " + Math.random().toString()))
result.addElement(LookupElementBuilder.create("random suggestion3 " + Math.random().toString()))
result.addLookupAdvertisement("只是一个测试而已")
}
}5 拉下 help 菜单搜索 gradle,打开gradle窗口,选择 Run Plugin
新开一个文件验证一下,已经可以实时动态生成随机推荐了。
边栏推荐
猜你喜欢
随机推荐
EfficientFormer学习笔记
Umi4 集成阿里低代码框架lowcode-engine
记一次Max模型导入到GIS平台歪了,尺寸不对过程分析
云渲染平台是互联网和云计算的发展产物
知识点滴 - ODBC和ADO的区别
使用 Monaco Editor 开发 SQL 编辑器
scapy 模块的安装
RHCE 作业三
OWASP的s-sdlc项目优秀分享
SQL注入 基础学习
PBX与VoIP:它们之间有什么区别?
rhcsa 第一次作业
div网页布局(做一个简单网页界面为例)
Analysis of the advantages and disadvantages of LED transparent screen VS conventional display
为什么企业需要使用 Wiki 工具?
tiup cluster destroy
国内Api行业,可以内卷到什么程度?
张高兴的 .NET IoT 入门指南:(八)基于 GPS 的 NTP 时间同步服务器
Alibaba billion-level concurrent system design manual has been open source (2022 latest version)
【Redis】key命令学习









