Skip to content

VB Service Added - Inline Parameter Name Hints#45622

Merged
akhera99 merged 7 commits intodotnet:features/parameter-hintsfrom
akhera99:vb-service
Jul 10, 2020
Merged

VB Service Added - Inline Parameter Name Hints#45622
akhera99 merged 7 commits intodotnet:features/parameter-hintsfrom
akhera99:vb-service

Conversation

@akhera99
Copy link
Member

@akhera99 akhera99 commented Jul 2, 2020

Hello,

This pull request is to be able to merge the added Visual Basic service to the current feature branch I have out.

View of the VB hints:
image

Modified/Created Files:
InlineParameterNameHintsService.vb much like the service for C#, I go through and located all the SimpleArgumentSyntax types and determine if the adornment should be added.
VisualBasicInlineParameterNameHintsTests.vb essentially did all the tests I did for the C# tagger, but for VB.
ArgumentSyntaxExtensions.vb previously the DetermineParameter function made a call to the GetSymbolInfo method which had the type ExpressionSyntax as a parameter. I just changed the call to use the GetSymbolInfo method which had the SyntaxNode type as a parameter so that I would be able to get the associated parameter for expressions as well as attributes.

Please let me know if you have any questions or concerns!

@akhera99 akhera99 requested a review from a team as a code owner July 2, 2020 19:39
Dim semanticModel = Await document.GetRequiredSemanticModelAsync(cancellationToken).ConfigureAwait(False)
Dim nodes = root.DescendantNodes()

For Each node In nodes
Copy link
Member

Choose a reason for hiding this comment

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

Something in this loop should be checking for cancellation.

Copy link
Member Author

Choose a reason for hiding this comment

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

Added

<Document>
Class Foo
Sub Main(args As String())
TestMethod({|x:CInt(5.5)|}, {|y:2.2|})
Copy link
Member

Choose a reason for hiding this comment

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

Also add tests for CType, TryCast and DirectCast.

Copy link
Member Author

Choose a reason for hiding this comment

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

Added, they don't resolve to the same base type so I had to add checks for it in the service as well.

Implements IInlineParameterNameHintsService

<ImportingConstructor>
<Obsolete(MefConstruction.ImportingConstructorMessage, True)>
Copy link
Contributor

Choose a reason for hiding this comment

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

named parameter for true.

Copy link
Member Author

@akhera99 akhera99 Jul 3, 2020

Choose a reason for hiding this comment

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

It does not allow me to add one?

Copy link
Contributor

Choose a reason for hiding this comment

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

really? weird :(

public async Task<IEnumerable<InlineParameterHint>> GetInlineParameterNameHintsAsync(Document document, TextSpan textSpan, CancellationToken cancellationToken)
{
var root = await document.GetRequiredSyntaxRootAsync(cancellationToken).ConfigureAwait(false);
var spans = new List<InlineParameterHint>();
Copy link
Contributor

Choose a reason for hiding this comment

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

remove this and just do var spans = ... below.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed

return spans;
}

protected abstract List<InlineParameterHint> AddAllParameterNameHintLocations(
Copy link
Contributor

Choose a reason for hiding this comment

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

don't really see why this is returning a List. Either have it be IEnuemrable, or ImmutableArray.

Copy link
Contributor

Choose a reason for hiding this comment

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

oh wait. it's even weirder :) you both pass in teh value to add to, and you return it out as a return value. Pick one or the other :)

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed

/// </summary>
[ExportLanguageService(typeof(IInlineParameterNameHintsService), LanguageNames.CSharp), Shared]
internal class InlineParameterNameHintsService : IInlineParameterNameHintsService
internal class InlineParameterNameHintsService : AbstractInlineParameterNameHintsService
Copy link
Contributor

Choose a reason for hiding this comment

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

once we have a VB and C# version we rename thsee. so this should be CSharpInlineParameterNameHintsService. That way it's easy to find/nav-to them since we have distinct names, not three types with the same name.


Namespace Microsoft.CodeAnalysis.VisualBasic.InlineParameterNameHints
<ExportLanguageService(GetType(IInlineParameterNameHintsService), LanguageNames.VisualBasic), [Shared]>
Friend Class InlineParameterNameHintsService
Copy link
Contributor

Choose a reason for hiding this comment

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

rename

Comment on lines +29 to +31
If param IsNot Nothing AndAlso param.Name.Length > 0 Then
spans.Add(New InlineParameterHint(param.Name, simpleArgument.Span.Start))
End If
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: you could share this code with c# by having a protected helper in teh base class. up to you.

Copy link
Contributor

@CyrusNajmabadi CyrusNajmabadi left a comment

Choose a reason for hiding this comment

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

lgtm as long as the renames happen. Up to you about the other nits :)

@akhera99 akhera99 merged commit 2f0fef4 into dotnet:features/parameter-hints Jul 10, 2020
Comment on lines +60 to +79
If TypeOf arg Is TryCastExpressionSyntax Then
Dim cast = DirectCast(arg, TryCastExpressionSyntax)
' Recurse until we find a literal
' If so, then we should add the adornment
Return IsExpressionWithNoName(cast.Expression)
End If

If TypeOf arg Is CTypeExpressionSyntax Then
Dim cast = DirectCast(arg, CTypeExpressionSyntax)
' Recurse until we find a literal
' If so, then we should add the adornment
Return IsExpressionWithNoName(cast.Expression)
End If

If TypeOf arg Is DirectCastExpressionSyntax Then
Dim cast = DirectCast(arg, DirectCastExpressionSyntax)
' Recurse until we find a literal
' If so, then we should add the adornment
Return IsExpressionWithNoName(cast.Expression)
End If
Copy link
Member

Choose a reason for hiding this comment

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

There's a CastExpressionSyntax base type you can use to cover all of these if you wanted.

@akhera99 akhera99 deleted the vb-service branch June 18, 2024 20:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants