diff --git a/src/dotnet/APIView/APIView/CodeFileHtmlRenderer.cs b/src/dotnet/APIView/APIView/CodeFileHtmlRenderer.cs index 082a6568379..70cd01bbbd1 100644 --- a/src/dotnet/APIView/APIView/CodeFileHtmlRenderer.cs +++ b/src/dotnet/APIView/APIView/CodeFileHtmlRenderer.cs @@ -18,7 +18,7 @@ protected CodeFileHtmlRenderer(bool readOnly) public static CodeFileHtmlRenderer Normal { get; } = new CodeFileHtmlRenderer(false); public static CodeFileHtmlRenderer ReadOnly { get; } = new CodeFileHtmlRenderer(true); - protected override void RenderToken(CodeFileToken token, StringBuilder stringBuilder) + protected override void RenderToken(CodeFileToken token, StringBuilder stringBuilder, bool isDeprecatedToken, bool isDocumentation) { if (token.Value == null) { @@ -47,6 +47,16 @@ protected override void RenderToken(CodeFileToken token, StringBuilder stringBui break; } + if (isDeprecatedToken) + { + elementClass += " deprecated"; + } + + if (isDocumentation) + { + elementClass += " documentation"; + } + string href = null; if (token.DefinitionId != null && !_readOnly) diff --git a/src/dotnet/APIView/APIView/CodeFileRenderer.cs b/src/dotnet/APIView/APIView/CodeFileRenderer.cs index f09010fcca3..bb1048ff7db 100644 --- a/src/dotnet/APIView/APIView/CodeFileRenderer.cs +++ b/src/dotnet/APIView/APIView/CodeFileRenderer.cs @@ -22,27 +22,47 @@ private void Render(List list, IEnumerable node) { var stringBuilder = new StringBuilder(); string currentId = null; + bool isDocumentation = false; + bool isDeprecatedToken = false; + foreach (var token in node) { - if (token.Kind == CodeFileTokenKind.Newline) - { - list.Add(new CodeLine(stringBuilder.ToString(), currentId)); - currentId = null; - stringBuilder.Clear(); - } - else + switch(token.Kind) { - if (token.DefinitionId != null) - { - currentId = token.DefinitionId; - } + case CodeFileTokenKind.Newline: + list.Add(new CodeLine(stringBuilder.ToString(), currentId)); + currentId = null; + stringBuilder.Clear(); + break; + + case CodeFileTokenKind.DocumentRangeStart: + isDocumentation = true; + break; + + case CodeFileTokenKind.DocumentRangeEnd: + isDocumentation = false; + break; + + case CodeFileTokenKind.DeprecatedRangeStart: + isDeprecatedToken = true; + break; + + case CodeFileTokenKind.DeprecatedRangeEnd: + isDeprecatedToken = false; + break; - RenderToken(token, stringBuilder); - } + default: + if (token.DefinitionId != null) + { + currentId = token.DefinitionId; + } + RenderToken(token, stringBuilder, isDeprecatedToken, isDocumentation); + break; + } } } - protected virtual void RenderToken(CodeFileToken token, StringBuilder stringBuilder) + protected virtual void RenderToken(CodeFileToken token, StringBuilder stringBuilder, bool isDeprecatedToken, bool isDocumentation) { if (token.Value != null) { diff --git a/src/dotnet/APIView/APIView/CodeLine.cs b/src/dotnet/APIView/APIView/CodeLine.cs index 73b1c45c168..45effeaefe2 100644 --- a/src/dotnet/APIView/APIView/CodeLine.cs +++ b/src/dotnet/APIView/APIView/CodeLine.cs @@ -6,7 +6,6 @@ public readonly struct CodeLine { public string DisplayString { get; } public string ElementId { get; } - public CodeLine(string html, string id) { this.DisplayString = html; diff --git a/src/dotnet/APIView/APIView/Model/CodeFileTokenKind.cs b/src/dotnet/APIView/APIView/Model/CodeFileTokenKind.cs index b6c58ccee9e..87b0a91b35d 100644 --- a/src/dotnet/APIView/APIView/Model/CodeFileTokenKind.cs +++ b/src/dotnet/APIView/APIView/Model/CodeFileTokenKind.cs @@ -14,6 +14,10 @@ public enum CodeFileTokenKind MemberName = 7, StringLiteral = 8, Literal = 9, - Comment = 10 + Comment = 10, + DocumentRangeStart = 11, + DocumentRangeEnd = 12, + DeprecatedRangeStart = 13, + DeprecatedRangeEnd = 14 } } \ No newline at end of file diff --git a/src/dotnet/APIView/APIViewWeb/APIViewWeb.csproj b/src/dotnet/APIView/APIViewWeb/APIViewWeb.csproj index 3bb25bb6069..9bbdfa729b5 100644 --- a/src/dotnet/APIView/APIViewWeb/APIViewWeb.csproj +++ b/src/dotnet/APIView/APIViewWeb/APIViewWeb.csproj @@ -38,5 +38,4 @@ - diff --git a/src/dotnet/APIView/APIViewWeb/Client/css/site.scss b/src/dotnet/APIView/APIViewWeb/Client/css/site.scss index 31589c250a9..63d29e1ad83 100644 --- a/src/dotnet/APIView/APIViewWeb/Client/css/site.scss +++ b/src/dotnet/APIView/APIViewWeb/Client/css/site.scss @@ -515,4 +515,12 @@ code-inner { } .code-removed { background-color: #ffeef0; +} + +.deprecated { + text-decoration: line-through; +} + +.documentation { + display: none; } \ No newline at end of file diff --git a/src/dotnet/APIView/APIViewWeb/Client/src/documentation.ts b/src/dotnet/APIView/APIViewWeb/Client/src/documentation.ts new file mode 100644 index 00000000000..93b8d7dc0a0 --- /dev/null +++ b/src/dotnet/APIView/APIViewWeb/Client/src/documentation.ts @@ -0,0 +1,36 @@ +$(() => { + const SEL_DOC_CLASS = ".documentation"; + const SHOW_DOC_CHECKBOX = "#show-documentation-checkbox"; + const SHOW_DOC_CHECK_COMPONENT = "#show-documentation-component"; + const SEL_CODE_INNER_CLASS = ".code-inner"; + const SEL_CODE_LINE = ".code-line"; + + hideCheckboxIfNoDocs(); + toggleEmptyLineVisibility(false); + + $(document).on("click", SHOW_DOC_CHECKBOX, e => { + toggleAllDocumentationVisibility(e.target.checked); + }); + + function hideCheckboxIfNoDocs() { + if ($(SEL_DOC_CLASS).length == 0) { + $(SHOW_DOC_CHECK_COMPONENT).hide(); + } + } + + function toggleEmptyLineVisibility(showDocuments: boolean) { + //If code line only has documentation then toggle that line + $(SEL_CODE_LINE).each(function () { + var tokenElements = $(this).find(SEL_CODE_INNER_CLASS).children(); + //Checking atleast one doc node is present to avoid hiding explicit empty lines + if (tokenElements.filter(SEL_DOC_CLASS).length > 0 && tokenElements.not(SEL_DOC_CLASS).length == 0) { + $(this).toggle(showDocuments); + } + }); + } + + function toggleAllDocumentationVisibility(showDocuments: boolean) { + $(SEL_DOC_CLASS).toggle(showDocuments); + toggleEmptyLineVisibility(showDocuments); + } +}); diff --git a/src/dotnet/APIView/APIViewWeb/Client/src/main.ts b/src/dotnet/APIView/APIViewWeb/Client/src/main.ts index 8fce9924725..5fb0df42f8c 100644 --- a/src/dotnet/APIView/APIViewWeb/Client/src/main.ts +++ b/src/dotnet/APIView/APIViewWeb/Client/src/main.ts @@ -2,3 +2,4 @@ import "./comments.ts"; import "./revisions.ts"; import "./file-input.ts"; import "./navbar.ts"; +import "./documentation.ts"; diff --git a/src/dotnet/APIView/APIViewWeb/Pages/Assemblies/Review.cshtml b/src/dotnet/APIView/APIViewWeb/Pages/Assemblies/Review.cshtml index 04a043d168e..97b05a449e2 100644 --- a/src/dotnet/APIView/APIViewWeb/Pages/Assemblies/Review.cshtml +++ b/src/dotnet/APIView/APIViewWeb/Pages/Assemblies/Review.cshtml @@ -88,6 +88,12 @@ Show comments + + +