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

VS: Make Fantomas auto-discoverable when user invokes F# format document/selection #2693

Open
lasp91 opened this issue Mar 24, 2017 · 20 comments
Assignees
Labels
Milestone

Comments

@lasp91
Copy link

lasp91 commented Mar 24, 2017

We should make Fantomas-for-VS auto-discoverable, e.g. suggest the marketplace addin by the community when the user invokes F# format-document or format-selection


Old notes:

I can't format any code in F# with VS2017, using the edit/format/advanced/document or selection. This is working perfectly in VS2015.

In VS2015 I had this issue at some stage and if disabling the the "Productive Power Tools", the edit/format started to work normally.
Then, if enabling the "Productive Power Tools" again, the edit/format functionality keept working and I had no issues anymore. All good in VS2015.

In VS2017 I installed the proper "Productive Power Tools", expecting no issues, but noticed the edit/format was not working. I decided to disable this functionality (in Extension and Updates) as I did for VS 2015 to see whether the issue is solved. But it did not solve the problem.

  • Operating system --> MS Windows 10 Pro
  • Editing Tools (e.g. Visual Studio Version) --> VS2015 Community Edition
@lasp91 lasp91 closed this as completed Mar 24, 2017
@lasp91 lasp91 reopened this Mar 24, 2017
@vasily-kirichenko
Copy link
Contributor

Formatting has never been supported. Visual F# Power Tools added it into VS 2012-2015, but we decided not to port it to VS 2017.

@lasp91
Copy link
Author

lasp91 commented Mar 24, 2017 via email

@cartermp
Copy link
Contributor

I think this is actually a good candidate to bring over from VFPT. Though not the most critical, formatting is definitely used a lot by people, and many folks do have ctrl+k+d and the like something they instinctively hit whenever they're coding. Also tagging as Up for Grabs since this wasn't a priority for folks porting over VFPT features.

@vasily-kirichenko Were there some issues in quality?

@vasily-kirichenko
Copy link
Contributor

The main ccncern was that it did not allow style settings. Another issue is that we used it via fantomas nuget package, which, in turn, depended on FCS package. We cannot use this approach in this repo.

@lasp91
Copy link
Author

lasp91 commented Mar 25, 2017 via email

@forki
Copy link
Contributor

forki commented Mar 25, 2017

The answer is simple as well: limited resources. While Visual F# is a Microsoft product most of the stuff in this area is done by the open source community. There is a lot happening around tooling at the moment and I assume someone will take care of formatting eventually. But right now it seems people's interests/priorities are at other (important) features. TBH there is very little hope that Microsoft will implement formatting, so our best shot is the community. You can be an active part here and help to make it happen. ;-)

@vasily-kirichenko
Copy link
Contributor

If we port Fantomas sources, it's easy. @dungpa do you mind?

@vasily-kirichenko
Copy link
Contributor

It seems quite easy to hook "format document" to Roslyn, see http://source.roslyn.io/#Microsoft.CodeAnalysis.EditorFeatures/Implementation/Formatting/FormatCommandHandler.cs,24
I could just copy-paste this whole folder https://github.com/dungpa/fantomas/tree/master/src/Fantomas and hook it. @dungpa @cartermp I'm not sure about licensing and stuff here.

@smoothdeveloper
Copy link
Contributor

Another issue is that we used it via fantomas nuget package, which, in turn, depended on FCS package. We cannot use this approach in this repo.

This is a major issue we are facing with the FCS split, and work to enhance VisualF# Tools; and it is detrimental to the state of all F# tooling outside VisualStudio.

Porting over Fantomas code will cause another split in the tooling, require backporting back & forth of enhancements and bugfixes.

Same problem appear with FSharpLint, and in fact any F# tooling backed by FCS.

The easiest approach, which does not cause those problems, would be to make the packages source compatible with FSharp.Compiler.LanguageService in this repository, and having a bit of fsproj massaging to make it compile easily with either FCS or inplace in this repository, probably a bit of #ifdef as well to make it happen.

Other approaches involving copying the code only work when the codebase is being deprecated like VFPT.

@vasily-kirichenko
Copy link
Contributor

We cannot use fantomas nuget anyway, because it depends on fcs, but we don't use the same fcs here and, if even we could, we'd get endless versions collision, like we got in vfpt.

@cloudRoutine
Copy link
Contributor

