コード例 #1
0
        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");
        }
コード例 #2
0
        private static void AddTemplateRow(Dictionary <string, XElement> tables,
                                           List <Tuple <string, XElement> > summaryItems,
                                           string lang, string templateId, Template template,
                                           string scopeString, XElement paramElement, string type, string imported)
        {
            if (!imported.IsNullOrEmpty())
            {
                imported = String.Format(" ({0})", imported);
            }
            var templateIdFull = (type + "_" + templateId + "_" + lang).NormalizeStringForAttribute();


            var noDescriptionFallback = (template.Description.IsNullOrEmpty() || type == "File" || type == "Surround") &&
                                        !template.Description.Contains(' ')
        ? XmlHelpers.CreateInclude("TR", templateIdFull + "_desc")
        : template.Description as object;

            var paramHeader = new XElement("p");

            if (paramElement.HasElements)
            {
                paramHeader.Add(new XElement("b", "Parameters "));
            }

            tables.GetValue(lang).Add(new XElement("tr",
                                                   new XElement("td",
                                                                new XElement("code", templateId), imported,
                                                                new XAttribute("id", templateIdFull)),
                                                   new XElement("td",
                                                                new XElement("p", noDescriptionFallback),
                                                                new XElement("p", new XElement("b", "Scope "), scopeString),
                                                                new XElement("p", new XElement("b", "Body ")),
                                                                XmlHelpers.CreateCodeBlock(template.Text, lang),
                                                                paramHeader,
                                                                paramElement,
                                                                XmlHelpers.CreateInclude("TR", templateIdFull))));

            summaryItems.Add(
                new Tuple <string, XElement>(lang, new XElement("tr",
                                                                new XElement("td",
                                                                             XmlHelpers.CreateHyperlink(templateId, CreateTopicIdForTypeAndLang(lang, type), templateIdFull), imported),
                                                                new XElement("td", noDescriptionFallback))));
        }
コード例 #3
0
        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");
        }
コード例 #4
0
        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");
        }
