package com.zxy.ijplugin.wechat_miniprogram.lang.wxml.tag;
import com.intellij.application.options.CodeStyle;
import com.intellij.application.options.editor.WebEditorOptions;
import com.intellij.codeInsight.TailType;
import com.intellij.codeInsight.completion.CompletionUtil;
import com.intellij.codeInsight.completion.InsertHandler;
import com.intellij.codeInsight.completion.InsertionContext;
import com.intellij.codeInsight.daemon.impl.quickfix.EmptyExpression;
import com.intellij.codeInsight.editorActions.XmlEditUtil;
import com.intellij.codeInsight.editorActions.XmlTagNameSynchronizer;
import com.intellij.codeInsight.lookup.Lookup;
import com.intellij.codeInsight.lookup.LookupElement;
import com.intellij.codeInsight.lookup.LookupItem;
import com.intellij.codeInsight.template.Template;
import com.intellij.codeInsight.template.TemplateEditingAdapter;
import com.intellij.codeInsight.template.TemplateManager;
import com.intellij.codeInsight.template.impl.MacroCallNode;
import com.intellij.codeInsight.template.macro.CompleteMacro;
import com.intellij.codeInsight.template.macro.CompleteSmartMacro;
import com.intellij.codeInspection.InspectionProfile;
import com.intellij.codeInspection.htmlInspections.XmlEntitiesInspection;
import com.intellij.injected.editor.EditorWindow;
import com.intellij.lang.ASTNode;
import com.intellij.openapi.command.WriteCommandAction;
import com.intellij.openapi.command.undo.UndoManager;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.RangeMarker;
import com.intellij.openapi.editor.ScrollType;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Ref;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.profile.codeInspection.InspectionProjectProfileManager;
import com.intellij.psi.PsiDocumentManager;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.psi.codeStyle.CodeStyleSettings;
import com.intellij.psi.formatter.xml.HtmlCodeStyleSettings;
import com.intellij.psi.formatter.xml.XmlCodeStyleSettings;
import com.intellij.psi.html.HtmlTag;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.psi.xml.XmlTag;
import com.intellij.psi.xml.XmlTokenType;
import com.intellij.xml.*;
import com.intellij.xml.XmlExtension.AttributeValuePresentation;
import com.intellij.xml.actions.GenerateXmlTagAction;
import com.intellij.xml.impl.schema.XmlElementDescriptorImpl;
import com.intellij.xml.util.HtmlUtil;
import com.intellij.xml.util.XmlUtil;
import com.zxy.ijplugin.wechat_miniprogram.lang.wxml.utils.WXMLAttributeInsertUtils;
import com.zxy.ijplugin.wechat_miniprogram.lang.wxml.utils.WXMLUtils;
import kotlin.collections.ArraysKt;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.*;
/**
* copy from {@see com.intellij.codeInsight.completion.XmlTagInsertHandler}
*/
public class WXMLTagInsertHandler implements InsertHandler<LookupElement> {
public static final WXMLTagInsertHandler INSTANCE = new WXMLTagInsertHandler();
public static void insertIncompleteTag(char completionChar,
final Editor editor,
XmlTag tag) {
XmlTag originalElement = CompletionUtil.getOriginalElement(tag);
XmlElementDescriptor descriptor = originalElement != null ? originalElement.getDescriptor() : tag.getDescriptor();
if (descriptor == null) return;
final Project project = editor.getProject();
assert project != null;
TemplateManager templateManager = TemplateManager.getInstance(project);
Template template = templateManager.createTemplate("", "");
template.setToIndent(true);
// temp code
PsiFile containingFile = tag.getContainingFile();
boolean htmlCode = HtmlUtil.hasHtml(containingFile) || HtmlUtil.supportsXmlTypedHandlers(containingFile);
template.setToReformat(!htmlCode);
StringBuilder indirectRequiredAttrs = addRequiredAttributes(tag, template, containingFile);
final boolean chooseAttributeName = addTail(completionChar, descriptor, htmlCode, tag, template,
indirectRequiredAttrs);
templateManager.startTemplate(editor, template, new TemplateEditingAdapter() {
private RangeMarker myAttrValueMarker;
@Override
public void waitingForInput(Template template) {
int offset = editor.getCaretModel().getOffset();
myAttrValueMarker = editor.getDocument().createRangeMarker(offset + 1, offset + 4);
}
@Override
public void templateFinished(@NotNull final Template template, boolean brokenOff) {
final int offset = editor.getCaretModel().getOffset();
if (chooseAttributeName && offset > 0) {
char c = editor.getDocument().getCharsSequence().charAt(offset - 1);
if (c == '/' || (c == ' ' && brokenOff)) {
WriteCommandAction.writeCommandAction(project).run(
() -> editor.getDocument().replaceString(offset, offset + 3, ">"));
}
}
}
@Override
public void templateCancelled(final Template template) {
if (myAttrValueMarker == null) {
return;
}
if (UndoManager.getInstance(project).isUndoOrRedoInProgress()) {
return;
}
if (chooseAttributeName && myAttrValueMarker.isValid()) {
final int startOffset = myAttrValueMarker.getStartOffset();
final int endOffset = myAttrValueMarker.getEndOffset();
WriteCommandAction.writeCommandAction(project).run(
() -> editor.getDocument().replaceString(startOffset, endOffset, ">"));
}
}
});
}
@Nullable
private static StringBuilder addRequiredAttributes(@Nullable XmlTag tag,
Template template,
PsiFile containingFile) {
Set<String> notRequiredAttributes = Collections.emptySet();
if (tag instanceof HtmlTag) {
final InspectionProfile profile = InspectionProjectProfileManager.getInstance(
tag.getProject()).getCurrentProfile();
XmlEntitiesInspection inspection = (XmlEntitiesInspection) profile.getUnwrappedTool(
XmlEntitiesInspection.REQUIRED_ATTRIBUTES_SHORT_NAME, tag);
if (inspection != null) {
StringTokenizer tokenizer = new StringTokenizer(inspection.getAdditionalEntries());
notRequiredAttributes = new HashSet<>();
while (tokenizer.hasMoreElements()) notRequiredAttributes.add(tokenizer.nextToken());
}
}
XmlAttributeDescriptor[] attributes = WXMLUtils.getWXMLAttributeDescriptors(tag);
StringBuilder indirectRequiredAttrs = null;
if (WebEditorOptions.getInstance().isAutomaticallyInsertRequiredAttributes()) {
final XmlExtension extension = XmlExtension.getExtension(containingFile);
for (XmlAttributeDescriptor attributeDecl : attributes) {
String attributeName = attributeDecl.getName(tag);
boolean shouldBeInserted = extension.shouldBeInserted(attributeDecl);
if (!shouldBeInserted) continue;
AttributeValuePresentation presenter =
extension.getAttributeValuePresentation(tag, attributeName,
XmlEditUtil.getAttributeQuote(containingFile));
boolean htmlCode = HtmlUtil.hasHtml(containingFile) || HtmlUtil.supportsXmlTypedHandlers(
没有合适的资源?快使用搜索试试~ 我知道了~
基于JetBrains平台的微信小程序插件
共248个文件
kt:145个
xml:20个
ts:18个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 68 浏览量
2024-12-31
15:56:05
上传
评论
收藏 1.02MB ZIP 举报
温馨提示
基于JetBrains平台的微信小程序插件。wxml/wxss/wxs文件支持,语法解析,代码完成,代码高亮。wxml嵌入表达式支持。wxml 标签支持。wxml提取自定义组件。创建微信小程序组件以及页面,相关文件导航,微信小程序自定义组件支持。自动注册自定义组件。组件配置解析。重命名小程序自定义组件或页面。同时移动自定义组件或页面的所有文件。微信小程序配置文件支持。代码检查以及自动修复。支持QQ小程序。支持NPM中的组件
资源推荐
资源详情
资源评论
收起资源包目录
基于JetBrains平台的微信小程序插件 (248个子文件)
$PRODUCT_WORKSPACE_FILE$ 489B
gradlew.bat 2KB
Wechat mini program page js file(Component API).js.ft 84B
Wechat mini program component js file.js.ft 84B
Wechat mini program page js file(Page API).js.ft 70B
Wechat mini program page json file(Component API).json.ft 58B
Wechat mini program component json file.json.ft 58B
Wechat mini program page json file(Page API).json.ft 35B
.gitignore 2KB
.gitignore 38B
gradlew 5KB
description.html 6KB
description.html 6KB
description.html 6KB
description.html 6KB
description.html 6KB
WXMLUnknownTag.html 122B
WxmlWxsModuleImport.html 110B
WXMLInvalidImport.html 110B
WXSSInvalidImport.html 110B
gradle-wrapper.jar 54KB
WXMLTagInsertHandler.java 21KB
WXMLParsing.java 11KB
WXMLXmlParser.java 2KB
WechatMiniProgramIcons.java 1KB
WXSSLanguage.java 640B
WXSSSyntaxHighlighterFactory.java 560B
WXMLLanguage.java 429B
WXSSElementType.java 428B
elementDescriptions.json 110KB
app.json 13KB
page.json 2KB
WXMLAttributeNameCompletionProvider.kt 15KB
WXMLReferenceContributor.kt 14KB
WxmlJsSpecificHandlersFactory.kt 14KB
WXSSTermImpl.kt 13KB
WXMLMetadata.kt 13KB
WXSSCompletionContributor.kt 12KB
WXMLElementDocumentProvider.kt 12KB
WXMLCreateEventHandlerIntentionAction.kt 11KB
WXMLElementAttributeDocumentProvider.kt 11KB
JsonReferenceContributor.kt 11KB
WXMLAttributeNameInsertHandler.kt 10KB
WXMLClassReference.kt 10KB
WXMLTagNameProvider.kt 10KB
WechatMiniProgramContext.kt 10KB
WXSSPropertyBlock.kt 10KB
WXMLModuleUtils.kt 10KB
WXMLElementPathAttributeInspection.kt 10KB
UpdateInfoActivity.kt 9KB
ComponentFileReference.kt 9KB
WxmlJSInjector.kt 9KB
WxmlXmlExtension.kt 9KB
CreateWechatMiniProgramPageAction.kt 9KB
MiniProgramSassFormattingModelBuilder.kt 9KB
WechatMiniProgramGotoRelatedProvider.kt 9KB
WXMLUtils.kt 9KB
MiniProgramScssFormattingModelBuilder.kt 9KB
WXSSInvalidImportInspection.kt 9KB
ComponentJsonUtils.kt 9KB
WechatMiniProgramJsonSchemaProviderFactory.kt 9KB
WXMLExtractComponentRefactoring.kt 9KB
CreateWechatMiniProgramFileGroupAction.kt 9KB
SetQQMiniProgramTypeNotification.kt 9KB
ComponentJsUtils.kt 8KB
WXMLExtractComponentIntentionAction.kt 8KB
MyExtends.kt 8KB
WXMLCreateClassAtWxssFileIntentionAction.kt 8KB
WxmlJsBracesInterpolationTypedHandler.kt 8KB
ComponentFilesAutomaticRenamerFactory.kt 8KB
WXSSReferenceContributor.kt 8KB
ComponentFilesCreator.kt 8KB
MyStylusTermListBlock.kt 8KB
ComponentWxmlUtils.kt 8KB
WXMLTemplateDefinitionChooseByNameContributor.kt 8KB
MoveComponentReferenceHandler.kt 8KB
WXMLIdReference.kt 8KB
RelateFileHolder.kt 8KB
WXSSIdChooseByNameContributor.kt 8KB
CreateWechatMiniProgramComponentAction.kt 8KB
MiniProgramLessFormattingModelBuilder.kt 8KB
WXSSClassChooseByNameContributor.kt 8KB
WXMLElementDescriptorProvider.kt 8KB
WXSSTermListBlock.kt 8KB
WXMLElementDescriptor.kt 8KB
WXMLTemplateNameAttributeReference.kt 8KB
WXMLIncludeTagFolding.kt 7KB
WXMLCreateSelectorAtWxssFileIntentionAction.kt 7KB
ComponentPathLastReferenceRenameHandler.kt 7KB
WxmlJsInspectionFilter.kt 7KB
WXSSElementDescriptionProvider.kt 7KB
WXMLAttributeInsertUtils.kt 7KB
WXMLCreateIdAtWxssFileIntentionAction.kt 7KB
MyJSPredefinedLibraryProvider.kt 7KB
WXMLTemplateFindUsageProvider.kt 7KB
WXMLElementColorProvider.kt 7KB
WXSSModuleUtils.kt 7KB
ComponentRegistrationRenameProcessor.kt 7KB
WXMLBasicElementDescriptor.kt 7KB
WXMLCustomComponentAttributeDescriptor.kt 7KB
共 248 条
- 1
- 2
- 3
资源评论
Java程序员-张凯
- 粉丝: 1w+
- 资源: 7525
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 这是一个筛选菜单库,开发者只需要填充数据即可,在很多App上都能看到这个效果,如美团,爱奇艺,大众点评等.zip
- Flask Web应用程序与PostgreSQL数据库集成实现API及自动化脚本构建工具
- 这是一个运动健身类app,纺大夜跑团 ,能够根据gps或网络定位来实时绘制跑步轨迹; (毕业设计 后台管理系统 学生管理系统 教务管理系统 学校管理系统 毕设 管理平台 数据管理系统 后端开发.zip
- html+css网页设计 美食 美食模版2个页面
- 遥感大数据012345.zip
- 阿里天池比赛 印象盐城·数创未来大数据竞赛 - 盐城汽车上牌量预测.zip
- 阿里巴巴天池大数据竞赛.zip
- 零代,项目脚手架,包括Web应用、WebApi接口、微服务、控制台、定时调度任务、大数据计算、物联网等项目模板.zip
- chrome 原生 netlog抓去
- 零基础大数据学习笔记.zip
- 高并发但每次爬取数据量不大的分布式爬虫 .zip
- 机械设计笔记本电脑自动搬运压合测试站sw16非常好的设计图纸100%好用.zip
- simulink 双馈风机稳态模型 包含最大功率跟踪控制,MPPT,参数可调 (1)转子侧变器采用基于定子电压定向的矢量控制策略,可以有功无功解耦,具备MPPT能力,采用功率外环电流内环双闭环控制结构
- 浪潮端到端产品安全保障体系:2021年度网络安全实践与展望
- Fluent的颗粒流 稀疏颗粒常使用DPM模型进行解决 不考虑颗粒碰撞变形,但考虑颗粒之间的碰撞行为,可以使用欧拉颗粒流模型 考虑颗粒碰撞摩擦以及变形,可以使用其内置的DEM模型,也可以采用与其他D
- python入门教程资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功