we'd need to do even more extensive testing of fantomas as it can break code

@cartermp
Copy link
Contributor

@lasp91 Another thing to keep in mind is that a source code formatter is one of the most deceptively difficult programs to write. The space of valid F# constructs and decisions which have to get made by pretty-printing the syntax tree is massive.

I think that porting over Fantomas code and modifying it to not depend on the FCS package is a good approach. Not sure about the license. I don't think there's any issue with Apache 2.0. @jongalloway may be able to provide more input here.

@dungpa
Copy link
Contributor

dungpa commented Mar 26, 2017

@vasily-kirichenko Feel free to do whatever you want with the code.

Just a word of warning, writing a code formatter for F# is significantly harder due to indentation-based syntax. Moreover, the fact that F# ASTs throw away formatting information (e.g. comments) makes the matter even worse.

@vasily-kirichenko
Copy link
Contributor

@dungpa thanks :)

@cartermp cartermp added this to the vFuture milestone Mar 31, 2017
@BentTranberg
Copy link

I ask that if the Fantomas source code formatter is brought into VS, then make sure it removes spaces at the end of all lines, and not add it to some lines. A code formatter that works against the one most obvious of all de facto formatting rules - remove trailing spaces - I consider not only useless, but a nuisance.

Why important? Source is normally written so that there are no trailing spaces in it. A tool that adds trailing spaces will be in constant conflict with developers and other tools. It will cause unneeded source changes, thereby creating a more messy VCS history, sometimes even with commits of files that actually doesn't have any effective changes. Teams waste time counteracting such flaws in tools.

@cartermp cartermp modified the milestones: vFuture, 16.0 Jul 29, 2018
@cartermp cartermp modified the milestones: 16.0, Unknown Aug 25, 2018
@s-trooper
Copy link

I just wrote my own source code formatter, may be it can be used for this issue.

@cartermp
Copy link
Contributor

@s-trooper We've used the F# codebase as a test case before, ensuring that CI still passes after a full run. If you'd like, you can submit a PR for personal review to get the project into shape.

@s-trooper
Copy link

@cartermp i have used CI (jenkins) before but i don't understand what you actually asking for.

My project do have some unit tests. But the tests versus F# code i have done manually, by cloning of this repo and run "fsfmt" on it and then build it (successfully).
I think you ask me to automate the latter part and include it in github CI pipiline for visualfsharp project? Or am i complete wrong?

@dsyme dsyme changed the title F# format document/selection doesn't work at all with VS2017. Implement F# format document/selection Apr 5, 2022
@dsyme dsyme changed the title Implement F# format document/selection Make Fantomas auto-discoverable when user invokes F# format document/selection Apr 5, 2022
@dsyme dsyme changed the title Make Fantomas auto-discoverable when user invokes F# format document/selection VS: Make Fantomas auto-discoverable when user invokes F# format document/selection Apr 6, 2022
@dsyme dsyme added Area-VS VS support for F# not covered elsewhere and removed Area-LangService-API labels Apr 6, 2022
@vzarytovskii vzarytovskii moved this to Not Planned in F# Compiler and Tooling Jun 17, 2022
@majocha
Copy link
Contributor

majocha commented Mar 26, 2023

Fantomas now provides Fantomas.Client nuget allowing to call into the installed tool out of process, so now we could easily integrate it.
There is also an extension that does it: F# Formatting

@T-Gro T-Gro self-assigned this Jul 4, 2023
@T-Gro T-Gro modified the milestones: Backlog, July-2023 Jul 4, 2023
@T-Gro T-Gro moved this from Not Planned to Planned in F# Compiler and Tooling Jul 4, 2023
@vzarytovskii
Copy link
Member

Fantomas now provides Fantomas.Client nuget allowing to call into the installed tool out of process, so now we could easily integrate it. There is also an extension that does it: F# Formatting

We'll still need to fork it, if we want it to be part of VS, also, might not play well with live buffers.

@T-Gro T-Gro modified the milestones: July-2023, Backlog Aug 3, 2023
@github-project-automation github-project-automation bot moved this from Planned to Done in F# Compiler and Tooling Jan 4, 2024
@vzarytovskii vzarytovskii reopened this Jan 4, 2024
@github-project-automation github-project-automation bot moved this from Done to In Progress in F# Compiler and Tooling Jan 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Archived in project
Development

No branches or pull requests