diff --git a/platform/lang-impl/src/com/intellij/codeInsight/template/impl/LiveTemplateRunLogger.java b/platform/lang-impl/src/com/intellij/codeInsight/template/impl/LiveTemplateRunLogger.java index 4e21ad63cf93..b79e7aa67859 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/template/impl/LiveTemplateRunLogger.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/template/impl/LiveTemplateRunLogger.java @@ -3,7 +3,9 @@ package com.intellij.codeInsight.template.impl; import com.intellij.internal.statistic.eventLog.FeatureUsageData; import com.intellij.internal.statistic.service.fus.collectors.FUCounterUsageLogger; +import com.intellij.internal.statistic.utils.PluginInfo; import com.intellij.lang.Language; +import com.intellij.openapi.util.text.StringUtil; import org.jetbrains.annotations.NotNull; class LiveTemplateRunLogger { @@ -12,11 +14,26 @@ class LiveTemplateRunLogger { static void log(@NotNull TemplateImpl template, @NotNull Language language) { String key = template.getKey(); String groupName = template.getGroupName(); - if (TemplateSettings.getInstance().isStatisticsSafeTemplate(key, groupName)) { - final FeatureUsageData data = new FeatureUsageData(). - addLanguage(language). - addData("group", groupName); - FUCounterUsageLogger.getInstance().logEvent(GROUP, key, data); + if (isCreatedProgrammatically(key, groupName)) return; + + PluginInfo plugin = TemplateSettings.getInstance().findPluginForPredefinedTemplate(template); + if (plugin == null) { + key = "user.defined.template"; + groupName = "user.defined.group"; } + else if (!plugin.isSafeToReport()) { + key = "custom.plugin.template"; + groupName = "custom.plugin.group"; + } + + FeatureUsageData data = new FeatureUsageData().addLanguage(language).addData("group", groupName); + if (plugin != null) { + data.addPluginInfo(plugin); + } + FUCounterUsageLogger.getInstance().logEvent(GROUP, key, data); + } + + private static boolean isCreatedProgrammatically(String key, String groupName) { + return StringUtil.isEmpty(key) || StringUtil.isEmpty(groupName); } } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateSettings.java b/platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateSettings.java index 34443f3a5637..179612dc1d49 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateSettings.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateSettings.java @@ -4,6 +4,7 @@ package com.intellij.codeInsight.template.impl; import com.intellij.AbstractBundle; import com.intellij.codeInsight.template.Template; import com.intellij.codeInsight.template.TemplateContextType; +import com.intellij.internal.statistic.utils.PluginInfo; import com.intellij.internal.statistic.utils.PluginInfoDetectorKt; import com.intellij.openapi.application.ex.DecodeDefaultsUtil; import com.intellij.openapi.components.PersistentStateComponent; @@ -94,7 +95,7 @@ public class TemplateSettings implements PersistentStateComponent mySchemeManager; private State myState = new State(); - private final Set> myStatisticsSafeTemplates = new HashSet<>(); + private final Map, PluginInfo> myPredefinedTemplates = new HashMap<>(); static final class ShortcutConverter extends Converter { @NotNull @@ -185,7 +186,8 @@ public class TemplateSettings implements PersistentStateComponent created = new LinkedHashMap<>(); - for (Element child : element.getChildren(TEMPLATE)) { - TemplateImpl template; try { - template = readTemplateFromElement(groupName, child, classLoader); + result.addElement(readTemplateFromElement(groupName, child, classLoader)); } catch (Exception e) { LOG.warn("failed to load template " + element.getAttributeValue(NAME), e); - continue; } + } + return result; + } + @Nullable + private TemplateGroup mergeParsedGroup(@NotNull Element element, + boolean isDefault, + boolean registerTemplate, + TemplateGroup parsedGroup) { + TemplateGroup result = new TemplateGroup(parsedGroup.getName(), element.getAttributeValue("REPLACE")); + + Map created = new LinkedHashMap<>(); + + for (TemplateImpl template : parsedGroup.getElements()) { if (isDefault) { myDefaultTemplates.put(TemplateKey.keyOf(template), template); }