protected override string GenerateContent(IDataContext context, string outputFolder) { const string caTopicId = "CA_Chunks"; var caLibrary = XmlHelpers.CreateHmTopic(caTopicId); var tablesByLanguage = new Dictionary <string, XElement>(); var sortedActions = context.GetComponent <IContextActionTable>().AllActions.OrderBy(ca => ca.Name); var caPath = GeneralHelpers.GetCaPath(context); caLibrary.Root.Add( new XComment("Total context actions in ReSharper " + GeneralHelpers.GetCurrentVersion() + ": " + sortedActions.Count())); foreach (var ca in sortedActions) { var lang = ca.Group ?? "Unknown"; if (!tablesByLanguage.ContainsKey(lang)) { tablesByLanguage.Add(lang, XmlHelpers.CreateTwoColumnTable("Name", "Description", "40%")); } var exampleTable = ExtractExamples(ca, caPath, lang); tablesByLanguage.GetValue(lang).Add(new XElement("tr", new XElement("td", new XElement("b", ca.Name)), new XElement("td", ca.Description ?? "", exampleTable, XmlHelpers.CreateInclude("CA_Static_Chunks", ca.MergeKey.NormalizeStringForAttribute())))); } foreach (var table in tablesByLanguage) { var languageChunk = XmlHelpers.CreateChunk("ca_" + table.Key .NormalizeStringForAttribute()); string langText = table.Key == "Common" ? "common use" : table.Key; languageChunk.Add(new XElement("p", "ReSharper provides the following context actions for " + langText + ":")); languageChunk.Add(table.Value); caLibrary.Root.Add(languageChunk); } caLibrary.Save(Path.Combine(outputFolder, caTopicId + ".xml")); return("Context actions"); }
protected override string GenerateContent(IDataContext context, string outputFolder) { const string postfixTopicId = "Postfix_Templates_Generated"; var postfixLibrary = XmlHelpers.CreateHmTopic(postfixTopicId); var postfixChunk = XmlHelpers.CreateChunk("postfix_table"); var macroTable = XmlHelpers.CreateTable(new[] { "Shortcut", "Description", "Example" }, null); var allSortedPostfix = context.GetComponent <PostfixTemplatesManager>() .AllRegisteredPostfixTemplates.OrderBy(template => template.Annotations.TemplateName); postfixLibrary.Root.Add( new XComment("Total postifix templates in ReSharper " + GeneralHelpers.GetCurrentVersion() + ": " + allSortedPostfix.Count())); foreach (var postTempalte in allSortedPostfix) { var postfixRow = new XElement("tr"); var shortcut = postTempalte.Annotations.TemplateName; var description = postTempalte.Annotations.Description; var example = postTempalte.Annotations.Example; var shortcutCell = XElement.Parse("<td><b>." + shortcut + "</b></td>"); shortcutCell.Add(new XAttribute("id", shortcut)); var descriptionCell = XElement.Parse("<td>" + description + "</td>"); var exampleCell = new XElement("td", new XElement("code", example)); postfixRow.Add(shortcutCell, descriptionCell, exampleCell); macroTable.Add(postfixRow); } postfixChunk.Add(macroTable); postfixLibrary.Root.Add(postfixChunk); postfixLibrary.Save(Path.Combine(outputFolder, postfixTopicId + ".xml")); return("Postfix templates"); }
protected override string GenerateContent(IDataContext context, string outputFolder) { var shortcutsXmlDoc = new XDocument(); var actionMapElement = new XElement("Keymap"); shortcutsXmlDoc.Add(actionMapElement); XmlHelpers.AddAutoGenComment(shortcutsXmlDoc.Root); const string menuPathLibId = "Menupath_by_ID"; var menuPathLibrary = XmlHelpers.CreateHmTopic(menuPathLibId); const string accessIntroLibId = "AccessIntro_by_ID"; var accessIntroLibrary = XmlHelpers.CreateHmTopic(accessIntroLibId); var actionManager = context.GetComponent <IActionManager>(); var productcatalogs = context.GetComponent <IPartCatalogSet>(); var actionParts = PartSelector.LeafsAndHides.SelectParts( productcatalogs.Catalogs.SelectMany(catalog => catalog.GetPartsWithAttribute <ActionAttribute>().ToEnumerable())) .ToList(); foreach (PartCatalogType actionPart in actionParts) { var attributes = actionPart.GetPartAttributes <ActionAttribute>(); if (attributes.Count == 0) { Assertion.Fail("{0} has no ActionAttribute", actionPart); } if (attributes.Count > 1) { Assertion.Fail("{0} has {1} ActionAttribute annotations. Only one annotation is supported.", actionPart, attributes.Count); } PartCatalogAttribute attribute = attributes.GetItemAt(0); var actionId = (attribute.ArgumentsOptional[ActionAttribute.ActionAttribute_ActionId].GetStringValueIfDefined() ?? StringSource.Empty).ToRuntimeString(); if (actionId.IsEmpty()) { actionId = ActionDefines.GetIdFromName(actionPart.LocalName); } var actionText = (attribute.ArgumentsOptional[ActionAttribute.ActionAttribute_Text].GetStringValueIfDefined() ?? StringSource.Empty).ToRuntimeString(); if (actionText.IsEmpty()) { actionText = actionId; } actionText = actionText.Replace("&", String.Empty); var vsShortcuts = attribute.ArgumentsOptional[ActionAttribute.ActionAttribute_VsShortcuts].GetArrayValueIfDefined(); var ideaShortcuts = attribute.ArgumentsOptional[ActionAttribute.ActionAttribute_IdeaShortcuts].GetArrayValueIfDefined(); if (actionId.Equals("CompleteCodeBasic")) { vsShortcuts = new object[] { "Control+Space" } } ; if (actionId.Equals("CompleteStatement")) { vsShortcuts = new object[] { "Control+Shift+Enter" } } ; if (actionId.Equals("CompleteCodeBasic")) { ideaShortcuts = new object[] { "Control+Space" } } ; if (actionId.Equals("CompleteStatement")) { ideaShortcuts = new object[] { "Control+Shift+Enter" } } ; string pathToTheRoot; try { pathToTheRoot = (context.GetComponent <ActionPresentationHelper>() .GetPathPresentationToRoot(actionManager.Defs.GetActionDefById(actionId))); } catch (Exception e) { pathToTheRoot = ""; } if (!pathToTheRoot.IsEmpty() && !actionText.IsEmpty()) { pathToTheRoot = pathToTheRoot.Replace('→', '|') + " | " + actionText; } var actionElement = new XElement("Action"); var pattern = new Regex("[_.]"); actionId = pattern.Replace(actionId, String.Empty); actionElement.Add( new XAttribute("id", actionId), new XAttribute("title", actionText), new XAttribute("menupath", pathToTheRoot)); var accessIntroChunk = XmlHelpers.CreateChunk(actionId); var accessIntroWrapper = new XElement("p"); if (!pathToTheRoot.IsNullOrEmpty()) { var menupPathChunk = XmlHelpers.CreateChunk(actionId); pathToTheRoot = pathToTheRoot.Replace("ReSharper | Navigate ", "%navigateMenu%") .Replace("ReSharper | Windows ", "%windowsMenu%"); menupPathChunk.Add(new XElement("menupath", pathToTheRoot)); accessIntroWrapper.Add(new XElement("menupath", pathToTheRoot)); accessIntroWrapper.Add(new XElement("br")); menuPathLibrary.Root.Add(menupPathChunk); } if (ideaShortcuts != null || vsShortcuts != null) { accessIntroWrapper.Add(new XElement("shortcut", new XAttribute("key", actionId))); accessIntroWrapper.Add(new XElement("br")); } accessIntroWrapper.Add(new XElement("code", String.Format("ReSharper_{0}", actionId), new XAttribute("product", "rs,dcv"))); accessIntroChunk.Add(accessIntroWrapper); accessIntroLibrary.Root.Add(accessIntroChunk); AddShortcuts(ideaShortcuts, actionElement, "rs"); AddShortcuts(vsShortcuts, actionElement, "vs"); if (actionId == "ParameterInfoShow") { actionElement.Add(new XElement("Shortcut", "Control+Shift+Space", new XAttribute("layout", "vs"))); } if (actionId == "GotoDeclaration") { actionElement.Add(new XElement("Shortcut", "F12", new XAttribute("layout", "vs"))); } if (actionId == "GotoImplementation") { actionElement.Add(new XElement("Shortcut", "Ctrl+F12", new XAttribute("layout", "vs"))); } // TODO: check if this hack works actionMapElement.Add(actionElement); } shortcutsXmlDoc.Save(Path.Combine(outputFolder, "keymap.xml")); menuPathLibrary.Save(Path.Combine(outputFolder, menuPathLibId + ".xml")); accessIntroLibrary.Save(Path.Combine(outputFolder, accessIntroLibId + ".xml")); return("Shortcuts and actions"); }
protected override string GenerateContent(IDataContext context, string outputFolder) { const string caTopicId = "Fix_in_Scope_Chunks"; var inScopeLibrary = XmlHelpers.CreateHmTopic(caTopicId); var qfChunk = XmlHelpers.CreateChunk("qf_list"); var caChunk = XmlHelpers.CreateChunk("ca_list"); var qfListByLang = new List <Tuple <string, XElement> >(); var caListByLang = new List <Tuple <string, XElement> >(); var qfLists = new Dictionary <string, XElement>(); var caLists = new Dictionary <string, XElement>(); foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies()) { Type[] types; try { types = assembly.GetTypes(); } catch (Exception e) { continue; } foreach (var type in types) { if (typeof(IBulkAction).IsAssignableFrom(type) && !type.IsInterface && !type.IsAbstract) { var text = ""; try { text = type.GetProperty("BulkText") .GetValue(FormatterServices.GetUninitializedObject(type), null) .ToString(); } catch (Exception) { try { text = type.GetProperty("Text") .GetValue(FormatterServices.GetUninitializedObject(type), null) .ToString(); } catch (Exception) { // ignored } } var actionElement = new XElement("li", text + Environment.NewLine, new XComment(type.FullName), XmlHelpers.CreateInclude("Fix_in_Scope_Static_Chunks", type.FullName.NormalizeStringForAttribute())); var lang = GeneralHelpers.TryGetLang(type.FullName); if (typeof(IContextAction).IsAssignableFrom(type)) { caListByLang.Add(new Tuple <string, XElement>(lang, actionElement)); if (!caLists.ContainsKey(lang)) { caLists.Add(lang, new XElement("list")); } } if (typeof(IQuickFix).IsAssignableFrom(type)) { qfListByLang.Add(new Tuple <string, XElement>(lang, actionElement)); if (!qfLists.ContainsKey(lang)) { qfLists.Add(lang, new XElement("list")); } } } } } foreach (var list in qfLists) { foreach (var qfListItem in qfListByLang) { if (list.Key == qfListItem.Item1) { list.Value.Add(qfListItem.Item2); } } var langChapter = XmlHelpers.CreateChapter(list.Key); langChapter.Add(list.Value); qfChunk.Add(langChapter); } foreach (var list in caLists) { foreach (var qfListItem in caListByLang) { if (list.Key == qfListItem.Item1) { list.Value.Add(qfListItem.Item2); } } var langChapter = XmlHelpers.CreateChapter(list.Key); langChapter.Add(list.Value); caChunk.Add(langChapter); } inScopeLibrary.Root.Add(new XComment("Total quick-fix in scope: " + qfListByLang.Count())); inScopeLibrary.Root.Add(new XComment("Total context actions in scope: " + caListByLang.Count())); inScopeLibrary.Root.Add(qfChunk); inScopeLibrary.Root.Add(caChunk); inScopeLibrary.Save(Path.Combine(outputFolder, caTopicId + ".xml")); return("Fix in scope actions"); }
protected override string GenerateContent(IDataContext context, string outputFolder) { const string macroTopicId = "Template_Macros"; var macroLibrary = XmlHelpers.CreateHmTopic(macroTopicId); var macroChunk = XmlHelpers.CreateChunk("macro_table"); var macroTable = XmlHelpers.CreateTable(new[] { "Expression", "Description", "Details" }, null); var macros = Shell.Instance.GetComponent <MacroManager>().Definitions; foreach (var macroDefinition in macros) { var macroRow = new XElement("tr"); var longDescription = MacroDescriptionFormatter.GetMacroAttribute(macroDefinition).LongDescription; var shortDescription = MacroDescriptionFormatter.GetMacroAttribute(macroDefinition).ShortDescription; var macroId = MacroDescriptionFormatter.GetMacroAttribute(macroDefinition).Name; const string paramMatch = @"{#0:(.*)}"; var parameters = macroDefinition.Parameters; MatchCollection paramNames = null; if (shortDescription != null) { paramNames = Regex.Matches(shortDescription, paramMatch); shortDescription = Regex.Replace(shortDescription, paramMatch, @"<b>$+</b>"); } var expressionCellRaw = "<td><code>" + macroId + "()" + "</code></td>"; var expressionCell = XElement.Parse(expressionCellRaw); expressionCell.Add(new XAttribute("id", macroId)); var shortDescriptionCellRaw = "<td>" + shortDescription + "</td>"; var shortDescriptionCell = XElement.Parse(shortDescriptionCellRaw); var paramNode = new XElement("list"); if (paramNames != null) { for (int idx = 0; idx < paramNames.Count; idx++) { var parameterInfo = parameters[idx]; paramNode.Add(new XElement("li", new XElement("b", paramNames[idx].Groups[1].Value), GetParameterAsString(parameterInfo.ParameterType))); } } var paramHeader = paramNode.HasElements ? new XElement("p", "Macro parameters:") : null; macroRow.Add(expressionCell, shortDescriptionCell, new XElement("td", longDescription, paramHeader, paramNode, XmlHelpers.CreateInclude("TR", "macros_" + macroId))); macroTable.Add(macroRow); } macroChunk.Add(macroTable); macroLibrary.Root.Add(XmlHelpers.CreateInclude("Templates__Template_Basics__Template_Macros", "intro")); macroLibrary.Root.Add(new XElement("p", "Here is the full list of template macros provided by ReSharper:")); macroLibrary.Root.Add(macroChunk); macroLibrary.Save(Path.Combine(outputFolder, macroTopicId + ".xml")); return("Template macros"); }