From a50c487f6be3025479aded1bbf7a793ded024837 Mon Sep 17 00:00:00 2001 From: Jordi Ramos Date: Thu, 25 Jan 2024 11:39:46 -0800 Subject: [PATCH 1/5] Update DefaultLSPTagHelperTooltipFactory.cs Make the tooltip show the full tagHelperTypeName instead of the reduced name in LSP factory. This method is used in both hover service and code completion service. --- .../Tooltip/DefaultLSPTagHelperTooltipFactory.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Tooltip/DefaultLSPTagHelperTooltipFactory.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Tooltip/DefaultLSPTagHelperTooltipFactory.cs index 601c2834796..1999c1fe59d 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Tooltip/DefaultLSPTagHelperTooltipFactory.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Tooltip/DefaultLSPTagHelperTooltipFactory.cs @@ -50,9 +50,8 @@ public override bool TryCreateTooltip( } var tagHelperType = descriptionInfo.TagHelperTypeName; - var reducedTypeName = ReduceTypeName(tagHelperType); StartOrEndBold(descriptionBuilder, markupKind); - descriptionBuilder.Append(reducedTypeName); + descriptionBuilder.Append(tagHelperType); StartOrEndBold(descriptionBuilder, markupKind); var documentation = descriptionInfo.Documentation; From 7a99d7bffc880fce72cecb74799b1034094d1941 Mon Sep 17 00:00:00 2001 From: Jordi Ramos Date: Fri, 26 Jan 2024 13:21:48 -0800 Subject: [PATCH 2/5] Changed united tests for hover -DefaultLSPTagHelperTooltopFactoryTest.cs: changed three unit tests so we are testing for showing the full name space - HoverInfoServiceTest.cs: changed the test to match the scenario of child hover show the namespce of parent. --- .../Completion/DefaultLSPTagHelperTooltipFactoryTest.cs | 8 ++++---- .../Hover/HoverInfoServiceTest.cs | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Completion/DefaultLSPTagHelperTooltipFactoryTest.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Completion/DefaultLSPTagHelperTooltipFactoryTest.cs index 970a66c815c..b8f79547800 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Completion/DefaultLSPTagHelperTooltipFactoryTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Completion/DefaultLSPTagHelperTooltipFactoryTest.cs @@ -92,7 +92,7 @@ public void TryCreateTooltip_Markup_Element_SingleAssociatedTagHelper_ReturnsTru // Assert Assert.True(result); - Assert.Equal(@"**SomeTagHelper** + Assert.Equal(@"**Microsoft.AspNetCore.SomeTagHelper** Uses `List`s", markdown.Value); Assert.Equal(MarkupKind.Markdown, markdown.Kind); @@ -115,7 +115,7 @@ public void TryCreateTooltip_Markup_Element_PlainText_NoBold() // Assert Assert.True(result, "TryCreateTooltip should have succeeded"); - Assert.Equal(@"SomeTagHelper + Assert.Equal(@"Microsoft.AspNetCore.SomeTagHelper Uses `List`s", markdown.Value); Assert.Equal(MarkupKind.PlainText, markdown.Kind); @@ -166,11 +166,11 @@ public void TryCreateTooltip_Markup_Element_MultipleAssociatedTagHelpers_Returns // Assert Assert.True(result); - Assert.Equal(@"**SomeTagHelper** + Assert.Equal(@"**Microsoft.AspNetCore.SomeTagHelper** Uses `List`s --- -**OtherTagHelper** +**Microsoft.AspNetCore.OtherTagHelper** Also uses `List`s", markdown.Value); Assert.Equal(MarkupKind.Markdown, markdown.Kind); diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Hover/HoverInfoServiceTest.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Hover/HoverInfoServiceTest.cs index d1a7cd6c04d..ed3f4f9d355 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Hover/HoverInfoServiceTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Hover/HoverInfoServiceTest.cs @@ -101,8 +101,8 @@ public void GetHoverInfo_TagHelper_Element_WithParent() // Act var hover = service.GetHoverInfo("file.cshtml", codeDocument, location, CreateMarkDownCapabilities()); - // Assert - Assert.Contains("**SomeChild**", ((MarkupContent)hover.Contents).Value, StringComparison.Ordinal); + // Assert addTagHelper.SomeChild + Assert.Contains("SomeChild**", ((MarkupContent)hover.Contents).Value, StringComparison.Ordinal); var expectedRange = new Range { Start = new Position(2, 5), From 64b28a03666fddd8cc31405a60178d439007ee3d Mon Sep 17 00:00:00 2001 From: Jordi Ramos Date: Mon, 29 Jan 2024 10:46:17 -0800 Subject: [PATCH 3/5] make only the final tagHelperType name bold - implemented simple logic to make the reducedTypeName bold while still keeping the namespace but leaving it intact - changed unit tests in DefaultLSPTagHelperTooltipFactoryTest and HomeInfoServiceTest to reflect such desired behavior --- .../Tooltip/DefaultLSPTagHelperTooltipFactory.cs | 14 +++++++++++++- .../DefaultLSPTagHelperTooltipFactoryTest.cs | 6 +++--- .../Hover/HoverInfoServiceTest.cs | 2 +- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Tooltip/DefaultLSPTagHelperTooltipFactory.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Tooltip/DefaultLSPTagHelperTooltipFactory.cs index 1999c1fe59d..1ee6020dfae 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Tooltip/DefaultLSPTagHelperTooltipFactory.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Tooltip/DefaultLSPTagHelperTooltipFactory.cs @@ -50,8 +50,20 @@ public override bool TryCreateTooltip( } var tagHelperType = descriptionInfo.TagHelperTypeName; + var reducedTypeName = ReduceTypeName(tagHelperType); + + // If the reducedTypeName != tagHelperType, then the type is prefixed by a namespace + if (reducedTypeName != tagHelperType) + { + var removeStartIndex = tagHelperType.Length - reducedTypeName.Length; + var TypeNamespace = tagHelperType.Remove(removeStartIndex, reducedTypeName.Length); + descriptionBuilder.Append(TypeNamespace); + + } + + // We make the reducedTypeName bold while leaving the namespace the intact StartOrEndBold(descriptionBuilder, markupKind); - descriptionBuilder.Append(tagHelperType); + descriptionBuilder.Append(reducedTypeName); StartOrEndBold(descriptionBuilder, markupKind); var documentation = descriptionInfo.Documentation; diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Completion/DefaultLSPTagHelperTooltipFactoryTest.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Completion/DefaultLSPTagHelperTooltipFactoryTest.cs index b8f79547800..5bcc30bdaf8 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Completion/DefaultLSPTagHelperTooltipFactoryTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Completion/DefaultLSPTagHelperTooltipFactoryTest.cs @@ -92,7 +92,7 @@ public void TryCreateTooltip_Markup_Element_SingleAssociatedTagHelper_ReturnsTru // Assert Assert.True(result); - Assert.Equal(@"**Microsoft.AspNetCore.SomeTagHelper** + Assert.Equal(@"Microsoft.AspNetCore.**SomeTagHelper** Uses `List`s", markdown.Value); Assert.Equal(MarkupKind.Markdown, markdown.Kind); @@ -166,11 +166,11 @@ public void TryCreateTooltip_Markup_Element_MultipleAssociatedTagHelpers_Returns // Assert Assert.True(result); - Assert.Equal(@"**Microsoft.AspNetCore.SomeTagHelper** + Assert.Equal(@"Microsoft.AspNetCore.**SomeTagHelper** Uses `List`s --- -**Microsoft.AspNetCore.OtherTagHelper** +Microsoft.AspNetCore.**OtherTagHelper** Also uses `List`s", markdown.Value); Assert.Equal(MarkupKind.Markdown, markdown.Kind); diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Hover/HoverInfoServiceTest.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Hover/HoverInfoServiceTest.cs index ed3f4f9d355..947ed3f52b6 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Hover/HoverInfoServiceTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Hover/HoverInfoServiceTest.cs @@ -102,7 +102,7 @@ public void GetHoverInfo_TagHelper_Element_WithParent() var hover = service.GetHoverInfo("file.cshtml", codeDocument, location, CreateMarkDownCapabilities()); // Assert addTagHelper.SomeChild - Assert.Contains("SomeChild**", ((MarkupContent)hover.Contents).Value, StringComparison.Ordinal); + Assert.Contains("**SomeChild**", ((MarkupContent)hover.Contents).Value, StringComparison.Ordinal); var expectedRange = new Range { Start = new Position(2, 5), From 86b3c808e4a73419f03986c4f24a6591ad8123fd Mon Sep 17 00:00:00 2001 From: Jordi Ramos Date: Mon, 29 Jan 2024 13:51:44 -0800 Subject: [PATCH 4/5] Using the range operator - using the range operator instead for getting the namespace of the TagHelper - other fixes: reducing extra white line, fixing comment --- .../Tooltip/DefaultLSPTagHelperTooltipFactory.cs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Tooltip/DefaultLSPTagHelperTooltipFactory.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Tooltip/DefaultLSPTagHelperTooltipFactory.cs index 1ee6020dfae..673a0d888a2 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Tooltip/DefaultLSPTagHelperTooltipFactory.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Tooltip/DefaultLSPTagHelperTooltipFactory.cs @@ -55,13 +55,10 @@ public override bool TryCreateTooltip( // If the reducedTypeName != tagHelperType, then the type is prefixed by a namespace if (reducedTypeName != tagHelperType) { - var removeStartIndex = tagHelperType.Length - reducedTypeName.Length; - var TypeNamespace = tagHelperType.Remove(removeStartIndex, reducedTypeName.Length); - descriptionBuilder.Append(TypeNamespace); - + descriptionBuilder.Append(tagHelperType[..^reducedTypeName.Length]); } - // We make the reducedTypeName bold while leaving the namespace the intact + // We make the reducedTypeName bold while leaving the namespace intact StartOrEndBold(descriptionBuilder, markupKind); descriptionBuilder.Append(reducedTypeName); StartOrEndBold(descriptionBuilder, markupKind); From 1dd03561d7e806a86e2d7bff9b4b5a37b95e0019 Mon Sep 17 00:00:00 2001 From: Jordi Ramos Date: Mon, 29 Jan 2024 14:46:32 -0800 Subject: [PATCH 5/5] Update HoverInfoServiceTest.cs deleted an extra comment --- .../Hover/HoverInfoServiceTest.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Hover/HoverInfoServiceTest.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Hover/HoverInfoServiceTest.cs index 947ed3f52b6..d1a7cd6c04d 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Hover/HoverInfoServiceTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Hover/HoverInfoServiceTest.cs @@ -101,7 +101,7 @@ public void GetHoverInfo_TagHelper_Element_WithParent() // Act var hover = service.GetHoverInfo("file.cshtml", codeDocument, location, CreateMarkDownCapabilities()); - // Assert addTagHelper.SomeChild + // Assert Assert.Contains("**SomeChild**", ((MarkupContent)hover.Contents).Value, StringComparison.Ordinal); var expectedRange = new Range {