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

Fantomas strips quotes from quoted type-parameters #2875

Closed
2 of 3 tasks
JohSand opened this issue May 5, 2023 · 2 comments · Fixed by #2876
Closed
2 of 3 tasks

Fantomas strips quotes from quoted type-parameters #2875

JohSand opened this issue May 5, 2023 · 2 comments · Fixed by #2876

Comments

@JohSand
Copy link
Contributor

JohSand commented May 5, 2023

Issue created from fantomas-online

Code

let repro (t: '``QuotedWithIllegalChar<'T>``) = ()

Result

let repro (t: 'QuotedWithIllegalChar<'T>) = ()

Problem description

Sometimes it is useful to have type-parameters in quotes, allowing them to contain characters such as '<' and '>'. After formatting, this quotation is lost, leading to non-compiling code.

Extra information

  • The formatted result breaks my code.
  • The formatted result gives compiler warnings.
  • I or my company would be willing to help fix this.

Options

Fantomas main branch at 2023-05-05T09:52:15Z - 4093fa5

Default Fantomas configuration

Did you know that you can ignore files when formatting from fantomas-tool or the FAKE targets by using a .fantomasignore file?

@nojaf
Copy link
Contributor

nojaf commented May 8, 2023

Hello, thank you for your interest in this project.

It appears we are not processing the ident text of a SynTypar in

let mkSynTypar (SynTypar(ident, req, _)) =
let range =
mkRange
ident.idRange.FileName
(Position.mkPos ident.idRange.StartLine (ident.idRange.StartColumn - 1))
ident.idRange.End
match req with
| TyparStaticReq.None -> stn $"'{ident}" range
| TyparStaticReq.HeadType -> stn $"^{ident.idText}" range

Some check along these lines could do the trick:

let mkSynTypar (SynTypar(ident, req, _)) =
    let range =
        mkRange
            ident.idRange.FileName
            (Position.mkPos ident.idRange.StartLine (ident.idRange.StartColumn - 1))
            ident.idRange.End

    let identText =
        let width = ident.idRange.EndColumn - ident.idRange.StartColumn
        // 5 because of ^ or ' and `` on each side
        if ident.idText.Length + 5 = width then
            $"``{ident.idText}``"
        else
            ident.idText

    match req with
    | TyparStaticReq.None -> stn $"'{identText}" range
    | TyparStaticReq.HeadType -> stn $"^{identText}" range

Are you interested in submitting a PR for this?

@JohSand
Copy link
Contributor Author

JohSand commented May 8, 2023

I'm willing to give it a try.

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

Successfully merging a pull request may close this issue.

2 participants