Git Product home page Git Product logo

fantomas-for-vs's People

Contributors

akoslukacs avatar dependabot[bot] avatar deviousasti avatar kxxt avatar nojaf avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

fantomas-for-vs's Issues

Thank you

Not an issue, just wanted to say thank you for this fantastic extension. It covers an important gap for F# afficionados that primarily use Visual Studio instead of VSCode. Keep up the great work!

Editorconfig

Earlier this week support for .editorconfig files was added.
You can get the settings by using CodeFormatter.ReadConfiguration
Simply pass the current fsharp file as a parameter to get the settings.

You will, of course, need to make a decision about what to do with the settings from the UI.

Formatting stopped working in VS2019

The extension probably automatically updated to version 0.4.5.1 and stopped working.
I am using Microsoft Visual Studio Professional 2019, Version 16.7.3

The message in the statusbar:
Could not format: Could not load type 'InterpolatedString' from assembly 'FSharp.Compiler.Service, version 36.0.3.0, etc'

The extension stopped working after upgrading Visual Studio 2022 to the latest version 17.4

Try:

Uninstall the extension and installing again, getting this message:

This extension is not installable on any currently installed products

Log:

16-Nov-22 4:56:48 PM - Microsoft VSIX Installer
16-Nov-22 4:56:48 PM - -------------------------------------------
16-Nov-22 4:56:48 PM - vsixinstaller.exe version:
16-Nov-22 4:56:48 PM - 17.4.2118-17-4P4Inse-ge4c88902
16-Nov-22 4:56:48 PM - -------------------------------------------
16-Nov-22 4:56:48 PM - Command line parameters:
16-Nov-22 4:56:48 PM - C:\Program Files (x86)\Microsoft Visual Studio\Installer\resources\app\ServiceHub\Services\Microsoft.VisualStudio.Setup.Service\VSIXInstaller.exe,C:\Users\fernanfr\Downloads\FantomasVs.vsix
16-Nov-22 4:56:48 PM - -------------------------------------------
16-Nov-22 4:56:48 PM - Microsoft VSIX Installer
16-Nov-22 4:56:48 PM - -------------------------------------------
16-Nov-22 4:56:48 PM - Skipping product Microsoft.VisualStudio.Product.BuildTools (ed51a08c) since it does not support extensions
16-Nov-22 4:56:48 PM - Initializing Install...
16-Nov-22 4:56:48 PM - Extension Details...
16-Nov-22 4:56:48 PM - 	Identifier         : FantomasVs.ef00bfc2-a899-45fc-aae8-afecf8673aaf
16-Nov-22 4:56:48 PM - 	Name               : F# Formatting
16-Nov-22 4:56:48 PM - 	Author             : Asti
16-Nov-22 4:56:48 PM - 	Version            : 1.0.2
16-Nov-22 4:56:48 PM - 	Description        : F# source code formatting using Fantomas. 
16-Nov-22 4:56:48 PM - 	Locale             : en-US
16-Nov-22 4:56:48 PM - 	MoreInfoURL        : https://github.com/deviousasti/fsharp-formatting-for-vs
16-Nov-22 4:56:48 PM - 	InstalledByMSI     : False
16-Nov-22 4:56:48 PM - 	SupportedFrameworkVersionRange : [4.5,)
16-Nov-22 4:56:48 PM - 
16-Nov-22 4:56:48 PM - 	SignatureState     : Unsigned
16-Nov-22 4:56:48 PM - 	Supported Products : 
16-Nov-22 4:56:48 PM - 		Microsoft.VisualStudio.Community
16-Nov-22 4:56:48 PM - 			Version : [16.0,17.0)
16-Nov-22 4:56:48 PM - 			ProductArchitecture : x86
16-Nov-22 4:56:48 PM - 
16-Nov-22 4:56:48 PM - 	References         : 
16-Nov-22 4:56:48 PM - 	Prerequisites      : 
16-Nov-22 4:56:48 PM - 		-------------------------------------------------------
16-Nov-22 4:56:48 PM - 		Identifier   : Microsoft.VisualStudio.Component.CoreEditor
16-Nov-22 4:56:48 PM - 		Name         : Visual Studio core editor
16-Nov-22 4:56:48 PM - 		Version      : [16.0,17.0)
16-Nov-22 4:56:48 PM - 
16-Nov-22 4:56:48 PM - Signature Details...
16-Nov-22 4:56:48 PM - 	Extension is not signed.
16-Nov-22 4:56:48 PM - 
16-Nov-22 4:56:48 PM - Searching for applicable products...
16-Nov-22 4:56:48 PM - Found installed product - Global Location
16-Nov-22 4:56:48 PM - Found installed product - Visual Studio Professional 2022
16-Nov-22 4:56:49 PM - VSIXInstaller.NoApplicableSKUsException: This extension is not installable on any currently installed products.
   at VSIXInstaller.ExtensionService.GetInstallableDataImpl(IInstallableExtension extension, String extensionPackParentName, Boolean isRepairSupported, IStateData stateData, IEnumerable`1& skuData)
   at VSIXInstaller.ExtensionService.GetInstallableData(String vsixPath, String extensionPackParentName, Boolean isRepairSupported, IStateData stateData, IEnumerable`1& skuData)
   at VSIXInstaller.ExtensionPackService.IsExtensionPack(IStateData stateData, Boolean isRepairSupported)
   at VSIXInstaller.ExtensionPackService.ExpandExtensionPackToInstall(IStateData stateData, Boolean isRepairSupported)
   at VSIXInstaller.App.Initialize(Boolean isRepairSupported)
   at VSIXInstaller.App.Initialize()
   at System.Threading.Tasks.Task`1.InnerInvoke()
   at System.Threading.Tasks.Task.Execute()

Fantomas' package name changed from `fantomas-tool` to `fantomas`

Context: fsprojects/fantomas#2174

These lines should probably be changed to adhere to the rename:

InstallAction.Global => await LaunchDotnet("Installing tool globally", "tool install --verbosity normal --global fantomas-tool"),
InstallAction.Local => await LaunchDotnet("Installing tool locally", "tool install --verbosity normal fantomas-tool"),

That way, the original intention by @nojaf is carried on to this Visual Studio extension as well: New users should be less confused. Suppose this change is not done to the VS extension. In that case, users might still get confused moving forward, as the extension adds a package to their machine (or local tools manifest) that is obsolete.

I see one issue with just changing it, though: fantomas is only a CLI tool starting in 5.0.0-alpha-003. Is it enough for this extension to wait for version 5 to be out of preview, perhaps? That way the tool install commands above would automatically pick a version that is at least the release version of v5.

Update Fantomas

I see the extension hasn't been updated for a couple of months. Fantomas 4.5.4 is out. Would be great to have the extension updated!

Migrate to Fantomas.Client

Hey @deviousasti,

I've released a first version of Fantomas.Client, this is the proposed solution for fsprojects/fantomas#1844.

A first editor implementation was recently merged in FsAutocomplete.

The main idea is that you reference Fantomas.Client and create a new LSPFantomasService instance and use the API in FantomasService to handle formatting requests.

Each request will give you a FantomasResponse which contains a FantomasResponseCode. Based on that code, you will know how to process the response.
The FantomasService will handle proxy each request to the right compatible version of fantomas-tool.

I've written a bit of documentation here, hopefully, that helps.

Let me know if you have any further questions.

Support VS2022

I don't have much to add, Visual Studio 2022 support would be nice.

Add docs

TODO:

Add readme, and images.

Error in format files inside Visual Studio after updating fantomas to 6.0.0-alpha-010

Just updated fantomas to 6.0.0-alpha-010. Command line worked like a charm to format all files. However, format inside Visual Studio showed the following error.

ParseException
  [{ Severity = Error
     SubCategory = "parse"
     Range = None
     ErrorNumber = None
     Message =
      "A type definition requires one or more members or other declarations. If you intend to define an empty class, struct or interface, then use 'type ... = class end', 'interface end' or 'struct end'." };
   { Severity = Error
     SubCategory = "parse"
     Range = Some (11,4--11,6)
     ErrorNumber = Some 10
     Message = "Unexpected symbol '[<' in expression" };
   { Severity = Error
     SubCategory = "parse"
     Range = None
     ErrorNumber = None
     Message = "Unmatched '{'" };
   { Severity = Error
     SubCategory = "parse"
     Range = Some (23,4--23,5)
     ErrorNumber = Some 10
     Message =
      "Incomplete structured construct at or before this point in implementation file" }]
Attempting to find Fantomas Tool...
Found at: FantomasToolFound
  (FantomasVersion "6.0.0-alpha-010",
   LocalTool (Folder "C:\FSharp\KARP\DeedleHelper\DeedleHelper.Math"))
The formatting operation failed:
 System.AggregateException: One or more errors occurred. ---> Newtonsoft.Json.JsonSerializationException: Deserializing JSON-RPC result to type FormatDocumentResponse failed with JsonSerializationException: The number of field values does not match the number of properties defined by union 'Formatted'. Path 'result'.
   at StreamJsonRpc.JsonMessageFormatter.JsonRpcResult.GetResult[T]()
   at StreamJsonRpc.JsonRpc.<InvokeCoreAsync>d__143`1.MoveNext()
   --- End of inner exception stack trace ---
   at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
   at Fantomas.Client.LSPFantomasService.Fantomas-Client-Contracts-FantomasService-FormatDocumentAsync@276-1.Invoke(Task`1 t) in C:\Users\nojaf\Projects\fantomas\src\Fantomas.Client\LSPFantomasService.fs:line 276
   at System.Threading.Tasks.ContinuationResultTaskFromResultTask`2.InnerInvoke()
   at System.Threading.Tasks.Task.Execute()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at FantomasVs.FantomasHandler.<FormatAsync>d__8.MoveNext()
---> (Inner Exception #0) Newtonsoft.Json.JsonSerializationException: Deserializing JSON-RPC result to type FormatDocumentResponse failed with JsonSerializationException: The number of field values does not match the number of properties defined by union 'Formatted'. Path 'result'.
   at StreamJsonRpc.JsonMessageFormatter.JsonRpcResult.GetResult[T]()
   at StreamJsonRpc.JsonRpc.<InvokeCoreAsync>d__143`1.MoveNext()<---

The formatting operation failed:
 System.AggregateException: One or more errors occurred. ---> Newtonsoft.Json.JsonSerializationException: Deserializing JSON-RPC result to type FormatDocumentResponse failed with JsonSerializationException: The number of field values does not match the number of properties defined by union 'Formatted'. Path 'result'.
   at StreamJsonRpc.JsonMessageFormatter.JsonRpcResult.GetResult[T]()
   at StreamJsonRpc.JsonRpc.<InvokeCoreAsync>d__143`1.MoveNext()
   --- End of inner exception stack trace ---
   at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
   at Fantomas.Client.LSPFantomasService.Fantomas-Client-Contracts-FantomasService-FormatDocumentAsync@276-1.Invoke(Task`1 t) in C:\Users\nojaf\Projects\fantomas\src\Fantomas.Client\LSPFantomasService.fs:line 276
   at System.Threading.Tasks.ContinuationResultTaskFromResultTask`2.InnerInvoke()
   at System.Threading.Tasks.Task.Execute()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at FantomasVs.FantomasHandler.<FormatAsync>d__8.MoveNext()
---> (Inner Exception #0) Newtonsoft.Json.JsonSerializationException: Deserializing JSON-RPC result to type FormatDocumentResponse failed with JsonSerializationException: The number of field values does not match the number of properties defined by union 'Formatted'. Path 'result'.
   at StreamJsonRpc.JsonMessageFormatter.JsonRpcResult.GetResult[T]()
   at StreamJsonRpc.JsonRpc.<InvokeCoreAsync>d__143`1.MoveNext()<---

My .editorconfig

indent_size = 4
tab_size = 4
max_line_length = 100
fsharp_max_value_binding_width = 60
fsharp_max_function_binding_width = 60
fsharp_max_infix_operator_expression = 60
fsharp_max_dot_get_expression_width = 60
fsharp_multi_line_lambda_closing_newline = true
fsharp_blank_lines_around_nested_multiline_expressions = false
fsharp_space_before_lowercase_invocation = false
fsharp_multiline_bracket_style = stroustrup
fsharp_newline_before_multiline_computation_expression = false

Visual Studio version: 17.4.5

Inconsistent version numbers

Just installed the extension - works great, btw! - but was confused which version I have:

  • I installed it directly from within VS. I got version 1.1.0
  • On the marketplace it shows the latest version as 1.0.2
  • In this repo, the latest tag is 0.9.4.

I was left confused, wondering if I really had the latest version or if I should have installed from the marketplace rather than directly in VS or something.

These numbers should really be consistent in order to increase confidence in the product.

Enable or disable "Format on save" per repo

Currently, if I enable "Format on save" then this will apply to all repos that I have open. If Fantomas isn't installed on another repo then I get the "Choose install" dialog from F# Formatting. I can click "Skip for now" but it reappears every time I save the file.

When working on multiple repos, sometimes in different teams, the decision to adopt Fantomas needs to be made per-repo. We need to enable format on save for all developers if we decide to use it on a repo, and if we don't use it then we can't have people always reformatting the entire file that they're working on.

I can't currently see a way to enable/disable "Format on save" for a given repo only. So currently that means each developer needs to enable and disable the setting in their editor manually according to the repo. Perhaps I'm missing something?

Maybe the editor extensions should be completely responsible for tracking this configuration per repo, or maybe there should be a change in the Fantomas repo to support this, like a .editorconfig setting that supports this, e.g. fsharp_recommend_format_on_save

Reformating on selection messes text following selection

Hello,

I encountered the following issue when using CTRL-K, CTRL-F (reformat selection). The text immediately following the selection gets duplicated :

example before :

unnamed

after :

unnamed

The code :

module Test

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

open System.Text.RegularExpressions

// Select this active function below, then hit CTRL-K CTRL-F
let (|Regex|_|) pattern input =
    let m = Regex.Match(input, pattern)

    if m.Success then
        Some(List.tail [ for g in m.Groups -> g.Value ])
    else
        None

// Then this comment should be messed-up !

File encoding is UTF-8 with BOM

Visual Studio Extention version used is 1.1.0.

Thanks !

Q: Ensuring same fantomas version with fantomas-tool and extension

In our setup our project members use this extension to format (on-save) while working on files, very nice! :).
In our CI pipeline we use fantomas-tool to verify that the formatting is indeed as expected and thus that everybody had the extension installed or applied the formatting otherwise.

Both the extension and tool use the fantomas configuration from the .editorconfig in the repository.

We found a mismatch in the resulting formatting due to the fact that the tool was pinned on 4.3.0, while the extension was 0.7.3, build against fantomas 4.4.0.
This was fixed by changing the pinned version of the tool to 4.4.0-alpha-001.

By default an extension automatically upgrades in VS, and it is not possible to install an old version easily.

It would be nice if there was a way to verify the fantomas version.
As the reference fantoms version it could maybe use the dotnet-tool version in dotnet-tool.json and/or an entry in the .editorconfig?

Maybe pinning the fantomas version in the .editorconfig is an issue for fantomas itself? I am not sure.

Unable to install the extension to VS 2022 on ARM64

I tried to install the extension to Visual Studio Community 2022 (ARM 64-bit) on Windows 11 Pro (ARM64). Here's the log:

12/7/2022 1:24:16 AM - Microsoft VSIX Installer
12/7/2022 1:24:16 AM - -------------------------------------------
12/7/2022 1:24:16 AM - vsixinstaller.exe version:
12/7/2022 1:24:16 AM - 17.4.2118-17-4P4Inse-ge4c88902
12/7/2022 1:24:16 AM - -------------------------------------------
12/7/2022 1:24:16 AM - Command line parameters:
12/7/2022 1:24:16 AM - C:\Program Files (x86)\Microsoft Visual Studio\Installer\resources\app\ServiceHub\Services\Microsoft.VisualStudio.Setup.Service\VSIXInstaller.exe,C:\Users\hongm\Downloads\FantomasVs.vsix
12/7/2022 1:24:16 AM - -------------------------------------------
12/7/2022 1:24:16 AM - Microsoft VSIX Installer
12/7/2022 1:24:16 AM - -------------------------------------------
12/7/2022 1:24:17 AM - Initializing Install...
12/7/2022 1:24:18 AM - Extension Details...
12/7/2022 1:24:18 AM - 	Identifier         : FantomasVs.4acfe0e3-4521-45ed-9c32-9265806f4108
12/7/2022 1:24:18 AM - 	Name               : F# Formatting
12/7/2022 1:24:18 AM - 	Author             : Asti
12/7/2022 1:24:18 AM - 	Version            : 1.1.0
12/7/2022 1:24:18 AM - 	Description        : F# source code formatting using Fantomas. 
12/7/2022 1:24:18 AM - 	Locale             : en-US
12/7/2022 1:24:18 AM - 	MoreInfoURL        : https://github.com/deviousasti/fsharp-formatting-for-vs
12/7/2022 1:24:18 AM - 	InstalledByMSI     : False
12/7/2022 1:24:18 AM - 	SupportedFrameworkVersionRange : [4.5,)
12/7/2022 1:24:18 AM - 
12/7/2022 1:24:18 AM - 	SignatureState     : Unsigned
12/7/2022 1:24:18 AM - 	Supported Products : 
12/7/2022 1:24:18 AM - 		Microsoft.VisualStudio.Community
12/7/2022 1:24:18 AM - 			Version : [17.0,18.0)
12/7/2022 1:24:18 AM - 			ProductArchitecture : amd64
12/7/2022 1:24:18 AM - 
12/7/2022 1:24:18 AM - 	References         : 
12/7/2022 1:24:18 AM - 	Prerequisites      : 
12/7/2022 1:24:18 AM - 		-------------------------------------------------------
12/7/2022 1:24:18 AM - 		Identifier   : Microsoft.VisualStudio.Component.CoreEditor
12/7/2022 1:24:18 AM - 		Name         : Visual Studio core editor
12/7/2022 1:24:18 AM - 		Version      : [17.0,18.0)
12/7/2022 1:24:18 AM - 
12/7/2022 1:24:18 AM - Signature Details...
12/7/2022 1:24:18 AM - 	Extension is not signed.
12/7/2022 1:24:18 AM - 
12/7/2022 1:24:18 AM - Searching for applicable products...
12/7/2022 1:24:18 AM - Found installed product - Global Location
12/7/2022 1:24:18 AM - Found installed product - Visual Studio Community 2022
12/7/2022 1:24:18 AM - VSIXInstaller.NoApplicableSKUsException: This extension is not installable on any currently installed products.
   at VSIXInstaller.ExtensionService.GetInstallableDataImpl(IInstallableExtension extension, String extensionPackParentName, Boolean isRepairSupported, IStateData stateData, IEnumerable`1& skuData)
   at VSIXInstaller.ExtensionService.GetInstallableData(String vsixPath, String extensionPackParentName, Boolean isRepairSupported, IStateData stateData, IEnumerable`1& skuData)
   at VSIXInstaller.ExtensionPackService.IsExtensionPack(IStateData stateData, Boolean isRepairSupported)
   at VSIXInstaller.ExtensionPackService.ExpandExtensionPackToInstall(IStateData stateData, Boolean isRepairSupported)
   at VSIXInstaller.App.Initialize(Boolean isRepairSupported)
   at VSIXInstaller.App.Initialize()
   at System.Threading.Tasks.Task`1.InnerInvoke()
   at System.Threading.Tasks.Task.Execute()

Describe default formatting options

Hello,

I am new to using this extension and I have just noticed that there is no description for the entries under Visual Studio 2019 options:

image

Bump to Fantomas 4.4

Just a friendly reminder that Fantomas 4.4 stable is out and we would like to update as soon as possible :)

Error: "Creating the Fantomas Deamon failed" when saving a file or trying to format in VS

In VS 2022, 17.8.0, with Fantomas 6.2.0 installed both locally (dotnet tool restore) and globally (the command fantomas is available anywhere), I get the following:

Creating the Fantomas Daemon failed:
Fantomas.Client tried to run `dotnet fantomas --daemon` but failed with "Daemon std error: Run "dotnet tool restore" to make the "fantomas" command available.
.
JsonRpc exception:One or more errors occurred."
Attempting to find Fantomas Tool...
Found at: FantomasToolFound
  (FantomasVersion "5.0.6",
   LocalTool
     (Folder
        "D:\Projects\TaskSeq\src\FSharp.Control.TaskSeq.Test"))

Note the odd thing that it says Found at: FantomasToolFould and then FantomasVersion "5.0.6", which is NOT a version I have installed, as far as I know:

PS D:\projects\TaskSeq> dotnet tool list
Package Id      Version      Commands      Manifest
------------------------------------------------------------------------------------------------------------------
fantomas        6.2.0        fantomas      D:\projects\TaskSeq\.config\dotnet-tools.json
PS D:\projects\TaskSeq> dotnet tool list --global
Package Id      Version      Commands
-------------------------------------
fantomas        6.2.2        fantomas

I'm not sure what's happening here. If I had to guess, maybe the tool expects a non-6.x version and should be updated for 6.x?

I can help, just need to figure out how to debug this ;).

Fantomas < 5.0 breaks nested lists

On latest F# Formatter extension for VS2022, formatting this

let webApp =
    choose
        [ GET
          >=> choose [
              route "/" >=> indexHandler "world"
              routef "/hello/%s" indexHandler ]
          setStatusCode 404 >=> text "Not Found" ]

becomes this

let webApp =
    choose
        [ GET
          >=> choose [ route "/" >=> indexHandler "world"; routef "/hello/%s" indexHandler ]

note the setStatusCode ... item and closing ] is dropped.

This appears to be fixed by 5.0

Add license

Having a license would make it clear that I can adopt this at work. Thanks!

Format on Save leaves the file unsaved after changes

Current behavior:
When saving a code file, if the file is reformatted, then it ends up having unsaved changes, and the user must save a second time to commit these formatting changes.

Expected behavior:
You should only ever have to save once.

Seen in version 0.7.1
Visual Studio Enterprise 2019 Version 16.8.4

Fantomas scrambled up a huge script file

Unfortunately fantomas set up to run on save, scrambled a huge script file of mine. This has caused literally days of work loss.

Is there a way to recover from this?

Well, actually, I am quite distressed by all of this. This is causing me big problems!

Microsoft.VisualStudio.Shell.15.0 not found when loading extension

Lately I cannot use this extension. Log says Microsoft.VisualStudio.Shell.15.0 cannot be found, specifically this version:

Microsoft.VisualStudio.Shell.15.0, Version=17.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a

Why is that happening? I tried to reinstall plugin but it keeps throwing that error. Something is required to be installed on my machine? Thank you.

Formatting doesn't work with WSL2 hosted files in VS2022

Steps to reproduce:

  • Create or open a solution/project hosted in WSL2;
  • Open a .fs file you wish to format;
  • Format the file with Edit > Advanced > Format Document.

Expected result:

The file is formatted according to the code style.

Actual result:

Nothing happens and no changes are introduced to the file.

Note:

Formatting works fine when I open projects in Windows host. Fantomas-tool is installed in both hosts and I can format files through both PowerShell in Windows and ZSH in WSL2 Debian.

Format all documents

I can format an individual document. Is it possible to format all documents in the workspace?

Diff is always one line longer than it should be

Before:

image

After:

image

As you can see, the diff indicates that the next line was also changed. I guess this has something to do with how newlines are included/applied as part of the diff. This is not a problem for this specific example, but can in many other cases lead you on a wild goose chase trying to find out what was changed on some lines where nothing was changed.

Formatting (often) results in garbled, uncompilable code

Formatting an F# file garbles the file, and results in uncompilable code.

Strange artifacts get introduced tot he code. Running fantomas from the command line does not cause this.

I can reproduce for example with this example:

input

module Repro

open System.Text.RegularExpressions

type Capacity = Capacity of count: int * item: string
type Container = Container of container: string * capacity: Capacity list

let parseInputLine (line: string) =
  let m =
    Regex.Match
      (line,
       """(?<container>\w+ \w+) bags contain (?<contents>no other bags|((?<count>\d+) (?<item>\w+ \w+) bag(s)?(, )?)+).""")
  ()

now I press Ctrl-E Ctrl-D

output

module Repro

open System.Text.RegularExpressions

type Capacity = Capacity of count: int * item: string
type Container = Container of container: string * capacity: Capacity list
    Regex.Match(
      line,
      """(?<container>\w+ \w+) bags contain (?<contents>no other bags|((?<count>\d+) (?<item>\w+ \w+) bag(s)?(, )?)+)."""
    )

  ()
      (line,
       """(?<container>\w+ \w+) bags contain (?<contents>no other bags|((?<count>\d+) (?<item>\w+ \w+) bag(s)?(, )?)+).""")
  ()

Environment

Visual Studio

Microsoft Visual Studio Community 2019
Version 16.8.6
VisualStudio.16.Release/16.8.6+31019.35
Microsoft .NET Framework
Version 4.8.04084

Installed Version: Community

Visual C++ 2019   00435-60000-00000-AA182
Microsoft Visual C++ 2019

ASP.NET and Web Tools 2019   16.8.560.26713
ASP.NET and Web Tools 2019

ASP.NET Core Razor Language Services   16.1.0.2052803+84e121f1403378489b842e1797df2f3f5a49ac3c
Provides languages services for ASP.NET Core Razor.

ASP.NET Web Frameworks and Tools 2019   16.8.560.26713
For additional information, visit https://www.asp.net/

Azure App Service Tools v3.0.0   16.8.560.26713
Azure App Service Tools v3.0.0

Azure Functions and Web Jobs Tools   16.8.560.26713
Azure Functions and Web Jobs Tools

C# Tools   3.8.0-5.20604.10+9ed4b774d20940880de8df1ca8b07508aa01c8cd
C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Common Azure Tools   1.10
Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

Cookiecutter   16.8.20241.2
Provides tools for finding, instantiating and customizing templates in cookiecutter format.

F# Formatting   0.8
F# source code formatting using Fantomas.

F# Lint   0.5
Source code linting for F#.

Fabric.DiagnosticEvents   1.0
Fabric Diagnostic Events

IntelliCode Extension   1.0
IntelliCode Visual Studio Extension Detailed Info

Microsoft Azure Service Fabric Tools for Visual Studio   16.0
Microsoft Azure Service Fabric Tools for Visual Studio

Microsoft Azure Tools   2.9
Microsoft Azure Tools for Microsoft Visual Studio 2019 - v2.9.30924.1

Microsoft Continuous Delivery Tools for Visual Studio   0.4
Simplifying the configuration of Azure DevOps pipelines from within the Visual Studio IDE.

Microsoft JVM Debugger   1.0
Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines

Microsoft MI-Based Debugger   1.0
Provides support for connecting Visual Studio to MI compatible debuggers

Microsoft Visual C++ Wizards   1.0
Microsoft Visual C++ Wizards

Microsoft Visual Studio Tools for Containers   1.1
Develop, run, validate your ASP.NET Core applications in the target environment. F5 your application directly into a container with debugging, or CTRL + F5 to edit & refresh your app without having to rebuild the container.

Microsoft Visual Studio VC Package   1.0
Microsoft Visual Studio VC Package

NuGet Package Manager   5.8.1
NuGet Package Manager in Visual Studio. For more information about NuGet, visit https://docs.nuget.org/

ProjectServicesPackage Extension   1.0
ProjectServicesPackage Visual Studio Extension Detailed Info

Python   16.8.20241.2
Provides IntelliSense, projects, templates, debugging, interactive windows, and other support for Python developers.

Python - Conda support   16.8.20241.2
Conda support for Python projects.

Python - Django support   16.8.20241.2
Provides templates and integration for the Django web framework.

Python - IronPython support   16.8.20241.2
Provides templates and integration for IronPython-based projects.

Python - Profiling support   16.8.20241.2
Profiling support for Python projects.

SQL Server Data Tools   16.0.62102.01130
Microsoft SQL Server Data Tools

Test Adapter for Boost.Test   1.0
Enables Visual Studio's testing tools with unit tests written for Boost.Test.  The use terms and Third Party Notices are available in the extension installation directory.

Test Adapter for Google Test   1.0
Enables Visual Studio's testing tools with unit tests written for Google Test.  The use terms and Third Party Notices are available in the extension installation directory.

TypeScript Tools   16.0.21016.2001
TypeScript Tools for Microsoft Visual Studio

Visual Basic Tools   3.8.0-5.20604.10+9ed4b774d20940880de8df1ca8b07508aa01c8cd
Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Visual F# Tools   16.8.0-beta.20507.4+da6be68280c89131cdba2045525b80890401defd
Microsoft Visual F# Tools

Visual Studio Code Debug Adapter Host Package   1.0
Interop layer for hosting Visual Studio Code debug adapters in Visual Studio

Visual Studio Container Tools Extensions   1.0
View, manage, and diagnose containers within Visual Studio.

Visual Studio Tools for CMake   1.0
Visual Studio Tools for CMake

Visual Studio Tools for Containers   1.0
Visual Studio Tools for Containers

Visual Studio Tools for Kubernetes   1.0
Visual Studio Tools for Kubernetes

Fantomas

I also have Fantomas v4.3.0-alpha-005 installed, which does the formatting without issues. (this preview version contains the eol enforcing I need on some projects, probably should update)

Editorconfig

I use editorconfig, but after having deleted it and restarted VS the problem still persisted. Nonetheless I attach it.

# top-most EditorConfig file
root = true

# Unix-style newlines with a newline ending every file
[*]
end_of_line = lf
insert_final_newline = true
charset = utf-8
indent_style = space
indent_size = 2

Please let me know how can I help tracing down the problem.

Thank you very much!

Formatting differs in VS from online fantomas even though I didn't touch the defaults

Hi

When trying to format the following code in the online formatter

let pIgnore p = p >>= fun _ -> fun rest -> Success ((), rest)
let pOption p = (p >>= fun result -> pReturn <| Some result) <|> pReturn None
let lookAhead (p:Parser<'a>) (input:Input) =
    (p >>= fun _ -> fun _ -> Success ((), input)) input

the result looks like

let pIgnore p =
    p >>= fun _ -> fun rest -> Success((), rest)

let pOption p =
    (p >>= fun result -> pReturn <| Some result)
    <|> pReturn None

let lookAhead (p: Parser<'a>) (input: Input) =
    (p >>= fun _ -> fun _ -> Success((), input)) input

However when I try it in VS using this plugin I get

let pIgnore p =
    p
    >>= fun _ -> fun rest -> Success((), rest)

let pOption p =
    (p
     >>= fun result -> pReturn <| Some result)
    <|> pReturn None

let lookAhead (p: Parser<'a>) (input: Input) =
    (p
     >>= fun _ -> fun _ -> Success((), input)) input

which looks really odd. I didn't change the defaults, and even after explicitly adding the editorconfig with default values the behaviour stayed the same. Any idea what might be going wrong?

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.