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

Detect type alias in implementation. #1243

Merged
merged 6 commits into from
Mar 14, 2024

Conversation

nojaf
Copy link
Contributor

@nojaf nojaf commented Mar 6, 2024

I'd like to add a codefix to include a type alias inside a signature file.
I'm quite specifically interested in this, and only this.

Sample

Comment on lines 40 to 46
match typeDefnInfo with
| None -> return []
| Some (typeName, mTypeDefn, implPath) ->

match parseAndCheckResults.TryGetSymbolUseFromIdent sourceText typeName with
| None -> return []
| Some typeSymbolUse ->
Copy link
Contributor

Choose a reason for hiding this comment

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

This makes me feel like we could use a short-circuit/guard style function to reduce the nesting, maybe something like

let guard input = 
  match input with
  | None -> Ok []
  | Some i -> Ok i

let! (typeName, mTypeDefn, implPath) = guard typeDefnInfo

thoughts? It could go in the CodeFix module where some of our other filters/checks go.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think I get the concept but I can't get that example to work in the asyncResult thing.

Copy link
Member

Choose a reason for hiding this comment

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

This would be a bit more tricky this is mimicking early return which would be more of a 3 case DU. (Ok for continue, Done for stop, Error for stop, then match at the end to map Done -> Ok)

Only way to model currently without going down the new CE rabbit hole would be to use the Result.requireXXX functions with an appropriate error message(s) and match on the message(s) after with AsyncResult.orElseWith and return empty list in those cases.

Copy link
Contributor

Choose a reason for hiding this comment

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

We can punt on making this nicer - though I could see some kind of codeFix CE that includes guards and custom operations for 'summoning' the relevant pieces of data for a codefix easily :D

@nojaf
Copy link
Contributor Author

nojaf commented Mar 7, 2024

add_type_to_signature

Works a little bit on my machine

@nojaf nojaf marked this pull request as ready for review March 7, 2024 15:22
@nojaf
Copy link
Contributor Author

nojaf commented Mar 7, 2024

Added some tests, calling it a day, ready for review.

Copy link
Contributor

@baronfel baronfel left a comment

Choose a reason for hiding this comment

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

As always, thank you for this contribution @nojaf!

@baronfel baronfel merged commit 8162411 into ionide:nightly Mar 14, 2024
13 of 14 checks passed
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.

3 participants