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

Fix & Enhancements for AddExplicitTypeToParameter #926

Merged
merged 1 commit into from
Apr 19, 2022

Conversation

Booksbaum
Copy link
Contributor

As promised in #917: Fix for AddExplicitTypeToParameter
And some enhancements


Fix: AddExplicitTypeToParameter triggers despite type already specified

Enhancement: Trigger for primary constructor

  • secondary ctors (new (...) = ...) already worked

Enhancement: Surround with parens less often

  • prev: only don't add parens when already directly surrounded by parens (no spaces allowed) [*1]
    let f1 (a) = a + 1
    //      ^
    let f2 (a ) = a + 1
    //      ^
    =>
    let f1 (a: int) = a + 1
    let f2 ((a: int) )
  • now: don't add parens when surrounded by parens or , and spaces somewhere between are ok:
    let f1 (a) = a + 1
    //      ^
    let f2 (a ) = a + 1
    //      ^
    let f3 (a, b, c) = a + b + c + 1
    //         ^
    let f4 (a,  b  ) = a + b + 1
    //          ^
    =>
    let f1 (a: int) = a + 1
    let f2 (a: int ) = a + 1
    let f3 (a, b: int, c) = a + b + c + 1
    let f4 (a,  b: int  ) = a + b + 1

Fix: NamedText.TryGetChar throws exception when Position in last column




hmpf...no code in footnotes allowed
-> footnote substitute using custom separator, html and [*1]....

[*1]: Actually there were some more cases it didn't add parens: when other text directly adjacent to identifier and no spaces to next parens:

let f1 (a,b,c) = a + b + c + 1
//        ^

=>

let f1 (a,b:int,c) = a + b + c + 1

But any spaces inside parens and param gets parens:

let f2 (a,b,c ) = a + b + c + 1
//        ^
let f3 (a ,b,c) = a + b + c + 1
//         ^
let f4 (a, b,c) = a + b + c + 1
//         ^

=>

let f2 (a,(b: int),c ) = a + b + c + 1
let f3 (a ,(b: int),c) = a + b + c + 1
let f4 (a, (b: int),c) = a + b + c + 1

With this PR neither of these cases gets parens

Enhancement: Trigger for primary constructor

Enhancement: Surround with parens less often

Fix: `NamedText.TryGetChar` throws exception when Position in last column
@baronfel
Copy link
Contributor

This test suite is awesome. I really appreciate the detail and effort you've put in here to make this codefix consistent and correct!

@baronfel baronfel merged commit 22cddf8 into ionide:main Apr 19, 2022
@Booksbaum Booksbaum deleted the FixAddExplicitTypeToParameter branch April 19, 2022 18:01
@baronfel
Copy link
Contributor

When you have such a detailed test suite, it makes it very easy for me to click the merge button. I love your approach here, thank you so much.

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