示例#1
0
        HtmlElementInfo GenerateHyperlinkForReference(ReferenceSymbol symbol)
        {
            string idHash = symbol.Id.Value;

            bool isMsBuild = _sourceFile.SourceFile.Info.Language == "msbuild";
            bool isDistributedDefinition =
                symbol.Kind == nameof(SymbolKinds.MSBuildItem) ||
                symbol.Kind == nameof(SymbolKinds.MSBuildItemMetadata) ||
                symbol.Kind == nameof(SymbolKinds.MSBuildProperty) ||
                symbol.Kind == nameof(SymbolKinds.MSBuildTarget) ||
                symbol.Kind == nameof(SymbolKinds.MSBuildTask) ||
                symbol.Kind == nameof(SymbolKinds.MSBuildTaskParameter);
            var isDefinition = symbol.ReferenceKind == nameof(ReferenceKind.Definition) || isDistributedDefinition;

            bool isProjectScopedReference = symbol.ReferenceKind == nameof(ReferenceKind.ProjectLevelReference);

            if (!isDefinition)
            {
                idHash = null;
            }

            string jsmethod         = isDefinition || isProjectScopedReference ? "R" : "D";
            string additionalParams = isProjectScopedReference ? $@", '{projectId}'" : string.Empty;
            string onclick          = $@"{jsmethod}('{symbol.ProjectId}', '{symbol.Id}'{additionalParams});return false;";

            string url = "";

            if (isDefinition)
            {
                url = $"/?leftProject={symbol.ProjectId}&leftSymbol={symbol.Id}&file={HttpUtility.UrlEncode(this._sourceFile.SourceFile.Info.Path)}";
            }
            else if (isProjectScopedReference)
            {
                url = $"/?leftProject={symbol.ProjectId}&leftSymbol={symbol.Id}&projectScope={projectId}";
            }
            else
            {
                url = $"/?rightProject={symbol.ProjectId}&rightSymbol={symbol.Id}";
            }

            var result = new HtmlElementInfo()
            {
                Name       = "a",
                Attributes =
                {
                    { "id",      idHash                                         },
                    { "onclick", onclick                                        },
                    { "href",    url                                            },
                    { "class",   isDistributedDefinition ? "msbuildlink" : null }
                },
                DeclaredSymbolId     = symbol.Id.Value,
                RequiresWrappingSpan = isMsBuild,
            };

            return(result);
        }
示例#2
0
        void WriteHtmlElement(TextWriter tw, HtmlElementInfo htmlElementInfo, string innerText)
        {
            tw.Write("<" + htmlElementInfo.Name);
            foreach (var att in htmlElementInfo.Attributes)
            {
                AddAttribute(tw, att.Key, att.Value);
            }

            tw.Write(">");
            HttpUtility.HtmlEncode(innerText, tw);
            tw.Write("</" + htmlElementInfo.Name + ">");
        }
示例#3
0
        private void GenerateSpan(TextWriter tw, ClassificationSpan span, string spanText, ref int referenceIndex, ref ReferenceSpan currentReference, IReadOnlyList <ReferenceSpan> referenceSpans)
        {
            while ((currentReference == null || currentReference.Start < span.Start) && referenceIndex < referenceSpans.Count)
            {
                referenceIndex++;
                if (referenceIndex < referenceSpans.Count)
                {
                    currentReference = referenceSpans[referenceIndex];
                }
                else
                {
                    currentReference = null;
                }
            }

            if (currentReference != null)
            {
                GetBestReference(ref referenceIndex, ref currentReference, referenceSpans);
            }

            string cssClass       = MapClassificationToCssClass(span.Classification);
            string referenceClass = string.Empty;

            if (span.LocalGroupId > 0)
            {
                referenceClass = $"r{span.LocalGroupId} r";
                cssClass       = string.IsNullOrEmpty(cssClass) ? referenceClass : $"{referenceClass} {cssClass}";
            }

            HtmlElementInfo htmlElementInfo = null;

            if (currentReference?.SpanEquals(span) == true)
            {
                htmlElementInfo = GenerateHyperlinkForReference(currentReference.Reference);
            }

            if (htmlElementInfo == null && !span.Contains(currentReference))
            {
                if (cssClass == null)
                {
                    tw.Write(HttpUtility.HtmlEncode(spanText));
                    return;
                }
            }

            string elementName             = "span";
            bool   classAttributeSpecified = false;

            if (htmlElementInfo != null)
            {
                elementName = htmlElementInfo.Name;

                if (htmlElementInfo.RequiresWrappingSpan)
                {
                    tw.Write("<span");
                    AddAttribute(tw, "class", cssClass);
                    tw.Write(">");
                    classAttributeSpecified = true;
                }
            }

            tw.Write("<" + elementName);

            if (htmlElementInfo != null)
            {
                foreach (var attribute in htmlElementInfo.Attributes)
                {
                    if (AddAttribute(tw, attribute.Key, attribute.Value))
                    {
                        if (attribute.Key == "class")
                        {
                            classAttributeSpecified = true;
                        }
                    }
                }
            }

            if (!classAttributeSpecified)
            {
                AddAttribute(tw, "class", cssClass);
            }

            if (span.LocalGroupId > 0 && (htmlElementInfo?.Attributes?.ContainsKey("onclick") != true))
            {
                AddAttribute(tw, "onclick", "t(this);");
            }

            tw.Write(">");
            if (htmlElementInfo != null || !span.Contains(currentReference))
            {
                tw.Write(HttpUtility.HtmlEncode(spanText));
            }
            else
            {
                WriteReferenceText(tw, span, spanText, ref referenceIndex, ref currentReference, referenceSpans);
            }

            tw.Write("</" + elementName + ">");

            if (htmlElementInfo?.RequiresWrappingSpan == true)
            {
                tw.Write("</span>");
            }
        }