ionide / ionide-vscode-fsharp

VS Code plugin for F# development
http://ionide.io
MIT License
860 stars 279 forks source link

Code formatting does not work #1313

Closed ghost closed 4 years ago

ghost commented 4 years ago

Describe the bug "Shift + Alt + F" and "Format On Save" do not work

Environment (please complete the following information):

Additional context

All settings and keybindings are default except

settings.json

{
    "editor.formatOnSave": true
}
open-collective-bot[bot] commented 4 years ago

Hey @koowashi :wave:,

Thank you for opening an issue. We will get back to you as soon as we can. Also, check out our OpenCollective and consider backing us.

https://opencollective.com/ionide

PS.: We offer backer support for all backers. Don't forget to add backer label when you start backing us :smile:

baronfel commented 4 years ago

Here's the error I see in the debug console:

[10:29:36 ERR] [Fantomas] Error while parsing the configuration files at /Users/chethusk/oss/FsAutoComplete/src/FsAutoComplete.Core. Using default configuration
System.Exception: No configuration files were found for /Users/chethusk/oss/FsAutoComplete/src/FsAutoComplete.Core
   at Microsoft.FSharp.Core.PrintfModule.PrintFormatToStringThenFail@1637.Invoke(String message) in E:\A\_work\130\s\src\fsharp\FSharp.Core\printf.fs:line 1637
   at Fantomas.CodeFormatterImpl.readConfiguration(String fileOrFolder)

looks like there's a problem in the 'no config files found' pathway?

I'll take a look at this, @koowashi.

ghost commented 4 years ago

Yes, this problem occurs due to that. Could you provide me more information on the config file?

MangelMaxime commented 4 years ago

Hello @koowashi

The config file is a JSON file. You can find more information about it on Fantomas documentation page

ghost commented 4 years ago

Thank you for your information.

I put fantomas-config.json file and got this error:

[Error - 1:01:27] Request textDocument/formatting failed.
  Message: System.MissingMethodException: Method not found: 'SynExpr LetOrUseBang.get_Item5()'.
   at Fantomas.AstTransformer.Ast.visitSynExpr(SynExpr synExpr)
   at Fantomas.AstTransformer.Ast.visitSynBinding@935-1.GenerateNext(IEnumerable`1& next)
   at Microsoft.FSharp.Core.CompilerServices.GeneratedSequenceBase`1.MoveNextImpl() in E:\A\_work\130\s\src\fsharp\FSharp.Core\seqcore.fs:line 371
   at Microsoft.FSharp.Collections.SeqModule.ToList[T](IEnumerable`1 source) in E:\A\_work\130\s\src\fsharp\FSharp.Core\seq.fs:line 557
   at Fantomas.AstTransformer.Ast.visitSynBinding(SynBinding binding)
   at Microsoft.FSharp.Primitives.Basics.List.map[T,TResult](FSharpFunc`2 mapping, FSharpList`1 x) in E:\A\_work\130\s\src\fsharp\FSharp.Core\local.fs:line 250
   at Fantomas.AstTransformer.Ast.visitSynModuleDecl(SynModuleDecl ast)
   at Microsoft.FSharp.Primitives.Basics.List.mapToFreshConsTail[a,b](FSharpList`1 cons, FSharpFunc`2 f, FSharpList`1 x) in E:\A\_work\130\s\src\fsharp\FSharp.Core\local.fs:line 243
   at Microsoft.FSharp.Primitives.Basics.List.map[T,TResult](FSharpFunc`2 mapping, FSharpList`1 x) in E:\A\_work\130\s\src\fsharp\FSharp.Core\local.fs:line 254
   at Fantomas.AstTransformer.Ast.visitSynModuleOrNamespace@71-2.GenerateNext(IEnumerable`1& next)
   at Microsoft.FSharp.Core.CompilerServices.GeneratedSequenceBase`1.MoveNextImpl() in E:\A\_work\130\s\src\fsharp\FSharp.Core\seqcore.fs:line 371
   at Microsoft.FSharp.Collections.SeqModule.ToList[T](IEnumerable`1 source)
   at Fantomas.AstTransformer.Ast.visitSynModuleOrNamespace(SynModuleOrNamespace modOrNs)
   at Microsoft.FSharp.Primitives.Basics.List.map[T,TResult](FSharpFunc`2 mapping, FSharpList`1 x) in E:\A\_work\130\s\src\fsharp\FSharp.Core\local.fs:line 250
   at Fantomas.AstTransformer.children@1691.GenerateNext(IEnumerable`1& next)
   at Microsoft.FSharp.Core.CompilerServices.GeneratedSequenceBase`1.MoveNextImpl() in E:\A\_work\130\s\src\fsharp\FSharp.Core\seqcore.fs:line 371
   at Microsoft.FSharp.Collections.SeqModule.ToList[T](IEnumerable`1 source)
   at Fantomas.AstTransformer.astToNode(FSharpList`1 hds, FSharpList`1 mdls)
   at Fantomas.Trivia.collectTrivia(FormatConfig config, FSharpList`1 tokens, Int32 lineCount, ParsedInput ast)
   at Fantomas.Context.Context.create(FormatConfig config, FSharpList`1 defines, String content, FSharpOption`1 maybeAst)
   at Fantomas.CodeFormatterImpl.formatWith(ParsedInput ast, FSharpList`1 defines, FormatContext formatContext, FormatConfig config)
   at Fantomas.CodeFormatterImpl.format@406-1.Invoke(Tuple`2[] _arg1)
   at Microsoft.FSharp.Control.AsyncPrimitives.CallThenInvokeNoHijackCheck[a,b](AsyncActivation`1 ctxt, FSharpFunc`2 userCode, b result1) in E:\A\_work\130\s\src\fsharp\FSharp.Core\async.fs:line 417
   at Microsoft.FSharp.Control.Trampoline.Execute(FSharpFunc`2 firstAction) in E:\A\_work\130\s\src\fsharp\FSharp.Core\async.fs:line 109
  Code: -32603
baronfel commented 4 years ago

yes, this is due to an incorrect version of Fantomas being used in Ionide. I'm working on the fix now.

Krzysztof-Cieslak commented 4 years ago

Fix released in 4.6.2