Skip to content

Specify Types: support named patterns and members #849

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

Merged
merged 13 commits into from
Apr 29, 2025
Merged

Conversation

DedSec256
Copy link
Collaborator

@DedSec256 DedSec256 commented Apr 25, 2025

Additional entry point for specify types via context actions. Currently supported the same scenarios as for inlay hints materialization.

The following PR's will add support for primary constructors / properties with accessors, etc

@DedSec256 DedSec256 force-pushed the ber.a/annotate branch 2 times, most recently from 03963a4 to 8ef21c3 Compare April 28, 2025 20:44
@DedSec256 DedSec256 marked this pull request as ready for review April 28, 2025 20:46
@DedSec256 DedSec256 marked this pull request as draft April 28, 2025 21:11
@DedSec256 DedSec256 marked this pull request as ready for review April 29, 2025 00:25
@DedSec256 DedSec256 requested a review from auduchinok April 29, 2025 02:27
Comment on lines 39 to 40
let inline (?>) (x: 'a) ([<InlineIfLambda>] f: 'a -> 'b) =
if isNull x then null else f x
Copy link
Member

Choose a reason for hiding this comment

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

Should we maybe do it in a separate PR and use it in more cases right away?

@@ -208,28 +226,54 @@ module SpecifyTypes =

| _ -> ()

module SpecifyTypesActionHelper =
open SpecifyTypes
let executePsiTransaction (node: ITreeNode) (availability: Availability) =
Copy link
Member

Choose a reason for hiding this comment

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

Please add new lines.

specifyParameterTypes types (fun x -> x[0].Type) enumerate parameters true
else
let types = getFunctionTypeArgs true mfv.FullType
specifyParameterTypes types id (_.GenericArguments) parameters true
Copy link
Member

Choose a reason for hiding this comment

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

Are the parens required here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We are currently using .NET 8.0.100 for GitHub Actions, which doesn't support shorthand syntax without parens properly.
We can upgrade it slightly in a separate PR or leave the brackets here.

Copy link
Member

Choose a reason for hiding this comment

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

Let's upgrade it then! :)

inherit FSharpContextActionBase(dataProvider)

override x.Text = "Add type annotations"
abstract member IsAvailable: 'a -> bool
member x.ContextNode = dataProvider.GetSelectedElement<'a>()
Copy link
Member

Choose a reason for hiding this comment

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

Please add new lines.

override x.IsAvailable(_: IUserDataHolder) =
let node = x.ContextNode

isNotNull node && isValid (node :> ITreeNode) &&
Copy link
Member

Choose a reason for hiding this comment

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

Are both isValid and isNotNull checks needed here? Doesn't the first one include the second? Also why is the cast needed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Also why is the cast needed?

The type inference has some difficulties, since isValid -- STRP-function
image

Copy link
Member

Choose a reason for hiding this comment

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

Oh, wow. That's really unfortunate :(

Copy link
Member

@auduchinok auduchinok left a comment

Choose a reason for hiding this comment

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

This is really good, thank you!

@DedSec256 DedSec256 merged commit 31632f9 into main Apr 29, 2025
1 check passed
@DedSec256 DedSec256 deleted the ber.a/annotate branch April 29, 2025 19:03
@auduchinok
Copy link
Member

@DedSec256 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants