Git Product home page Git Product logo

Comments (5)

deviousasti avatar deviousasti commented on May 24, 2024

Formatting a selection is a bit of a known issue for Fantomas.
This is the output I get back from Fantomas LSP:

image

I think @nojaf might already be aware of this.

Aside:

/// Fantomas-for-vs does works well with CTRL-K CTRL-F

is an invalid comment (because of 3 slashes) in that position, because it's interpreted as an xmldoc. This might make it invisible to Fantomas in the first place.

from fantomas-for-vs.

lkluc avatar lkluc commented on May 24, 2024

Hello deviousasti,

First, thanks for the fast reply ! :)

And I'm glad you can reproduce my problem, it's usually the first step to a fix ;)

But I humbly beg to differ on the "invalid" part of the comment, on the MS website it seems clearly legit and interpreted as if I had enclosed it with summary tags, MS even seems to encourage it for quick XML summaries :

https://docs.microsoft.com/en-us/dotnet/fsharp/language-reference/xml-documentation#comments-without-xml-tags

Although I don't know for the other part where invalid XML comments are invisible to Fantomas.

Just to mention, I had the same thought at first (that the XML doc style comment might be the reason for the bug to occur) but think I tried with a regular comment and had the same badly formatted result. I'll give it a try just to be sure.

But thank you for looking into this problem, its appreciated. :)

from fantomas-for-vs.

nojaf avatar nojaf commented on May 24, 2024

Hello, format selection is being reworked in fsprojects/fantomas#2272.
This might solve your problem, it might not.
For now, Fantomas works best on the entire file.

But I humbly beg to differ on the "invalid" part of the comment,

The F# compiler stored /// comments in certain locations.
For example, when placed above a function, it will be part of the AST node of said function.

When stored anywhere else, you can already see a warning sign:
image
It is subtle but there are dots at the start here. In future versions of the compiler, you will receive warnings when you use triple-slash where you shouldn't.

Fantomas does restore invalid triple-slash comments, but I highly recommend that you only use them where you should.

from fantomas-for-vs.

lkluc avatar lkluc commented on May 24, 2024

Hello nojaf,

Thanks for the follow-up.

Glad to hear you're working on it, it's a very essential tool for me!

As for the comment, I see, my bad, I did not understood deviousasti's comment : it is on the placement that makes it illegal, not on the implicit XML tags, got it !

Thanks!

from fantomas-for-vs.

nojaf avatar nojaf commented on May 24, 2024

Leaving this as an up-for-grabs todo item:
https://www.nuget.org/packages/Fantomas.Client/0.6.0 was released. This contains a change in the selection API.

The FantomasResponse now exposes the range of the selection that was formatted.

https://github.com/fsprojects/fantomas/blob/98a7449918c2167c0478a151ec89bbde826a74c0/src/Fantomas.Client/Contracts.fs#L61-L70

So, if the user selected any additional whitespace, the response will contain the range that should be replaced with the format selection result.

from fantomas-for-vs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.