Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not put an equals and quotes when completing an xml attribute if present #72508

Merged
merged 8 commits into from
Mar 21, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,35 @@ static void Goo()
""", "cref", "langword", "href");
}

[Fact, WorkItem("https://github.com/dotnet/roslyn/issues/72259")]
public async Task SeeAttributeNames2()
{
var text = """
class C
{
/// <summary>
/// <see l$$=""/>
This conversation was marked as resolved.
Show resolved Hide resolved
/// </summary>
static void Goo()
{
}
}
""";
var expected = """
class C
{
/// <summary>
/// <see langword=""/>
This conversation was marked as resolved.
Show resolved Hide resolved
/// </summary>
static void Goo()
{
}
}
""";

await VerifyProviderCommitAsync(text, "langword", expected, null);
}
This conversation was marked as resolved.
Show resolved Hide resolved

[Fact, WorkItem("https://github.com/dotnet/roslyn/issues/37504")]
public async Task SeeAlsoAttributeNames()
{
Expand Down Expand Up @@ -1015,23 +1044,6 @@ void Goo() { }
await VerifyItemExistsAsync(text, "langword");
}

[Fact, WorkItem("https://github.com/dotnet/roslyn/issues/11489")]
public async Task AttributeValueOnQuote()
{
var text = """
class C
{
/// <summary>
/// <see langword="$$
/// </summary>
static void Goo()
{
}
}
""";
await VerifyItemExistsAsync(text, "await", usePreviousCharAsTrigger: true);
}
This conversation was marked as resolved.
Show resolved Hide resolved

[Fact, WorkItem("https://github.com/dotnet/roslyn/issues/757")]
public async Task TermAndDescriptionInsideItem()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,54 @@ class c
End Using
End Function

<WpfTheory, CombinatorialData>
Public Async Function InvokeWithOpenAngleSeeCommitLangwordWithEqualsQuotes(showCompletionInArgumentLists As Boolean) As Task

This conversation was marked as resolved.
Show resolved Hide resolved
Using state = TestStateFactory.CreateCSharpTestState(
<Document><![CDATA[
class c
{
/// <summary>
/// <see $$=""
/// </summary>
void goo() { }
}
]]></Document>, showCompletionInArgumentLists:=showCompletionInArgumentLists)

state.SendTypeChars("l")
state.SendInvokeCompletionList()
Await state.AssertSelectedCompletionItem(displayText:="langword")
state.SendReturn()

' /// <see langword="$$"/>
This conversation was marked as resolved.
Show resolved Hide resolved
Await state.AssertLineTextAroundCaret(" /// <see langword=""", """")
End Using
End Function

<WpfTheory, CombinatorialData>
Public Async Function InvokeWithOpenAngleSeeCommitLangwordWithSpaceEqualsQuotes(showCompletionInArgumentLists As Boolean) As Task

This conversation was marked as resolved.
Show resolved Hide resolved
Using state = TestStateFactory.CreateCSharpTestState(
<Document><![CDATA[
class c
{
/// <summary>
/// <see $$ =""
/// </summary>
void goo() { }
}
]]></Document>, showCompletionInArgumentLists:=showCompletionInArgumentLists)

state.SendTypeChars("l")
state.SendInvokeCompletionList()
Await state.AssertSelectedCompletionItem(displayText:="langword")
state.SendReturn()

' /// <see langword="$$"/>
This conversation was marked as resolved.
Show resolved Hide resolved
Await state.AssertLineTextAroundCaret(" /// <see langword=""", """ =""""")
End Using
End Function

<WpfTheory, CombinatorialData>
Public Function InvokeWithNullKeywordCommitSeeLangword(showCompletionInArgumentLists As Boolean) As Task
Return InvokeWithKeywordCommitSeeLangword("null", showCompletionInArgumentLists)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ public override bool IsInsertionTrigger(SourceText text, int characterPosition,

if (IsAttributeNameContext(token, position, out var elementName, out var existingAttributes))
{
return GetAttributeItems(elementName, existingAttributes);
var nextToken = token.GetNextToken();
return GetAttributeItems(elementName, existingAttributes,
addEqualsAndQuotes: !nextToken.IsKind(SyntaxKind.EqualsToken) || nextToken.HasLeadingTrivia);
}

var wasTriggeredAfterSpace = trigger.Kind == CompletionTriggerKind.Insertion && trigger.Character == ' ';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,14 @@ private CompletionItem GetItem(string name)
return CreateCompletionItem(name);
}

protected IEnumerable<CompletionItem> GetAttributeItems(string tagName, ISet<string> existingAttributes)
protected IEnumerable<CompletionItem> GetAttributeItems(string tagName, ISet<string> existingAttributes, bool addEqualsAndQuotes)
{
return s_attributeMap.Where(x => x.elementName == tagName && !existingAttributes.Contains(x.attributeName))
.Select(x => CreateCompletionItem(x.attributeName, beforeCaretText: x.text, afterCaretText: "\""));
return s_attributeMap
.Where(x => x.elementName == tagName && !existingAttributes.Contains(x.attributeName))
.Select(x => CreateCompletionItem(
x.attributeName,
beforeCaretText: addEqualsAndQuotes ? x.text : x.text[..^2],
afterCaretText: addEqualsAndQuotes ? "\"" : ""));
}

protected IEnumerable<CompletionItem> GetAlwaysVisibleItems()
Expand Down Expand Up @@ -279,6 +283,13 @@ public override async Task<CompletionChange> GetChangeAsync(Document document, C
var replacementText = beforeCaretText;
var newPosition = replacementSpan.Start + beforeCaretText.Length;

if (text.Length > replacementSpan.End + 1
&& text[replacementSpan.End] == '='
&& text[replacementSpan.End + 1] == '"')
{
newPosition += 2;
This conversation was marked as resolved.
Show resolved Hide resolved
}

if (commitChar.HasValue && !char.IsWhiteSpace(commitChar.Value) && commitChar.Value != replacementText[^1])
{
// include the commit character
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@

Private Function GetAttributes(tagName As String, attributes As SyntaxList(Of XmlNodeSyntax)) As IEnumerable(Of CompletionItem)
Dim existingAttributeNames = attributes.Select(AddressOf GetAttributeName).WhereNotNull().ToSet()
Return GetAttributeItems(tagName, existingAttributeNames)
Return GetAttributeItems(tagName, existingAttributeNames, addEqualsAndQuotes := false)

Check failure on line 335 in src/Features/VisualBasic/Portable/Completion/CompletionProviders/XmlDocCommentCompletionProvider.vb

View check run for this annotation

Azure Pipelines / roslyn-CI (Correctness Correctness_Analyzers)

src/Features/VisualBasic/Portable/Completion/CompletionProviders/XmlDocCommentCompletionProvider.vb#L335

src/Features/VisualBasic/Portable/Completion/CompletionProviders/XmlDocCommentCompletionProvider.vb(335,89): error IDE0055: (NETCORE_ENGINEERING_TELEMETRY=Build) Fix formatting (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0055)

Check failure on line 335 in src/Features/VisualBasic/Portable/Completion/CompletionProviders/XmlDocCommentCompletionProvider.vb

View check run for this annotation

Azure Pipelines / roslyn-CI (Correctness Correctness_Analyzers)

src/Features/VisualBasic/Portable/Completion/CompletionProviders/XmlDocCommentCompletionProvider.vb#L335

src/Features/VisualBasic/Portable/Completion/CompletionProviders/XmlDocCommentCompletionProvider.vb(335,92): error IDE0055: (NETCORE_ENGINEERING_TELEMETRY=Build) Fix formatting (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0055)

Check failure on line 335 in src/Features/VisualBasic/Portable/Completion/CompletionProviders/XmlDocCommentCompletionProvider.vb

View check run for this annotation

Azure Pipelines / roslyn-CI (Correctness Correctness_Analyzers)

src/Features/VisualBasic/Portable/Completion/CompletionProviders/XmlDocCommentCompletionProvider.vb#L335

src/Features/VisualBasic/Portable/Completion/CompletionProviders/XmlDocCommentCompletionProvider.vb(335,89): error IDE0055: (NETCORE_ENGINEERING_TELEMETRY=Build) Fix formatting (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0055)

Check failure on line 335 in src/Features/VisualBasic/Portable/Completion/CompletionProviders/XmlDocCommentCompletionProvider.vb

View check run for this annotation

Azure Pipelines / roslyn-CI (Correctness Correctness_Analyzers)

src/Features/VisualBasic/Portable/Completion/CompletionProviders/XmlDocCommentCompletionProvider.vb#L335

src/Features/VisualBasic/Portable/Completion/CompletionProviders/XmlDocCommentCompletionProvider.vb(335,92): error IDE0055: (NETCORE_ENGINEERING_TELEMETRY=Build) Fix formatting (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0055)

Check failure on line 335 in src/Features/VisualBasic/Portable/Completion/CompletionProviders/XmlDocCommentCompletionProvider.vb

View check run for this annotation

Azure Pipelines / roslyn-CI

src/Features/VisualBasic/Portable/Completion/CompletionProviders/XmlDocCommentCompletionProvider.vb#L335

src/Features/VisualBasic/Portable/Completion/CompletionProviders/XmlDocCommentCompletionProvider.vb(335,89): error IDE0055: (NETCORE_ENGINEERING_TELEMETRY=Build) Fix formatting (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0055)

Check failure on line 335 in src/Features/VisualBasic/Portable/Completion/CompletionProviders/XmlDocCommentCompletionProvider.vb

View check run for this annotation

Azure Pipelines / roslyn-CI

src/Features/VisualBasic/Portable/Completion/CompletionProviders/XmlDocCommentCompletionProvider.vb#L335

src/Features/VisualBasic/Portable/Completion/CompletionProviders/XmlDocCommentCompletionProvider.vb(335,92): error IDE0055: (NETCORE_ENGINEERING_TELEMETRY=Build) Fix formatting (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0055)

Check failure on line 335 in src/Features/VisualBasic/Portable/Completion/CompletionProviders/XmlDocCommentCompletionProvider.vb

View check run for this annotation

Azure Pipelines / roslyn-CI

src/Features/VisualBasic/Portable/Completion/CompletionProviders/XmlDocCommentCompletionProvider.vb#L335

src/Features/VisualBasic/Portable/Completion/CompletionProviders/XmlDocCommentCompletionProvider.vb(335,89): error IDE0055: (NETCORE_ENGINEERING_TELEMETRY=Build) Fix formatting (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0055)

Check failure on line 335 in src/Features/VisualBasic/Portable/Completion/CompletionProviders/XmlDocCommentCompletionProvider.vb

View check run for this annotation

Azure Pipelines / roslyn-CI

src/Features/VisualBasic/Portable/Completion/CompletionProviders/XmlDocCommentCompletionProvider.vb#L335

src/Features/VisualBasic/Portable/Completion/CompletionProviders/XmlDocCommentCompletionProvider.vb(335,92): error IDE0055: (NETCORE_ENGINEERING_TELEMETRY=Build) Fix formatting (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0055)
End Function

Private Shared Function GetAttributeName(node As XmlNodeSyntax) As String
Expand Down
Loading