Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ private async Task<Model> ComputeModelInBackgroundAsync(
}

if (triggerInfo.TriggerCharacter.HasValue &&
!currentModel.Provider.IsRetriggerCharacter(triggerInfo.TriggerCharacter.Value))
!currentModel.Provider.RetriggerCharacters.Contains(triggerInfo.TriggerCharacter.Value))
{
return currentModel;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ void IChainedCommandHandler<TypeCharCommandArgs>.ExecuteCommand(TypeCharCommandA
else
{
var computed = false;
if (allProviders.Any(static (p, args) => p.IsRetriggerCharacter(args.TypedChar), args))
if (allProviders.Any(static (p, args) => p.RetriggerCharacters.Contains(args.TypedChar), args))
{
// The user typed a character that might close the scope of the current model.
// In this case, we should requery all providers.
Expand Down Expand Up @@ -138,7 +138,7 @@ void IChainedCommandHandler<TypeCharCommandArgs>.ExecuteCommand(TypeCharCommandA
using var unmatchedProvidersDisposer = ArrayBuilder<ISignatureHelpProvider>.GetInstance(out var unmatchedProviders);
foreach (var provider in providers)
{
if (provider.IsTriggerCharacter(ch))
if (provider.TriggerCharacters.Contains(ch))
{
matchedProviders.Add(provider);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
' The .NET Foundation licenses this file to you under the MIT license.
' See the LICENSE file in the project root for more information.

Imports System.Collections.Immutable
Imports System.Runtime.CompilerServices
Imports System.Threading
Imports Microsoft.CodeAnalysis.Editor.Implementation.IntelliSense
Expand Down Expand Up @@ -60,8 +61,8 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.IntelliSense

' Create a provider that will return an empty state when queried the second time
Dim slowProvider = New Mock(Of ISignatureHelpProvider)(MockBehavior.Strict)
slowProvider.Setup(Function(p) p.IsTriggerCharacter(" "c)).Returns(True)
slowProvider.Setup(Function(p) p.IsRetriggerCharacter(" "c)).Returns(True)
slowProvider.Setup(Function(p) p.TriggerCharacters).Returns(ImmutableArray.Create(Of Char)(" "c))
slowProvider.Setup(Function(p) p.RetriggerCharacters).Returns(ImmutableArray.Create(Of Char)(" "c))
slowProvider.Setup(Function(p) p.GetItemsAsync(It.IsAny(Of Document), It.IsAny(Of Integer), It.IsAny(Of SignatureHelpTriggerInfo), options, It.IsAny(Of CancellationToken))) _
.Returns(Task.FromResult(New SignatureHelpItems(CreateItems(2), TextSpan.FromBounds(0, 0), selectedItem:=0, semanticParameterIndex:=0, syntacticArgumentCount:=0, argumentName:=Nothing)))
Dim controller = Await CreateController(CreateWorkspace(), provider:=slowProvider.Object, waitForPresentation:=True)
Expand Down Expand Up @@ -214,13 +215,17 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.IntelliSense
Nothing))
End Function

Public Function IsTriggerCharacter(ch As Char) As Boolean Implements ISignatureHelpProvider.IsTriggerCharacter
Return ch = "("c
End Function

Public Function IsRetriggerCharacter(ch As Char) As Boolean Implements ISignatureHelpProvider.IsRetriggerCharacter
Return ch = ")"c
End Function
Public ReadOnly Property TriggerCharacters As ImmutableArray(Of Char) Implements ISignatureHelpProvider.TriggerCharacters
Get
Return ImmutableArray.Create("("c)
End Get
End Property

Public ReadOnly Property RetriggerCharacters As ImmutableArray(Of Char) Implements ISignatureHelpProvider.RetriggerCharacters
Get
Return ImmutableArray.Create(")"c)
End Get
End Property
End Class

Private Shared Function CreateMockTextView(buffer As ITextBuffer) As Mock(Of ITextView)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,12 @@ protected void VerifyTriggerCharacters(char[] expectedTriggerCharacters, char[]

foreach (var expectedTriggerCharacter in expectedTriggerCharacters)
{
Assert.True(signatureHelpProvider.IsTriggerCharacter(expectedTriggerCharacter), "Expected '" + expectedTriggerCharacter + "' to be a trigger character");
Assert.True(signatureHelpProvider.TriggerCharacters.Contains(expectedTriggerCharacter), "Expected '" + expectedTriggerCharacter + "' to be a trigger character");
}

foreach (var unexpectedTriggerCharacter in unexpectedTriggerCharacters)
{
Assert.False(signatureHelpProvider.IsTriggerCharacter(unexpectedTriggerCharacter), "Expected '" + unexpectedTriggerCharacter + "' to NOT be a trigger character");
Assert.False(signatureHelpProvider.TriggerCharacters.Contains(unexpectedTriggerCharacter), "Expected '" + unexpectedTriggerCharacter + "' to NOT be a trigger character");
}
}

Expand Down Expand Up @@ -389,7 +389,7 @@ private async Task TestSignatureHelpWorkerSharedAsync(
SignatureHelpTriggerReason.TypeCharCommand,
code.ElementAt(cursorPosition - 1));

if (!signatureHelpProvider.IsTriggerCharacter(triggerInfo.TriggerCharacter.Value))
if (!signatureHelpProvider.TriggerCharacters.Contains(triggerInfo.TriggerCharacter.Value))
{
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Composition;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
Expand Down Expand Up @@ -31,11 +32,9 @@ public AttributeSignatureHelpProvider()
{
}

public override bool IsTriggerCharacter(char ch)
=> ch is '(' or ',';
public override ImmutableArray<char> TriggerCharacters => ['(', ','];

public override bool IsRetriggerCharacter(char ch)
=> ch == ')';
public override ImmutableArray<char> RetriggerCharacters => [')'];

private bool TryGetAttributeExpression(
SyntaxNode root,
Expand All @@ -58,7 +57,7 @@ private bool IsTriggerToken(SyntaxToken token)
{
return !token.IsKind(SyntaxKind.None) &&
token.ValueText.Length == 1 &&
IsTriggerCharacter(token.ValueText[0]) &&
TriggerCharacters.Contains(token.ValueText[0]) &&
token.Parent is AttributeArgumentListSyntax &&
token.Parent.Parent is AttributeSyntax;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Composition;
using System.Linq;
using System.Threading;
Expand All @@ -29,11 +30,9 @@ public ConstructorInitializerSignatureHelpProvider()
{
}

public override bool IsTriggerCharacter(char ch)
=> ch is '(' or ',';
public override ImmutableArray<char> TriggerCharacters => ['(', ','];

public override bool IsRetriggerCharacter(char ch)
=> ch == ')';
public override ImmutableArray<char> RetriggerCharacters => [')'];

private async Task<ConstructorInitializerSyntax?> TryGetConstructorInitializerAsync(
Document document,
Expand All @@ -57,7 +56,7 @@ public override bool IsRetriggerCharacter(char ch)
}

private bool IsTriggerToken(SyntaxToken token)
=> SignatureHelpUtilities.IsTriggerParenOrComma<ConstructorInitializerSyntax>(token, IsTriggerCharacter);
=> SignatureHelpUtilities.IsTriggerParenOrComma<ConstructorInitializerSyntax>(token, TriggerCharacters);

private static bool IsArgumentListToken(ConstructorInitializerSyntax expression, SyntaxToken token)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,17 @@ namespace Microsoft.CodeAnalysis.CSharp.SignatureHelp;
[ExportSignatureHelpProvider("ElementAccessExpressionSignatureHelpProvider", LanguageNames.CSharp), Shared]
internal sealed class ElementAccessExpressionSignatureHelpProvider : AbstractCSharpSignatureHelpProvider
{
private static readonly ImmutableArray<char> s_triggerCharacters = ['[', ','];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could remove and do TriggerCharaacters { get; } = ...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is used in a bunch of static classes and methods - found it easier to do this than change the rest of the callers


[ImportingConstructor]
[Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
public ElementAccessExpressionSignatureHelpProvider()
{
}

public override bool IsTriggerCharacter(char ch)
=> IsTriggerCharacterInternal(ch);

private static bool IsTriggerCharacterInternal(char ch)
=> ch is '[' or ',';
public override ImmutableArray<char> TriggerCharacters => s_triggerCharacters;

public override bool IsRetriggerCharacter(char ch)
=> ch == ']';
public override ImmutableArray<char> RetriggerCharacters => [']'];

private static bool TryGetElementAccessExpression(SyntaxNode root, int position, ISyntaxFactsService syntaxFacts, SignatureHelpTriggerReason triggerReason, CancellationToken cancellationToken, [NotNullWhen(true)] out ExpressionSyntax? identifier, out SyntaxToken openBrace)
{
Expand Down Expand Up @@ -281,7 +278,7 @@ internal static bool IsTriggerToken(SyntaxToken token)
{
return !token.IsKind(SyntaxKind.None) &&
token.ValueText.Length == 1 &&
IsTriggerCharacterInternal(token.ValueText[0]) &&
s_triggerCharacters.Contains(token.ValueText[0]) &&
token.Parent is BracketedArgumentListSyntax &&
token.Parent.Parent is ElementAccessExpressionSyntax;
}
Expand Down Expand Up @@ -330,7 +327,7 @@ internal static bool IsTriggerToken(SyntaxToken token)
{
return !token.IsKind(SyntaxKind.None) &&
token.ValueText.Length == 1 &&
IsTriggerCharacterInternal(token.ValueText[0]) &&
s_triggerCharacters.Contains(token.ValueText[0]) &&
token.Parent is ArrayRankSpecifierSyntax;
}

Expand Down Expand Up @@ -365,7 +362,7 @@ internal static bool IsTriggerToken(SyntaxToken token)
{
return !token.IsKind(SyntaxKind.None) &&
token.ValueText.Length == 1 &&
IsTriggerCharacterInternal(token.ValueText[0]) &&
s_triggerCharacters.Contains(token.ValueText[0]) &&
token.Parent is BracketedArgumentListSyntax &&
token.Parent.Parent is ElementBindingExpressionSyntax &&
token.Parent.Parent.Parent is ConditionalAccessExpressionSyntax;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Composition;
using System.Linq;
using System.Threading;
Expand Down Expand Up @@ -31,11 +32,9 @@ public GenericNameSignatureHelpProvider()
{
}

public override bool IsTriggerCharacter(char ch)
=> ch is '<' or ',';
public override ImmutableArray<char> TriggerCharacters => ['<', ','];

public override bool IsRetriggerCharacter(char ch)
=> ch == '>';
public override ImmutableArray<char> RetriggerCharacters => ['>'];

protected virtual bool TryGetGenericIdentifier(
SyntaxNode root, int position,
Expand All @@ -62,7 +61,7 @@ private bool IsTriggerToken(SyntaxToken token)
{
return !token.IsKind(SyntaxKind.None) &&
token.ValueText.Length == 1 &&
IsTriggerCharacter(token.ValueText[0]) &&
TriggerCharacters.Contains(token.ValueText[0]) &&
token.Parent is TypeArgumentListSyntax &&
token.Parent.Parent is GenericNameSyntax;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// See the LICENSE file in the project root for more information.

using System;
using System.Collections.Immutable;
using System.Composition;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
Expand All @@ -26,11 +27,9 @@ public InitializerExpressionSignatureHelpProvider()
{
}

public override bool IsTriggerCharacter(char ch)
=> ch is '{' or ',';
public override ImmutableArray<char> TriggerCharacters => ['{', ','];

public override bool IsRetriggerCharacter(char ch)
=> ch == '}';
public override ImmutableArray<char> RetriggerCharacters => ['}'];

private bool TryGetInitializerExpression(
SyntaxNode root,
Expand All @@ -47,7 +46,7 @@ private bool TryGetInitializerExpression(
private bool IsTriggerToken(SyntaxToken token)
=> !token.IsKind(SyntaxKind.None) &&
token.ValueText.Length == 1 &&
IsTriggerCharacter(token.ValueText[0]) &&
TriggerCharacters.Contains(token.ValueText[0]) &&
token.Parent is InitializerExpressionSyntax;

private static bool IsInitializerExpressionToken(InitializerExpressionSyntax expression, SyntaxToken token)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,9 @@ public InvocationExpressionSignatureHelpProvider()

internal partial class InvocationExpressionSignatureHelpProviderBase : AbstractOrdinaryMethodSignatureHelpProvider
{
public override bool IsTriggerCharacter(char ch)
=> ch is '(' or ',';
public override ImmutableArray<char> TriggerCharacters => ['(', ','];

public override bool IsRetriggerCharacter(char ch)
=> ch == ')';
public override ImmutableArray<char> RetriggerCharacters => [')'];

private async Task<InvocationExpressionSyntax?> TryGetInvocationExpressionAsync(Document document, int position, SignatureHelpTriggerReason triggerReason, CancellationToken cancellationToken)
{
Expand All @@ -54,7 +52,7 @@ public override bool IsRetriggerCharacter(char ch)
}

private bool IsTriggerToken(SyntaxToken token)
=> SignatureHelpUtilities.IsTriggerParenOrComma<InvocationExpressionSyntax>(token, IsTriggerCharacter);
=> SignatureHelpUtilities.IsTriggerParenOrComma<InvocationExpressionSyntax>(token, TriggerCharacters);

private static bool IsArgumentListToken(InvocationExpressionSyntax expression, SyntaxToken token)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// See the LICENSE file in the project root for more information.

using System;
using System.Collections.Immutable;
using System.Composition;
using System.Diagnostics;
using System.Threading;
Expand All @@ -22,11 +23,9 @@ namespace Microsoft.CodeAnalysis.CSharp.SignatureHelp;
[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
internal sealed partial class ObjectCreationExpressionSignatureHelpProvider() : AbstractCSharpSignatureHelpProvider
{
public override bool IsTriggerCharacter(char ch)
=> ch is '(' or ',';
public override ImmutableArray<char> TriggerCharacters => ['(', ','];

public override bool IsRetriggerCharacter(char ch)
=> ch == ')';
public override ImmutableArray<char> RetriggerCharacters => [')'];

private async Task<BaseObjectCreationExpressionSyntax?> TryGetObjectCreationExpressionAsync(
Document document,
Expand All @@ -50,7 +49,7 @@ public override bool IsRetriggerCharacter(char ch)
}

private bool IsTriggerToken(SyntaxToken token)
=> SignatureHelpUtilities.IsTriggerParenOrComma<BaseObjectCreationExpressionSyntax>(token, IsTriggerCharacter);
=> SignatureHelpUtilities.IsTriggerParenOrComma<BaseObjectCreationExpressionSyntax>(token, TriggerCharacters);

private static bool IsArgumentListToken(BaseObjectCreationExpressionSyntax expression, SyntaxToken token)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Composition;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
Expand Down Expand Up @@ -35,11 +36,9 @@ public PrimaryConstructorBaseTypeSignatureHelpProvider()
{
}

public override bool IsTriggerCharacter(char ch)
=> ch is '(' or ',';
public override ImmutableArray<char> TriggerCharacters => ['(', ','];

public override bool IsRetriggerCharacter(char ch)
=> ch == ')';
public override ImmutableArray<char> RetriggerCharacters => [')'];

private bool TryGetBaseTypeSyntax(
SyntaxNode root,
Expand All @@ -65,7 +64,7 @@ static bool IsArgumentListToken(PrimaryConstructorBaseTypeSyntax expression, Syn
}

private bool IsTriggerToken(SyntaxToken token)
=> SignatureHelpUtilities.IsTriggerParenOrComma<PrimaryConstructorBaseTypeSyntax>(token, IsTriggerCharacter);
=> SignatureHelpUtilities.IsTriggerParenOrComma<PrimaryConstructorBaseTypeSyntax>(token, TriggerCharacters);

protected override async Task<SignatureHelpItems?> GetItemsWorkerAsync(Document document, int position, SignatureHelpTriggerInfo triggerInfo, MemberDisplayOptions options, CancellationToken cancellationToken)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using Microsoft.CodeAnalysis.SignatureHelp;
using Microsoft.CodeAnalysis.Text;
using Microsoft.CodeAnalysis.Shared.Extensions;
using System.Collections.Immutable;

namespace Microsoft.CodeAnalysis.CSharp.SignatureHelp;

Expand Down Expand Up @@ -96,7 +97,7 @@ internal static TextSpan GetSignatureHelpSpan(InitializerExpressionSyntax initia
internal static TextSpan GetSignatureHelpSpan(AttributeArgumentListSyntax argumentList)
=> CommonSignatureHelpUtilities.GetSignatureHelpSpan(argumentList, s_getAttributeArgumentListCloseToken);

internal static bool IsTriggerParenOrComma<TSyntaxNode>(SyntaxToken token, Func<char, bool> isTriggerCharacter) where TSyntaxNode : SyntaxNode
internal static bool IsTriggerParenOrComma<TSyntaxNode>(SyntaxToken token, ImmutableArray<char> triggerCharacters) where TSyntaxNode : SyntaxNode
{
// Don't dismiss if the user types ( to start a parenthesized expression or tuple
// Note that the tuple initially parses as a parenthesized expression
Expand Down Expand Up @@ -134,7 +135,7 @@ internal static bool IsTriggerParenOrComma<TSyntaxNode>(SyntaxToken token, Func<

return !token.IsKind(SyntaxKind.None) &&
token.ValueText.Length == 1 &&
isTriggerCharacter(token.ValueText[0]) &&
triggerCharacters.Contains(token.ValueText[0]) &&
token.Parent is ArgumentListSyntax &&
token.Parent.Parent is TSyntaxNode;
}
Expand Down
Loading
Loading