Skip to content

Conversation

eugenesmlv
Copy link
Contributor

@eugenesmlv eugenesmlv commented Oct 17, 2020

PR Summary

These changes provide more informative method definition for methods with the optional parameters.

  • Primitive value types and strings.
static void Bar(int optParam = -1)
static void Bar(string optParam = "default string")
  • Reference types.
static void Bar(string optParam = null)
  • Enums.
static void Bar(System.UriKind optParam = System.UriKind.Relative)
  • Structs and generic method parameters.
static void Bar(datetime optParam = default)
static void GenericBar[T](T optParam = default)

PR Context

Fix #13728

The changes don't cover a case with an OptionalAttribute. Calling such a method without optional arguments throws an exception.

Add-Type -NameSpace demo -Name Foo -MemberDefinition @"
public static void Bar([System.Runtime.InteropServices.Optional]int optParam) { }
"@

[demo.Foo]::Bar()
#OperationStopped: Expression of type 'System.Reflection.Missing' cannot be used for parameter of type 'System.Int32' of method 'Void Bar(Int32)' (Parameter 'arg0')

I could investigate it if you show me where to start.

PR Checklist

@ghost ghost assigned TravisEz13 Oct 17, 2020
@eugenesmlv
Copy link
Contributor Author

@iSazonov it seems like CompletionCompleters also uses a method definition for the tooltip. Is it possible to test that case somehow?

var methodCacheEntry = member as DotNetAdapter.MethodCacheEntry;
if (methodCacheEntry != null)
{
memberName = methodCacheEntry[0].method.Name;
isMethod = true;
getToolTip = () => string.Join("\n", methodCacheEntry.methodInformationStructures.Select(m => m.methodDefinition));
}

@eugenesmlv eugenesmlv changed the title Show optional parameters as such wheh dislplaying method definition and overloads Show optional parameters as such when dislplaying method definition and overloads Oct 17, 2020
Copy link
Collaborator

@iSazonov iSazonov left a comment

Choose a reason for hiding this comment

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

it seems like CompletionCompleters also uses a method definition for the tooltip. Is it possible to test that case somehow?

You can use TabCompletion2 (see our tests how it is used).

@iSazonov iSazonov added CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log Hacktoberfest-Accepted Accepted to participate in Hacktoberfest labels Oct 19, 2020
@eugenesmlv
Copy link
Contributor Author

You can use TabCompletion2 (see our tests how it is used).

I couldn't find TabCompletion2 anywhere. Do you mean TabExpansion2? Anyway, as far as I understand, tab completion completes just method name and there are already tests for that.

Do you mean "method signature"?

Rather, "method signature with parameters of various types such as parameters passed by reference, generic and optional parameters", but it seems to me, we could combine tests for the overloaded definition and different method signature into one context.

I also want to suggest to mark parameters passed by reference with [in] and [out] keywords in addition to the [ref]. Can I implement that in this PR?

@SeeminglyScience
Copy link
Collaborator

SeeminglyScience commented Oct 19, 2020

You can use TabCompletion2 (see our tests how it is used).

I couldn't find TabCompletion2 anywhere. Do you mean TabExpansion2? Anyway, as far as I understand, tab completion completes just method name and there are already tests for that.

Tab expansion results include a tooltip, which is only shown in editors and some PSReadLine key handlers (but not the Tab one). You can see it here:

(TabExpansion2 -inputScript ($s = '$Host.PushRunspace') -cursorColumn $s.Length).CompletionMatches

returns

CompletionText ListItemText ResultType ToolTip
-------------- ------------ ---------- -------
PushRunspace(  PushRunspace     Method void PushRunspace(runspace runspace)…

I also want to suggest to mark parameters passed by reference with [in] and [out] keywords in addition to the [ref]. Can I implement that in this PR?

Maybe best to open an issue to discuss that one. Part of the problem there is that [in] and [out] aren't really a thing in PowerShell, so the way to pass it will still be [ref].

@iSazonov
Copy link
Collaborator

I couldn't find TabCompletion2 anywhere. Do you mean TabExpansion2?

Yes, sorry.

@eugenesmlv
Copy link
Contributor Author

@iSazonov @SeeminglyScience thanks for helping me! I've added tests for the TabExpansion2 tooltip.

@iSazonov iSazonov requested a review from SteveL-MSFT October 20, 2020 13:20
@ghost ghost added the Review - Needed The PR is being reviewed label Oct 27, 2020
@ghost
Copy link

ghost commented Oct 27, 2020

This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days.
Maintainer, please provide feedback and/or mark it as Waiting on Author

@ghost ghost removed the Review - Needed The PR is being reviewed label Sep 15, 2021
@ghost ghost added the Review - Needed The PR is being reviewed label Sep 23, 2021
@ghost
Copy link

ghost commented Sep 23, 2021

This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days.
Maintainer, please provide feedback and/or mark it as Waiting on Author

Copy link
Member

@SteveL-MSFT SteveL-MSFT left a comment

Choose a reason for hiding this comment

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

LGTM

@SteveL-MSFT SteveL-MSFT requested a review from daxian-dbw May 16, 2022 23:22
@iSazonov
Copy link
Collaborator

/rebase

@ghost ghost removed the Review - Needed The PR is being reviewed label May 18, 2022
@github-actions
Copy link
Contributor

github-actions bot commented May 18, 2022

Started rebase: https://github.com/PowerShell/PowerShell/actions/runs/2343284398

GitHub
PowerShell for every system! Contribute to PowerShell/PowerShell development by creating an account on GitHub.

@iSazonov
Copy link
Collaborator

iSazonov commented May 18, 2022

@TravisEz13 Could you please look the rebase error? https://github.com/PowerShell/PowerShell/runs/6483334261?check_suite_focus=true#step:5:31

GitHub
PowerShell for every system! Contribute to PowerShell/PowerShell development by creating an account on GitHub.

@ghost ghost added the Review - Needed The PR is being reviewed label May 25, 2022
@ghost
Copy link

ghost commented May 25, 2022

This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days.
Maintainer, please provide feedback and/or mark it as Waiting on Author

@TravisEz13 TravisEz13 merged commit 735096b into PowerShell:master Jun 27, 2022
@ghost ghost removed the Review - Needed The PR is being reviewed label Jun 27, 2022
@ghost
Copy link

ghost commented Jul 18, 2022

🎉v7.3.0-preview.6 has been released which incorporates this pull request.:tada:

Handy links:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log Hacktoberfest-Accepted Accepted to participate in Hacktoberfest
Projects
None yet
Development

Successfully merging this pull request may close these issues.

When displaying method overloads, show optional parameters as such
6 participants