コード例 #5
0
        private void CreateXml(TemplateApplicability applicability, IContextBoundSettingsStore bound,
                               string saveDirectoryPath, string version, IDataContext context)
        {
            string      type;
            ScopeFilter scopeFilter = ScopeFilter.Language;

            switch (applicability)
            {
            case TemplateApplicability.Live:
                type = "Live";
                break;

            case TemplateApplicability.Surround:
                type = "Surround";
                break;

            case TemplateApplicability.File:
                type        = "File";
                scopeFilter = ScopeFilter.Project;
                break;

            default: return;
            }

            var topicId   = "Reference__Templates_Explorer__" + type + "_Templates";
            var fileName  = Path.Combine(saveDirectoryPath, topicId + ".xml");
            var topic     = XmlHelpers.CreateHmTopic(topicId);
            var topicRoot = topic.Root;

            topicRoot.Add(new XElement("p",
                                       new XElement("menupath", "ReSharper | Templates Explorer | " + type + " Templates")));

            topicRoot.Add(new XElement("p",
                                       "This section lists all predefined " + type + " templates in ReSharper " + version + "."));

            topicRoot.Add(new XElement("p", XmlHelpers.CreateInclude("Templates__Template_Basics__Template_Types", type)));
            var summaryTable     = XmlHelpers.CreateTable(new[] { "Template", "Description" }, new[] { "20%", "80%" });
            var summaryItems     = new List <Tuple <string, XElement> >();
            var tables           = new Dictionary <string, XElement>();
            var defaultTemplates = context.GetComponent <StoredTemplatesProvider>()
                                   .EnumerateTemplates(bound, applicability, false);

            var myScopeCategoryManager = context.GetComponent <ScopeCategoryManager>();

            foreach (var template in defaultTemplates)
            {
                var templateIdPresentable = !template.Shortcut.IsNullOrEmpty() ? template.Shortcut : template.Description;
                templateIdPresentable = Regex.Replace(templateIdPresentable, "&Enum", "Enum");
                var currentTemplateLangs = new List <string>();
                var imported             = String.Empty;
                var scopeString          = String.Empty;
                var cat = String.Empty;

                foreach (var category in template.Categories)
                {
                    if (category.Contains("Imported"))
                    {
                        imported = category;
                        break;
                    }
                    if (category.Contains("C#"))
                    {
                        cat = "C#";
                    }
                    if (category.Contains("VB.NET"))
                    {
                        cat = "VB.NET";
                    }
                }

                foreach (var point in template.ScopePoints)
                {
                    foreach (var provider in myScopeCategoryManager.GetCoveredProviders(scopeFilter, point))
                    {
                        var lang = provider.CategoryCaption;
                        if (lang == "ASP.NET" && type == "Surround" && !cat.IsNullOrEmpty())
                        {
                            lang = lang + "(" + cat + ")";
                        }
                        if (!lang.IsNullOrEmpty())
                        {
                            currentTemplateLangs.Add(lang);
                            if (!tables.ContainsKey(lang))
                            {
                                tables.Add(lang, XmlHelpers.CreateTable(new[] { "Template", "Details" }, new[] { "20%", "80%" }));
                            }
                        }
                    }

                    if (currentTemplateLangs.Count == 0)
                    {
                        MessageBox.ShowExclamation(String.Format("The '{0}' template has no associated languages",
                                                                 templateIdPresentable));
                    }

                    scopeString += " " + point.PresentableShortName + ",";
                }

                scopeString = scopeString.TrimEnd(',');

                var paramElement = new XElement("list");
                foreach (var param in template.Fields)
                {
                    var expr             = param.Expression as MacroCallExpressionNew;
                    var paramItemElement = new XElement("li", new XElement("code", param.Name));
                    if (expr != null)
                    {
                        var macro = MacroDescriptionFormatter.GetMacroAttribute(expr.Definition);
                        paramItemElement.Add(" - " + macro.LongDescription + " (",
                                             XmlHelpers.CreateHyperlink(macro.Name, "Template_Macros", macro.Name),
                                             ")");
                    }
                    else
                    {
                        paramItemElement.Add(" - " + "no macro");
                    }
                    paramElement.Add(paramItemElement);
                }

                if (template.Text.Contains("$SELECTION$"))
                {
                    paramElement.Add(new XElement("li",
                                                  new XElement("code", "SELECTION"), " - The text selected by the user before invoking the template."));
                }

                if (template.Text.Contains("$END$"))
                {
                    paramElement.Add(new XElement("li",
                                                  new XElement("code", "END"), " - The caret position after the template is applied."));
                }

                var processedLangs = new List <string>();

                foreach (var lang in currentTemplateLangs)
                {
                    if (!processedLangs.Contains(lang))
                    {
                        AddTemplateRow(tables, summaryItems, lang, templateIdPresentable, template, scopeString, paramElement, type,
                                       imported);
                        processedLangs.Add(lang);
                    }
                }
            }

            foreach (var table in tables)
            {
                summaryTable.Add(new XElement("tr",
                                              new XElement("td",
                                                           new XAttribute("colspan", "2"),
                                                           new XElement("b", table.Key))));

                foreach (var item in summaryItems)
                {
                    if (item.Item1 == table.Key)
                    {
                        summaryTable.Add(item.Item2);
                    }
                }

                var langForHeading = table.Key;
                if (langForHeading == "Global")
                {
                    langForHeading = "Global Usage";
                }
                CreateTopicForLang(langForHeading, type, table.Value, saveDirectoryPath, version);
            }

            var indexChapter = XmlHelpers.CreateChapter(String.Format("Index of {0} Templates", type));

            topicRoot.Add(new XComment("Total " + type + " templates: " + summaryItems.Count));
            indexChapter.Add(summaryTable);
            topicRoot.Add(indexChapter);
            topic.Save(fileName);
        }