fsprojects / fantomas-for-vs

Visual Studio Formatter for F#
https://marketplace.visualstudio.com/items?itemName=asti.fantomas-vs
46 stars 10 forks source link

Fantomas does not work in Visual Studio 2022 #32

Closed suchitraDev closed 1 year ago

suchitraDev commented 2 years ago

I get a error of the Formatting not working for the Visual studio 2022

deviousasti commented 2 years ago

Could you describe the error? Would be ideal if you can paste the log from the output window.

javicabanas commented 2 years ago

Formatting options not be found. I have F# Formatting extension installed and VS has already been restarted and I don't have the Formatting options, I only see the below options:

On Save: "Commit Changes" and "Format on Save" options Performance: "Apply As Diff" and "Enable SpaceBar Heating" options

The link to "editor config" (https://marketplace.visualstudio.com/editorconfig.org) is broken

bartsokol commented 1 year ago

Experiencing the same issue, formatting fails, the exception from the stack trace is as below. VS 2022 version 17.3.6.

Getting this exception when trying to reformat selection (Ctrl-K F). Formatting on save or formatting the whole file (Ctrl-E D) seems to work OK.

The formatting operation failed:
 System.AggregateException: One or more errors occurred. ---> StreamJsonRpc.RemoteInvocationException: Could not load type 'System.Runtime.CompilerServices.IsReadOnlyAttribute' from assembly 'System.Collections.Immutable, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
   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-FormatSelectionAsync@274-1.Invoke(Task`1 t) in C:\Users\nojaf\Projects\fantomas\src\Fantomas.Client\LSPFantomasService.fs:line 274
   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) StreamJsonRpc.RemoteInvocationException: Could not load type 'System.Runtime.CompilerServices.IsReadOnlyAttribute' from assembly 'System.Collections.Immutable, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
   at StreamJsonRpc.JsonRpc.<InvokeCoreAsync>d__143`1.MoveNext()
RPC server exception:
System.TypeLoadException: Could not load type 'System.Runtime.CompilerServices.IsReadOnlyAttribute' from assembly 'System.Collections.Immutable, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
      at System.ModuleHandle.ResolveType(QCallModule module, Int32 typeToken, IntPtr* typeInstArgs, Int32 typeInstCount, IntPtr* methodInstArgs, Int32 methodInstCount, ObjectHandleOnStack type)
      at System.ModuleHandle.ResolveTypeHandle(Int32 typeToken, RuntimeTypeHandle[] typeInstantiationContext, RuntimeTypeHandle[] methodInstantiationContext)
      at System.Reflection.RuntimeModule.ResolveType(Int32 metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
      at System.Reflection.CustomAttribute.FilterCustomAttributeRecord(MetadataToken caCtorToken, MetadataImport& scope, RuntimeModule decoratedModule, MetadataToken decoratedToken, RuntimeType attributeFilterType, Boolean mustBeInheritable, ListBuilder`1& derivedAttributes, RuntimeType& attributeType, IRuntimeMethodInfo& ctorWithParameters, Boolean& isVarArg)
      at System.Reflection.CustomAttribute.IsCustomAttributeDefined(RuntimeModule decoratedModule, Int32 decoratedMetadataToken, RuntimeType attributeFilterType, Int32 attributeCtorToken, Boolean mustBeInheritable)
      at System.Reflection.CustomAttribute.IsDefined(RuntimeMethodInfo method, RuntimeType caType, Boolean inherit)
      at System.Reflection.RuntimeMethodInfo.IsDefined(Type attributeType, Boolean inherit)
      at Newtonsoft.Json.Serialization.DefaultContractResolver.IsValidCallback(MethodInfo method, ParameterInfo[] parameters, Type attributeType, MethodInfo currentCallback, Type& prevAttributeType)
      at Newtonsoft.Json.Serialization.DefaultContractResolver.GetCallbackMethodsForType(Type type, List`1& onSerializing, List`1& onSerialized, List`1& onDeserializing, List`1& onDeserialized, List`1& onError)
      at Newtonsoft.Json.Serialization.DefaultContractResolver.ResolveCallbackMethods(JsonContract contract, Type t)
      at Newtonsoft.Json.Serialization.DefaultContractResolver.InitializeContract(JsonContract contract)
      at Newtonsoft.Json.Serialization.DefaultContractResolver.CreateObjectContract(Type objectType)
      at Newtonsoft.Json.Serialization.DefaultContractResolver.CreateContract(Type objectType)
      at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
      at Newtonsoft.Json.Utilities.ThreadSafeStore`2.Get(TKey key)
      at Newtonsoft.Json.Serialization.DefaultContractResolver.ResolveContract(Type type)
      at StreamJsonRpc.JsonMessageFormatter.ImplicitMarshalContractResolver.ResolveContract(Type type)
      at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.ResolvePropertyAndCreatorValues(JsonObjectContract contract, JsonProperty containerProperty, JsonReader reader, Type objectType)
      at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObjectUsingCreatorWithParameters(JsonReader reader, JsonObjectContract contract, JsonProperty containerProperty, ObjectConstructor`1 creator, String id)
      at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateNewObject(JsonReader reader, JsonObjectContract objectContract, JsonProperty containerMember, JsonProperty containerProperty, String id, Boolean& createdFromNonDefaultCreator)
      at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
      at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
      at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
      at Newtonsoft.Json.JsonSerializer.Deserialize(JsonReader reader, Type objectType)
      at Newtonsoft.Json.Linq.JToken.ToObject(Type objectType, JsonSerializer jsonSerializer)
      at StreamJsonRpc.JsonMessageFormatter.JsonRpcRequest.TryGetTypedArguments(ReadOnlySpan`1 parameters, Span`1 typedArguments)
      at StreamJsonRpc.TargetMethod.TryGetArguments(JsonRpcRequest request, MethodSignature method, Span`1 arguments)
      at StreamJsonRpc.TargetMethod..ctor(JsonRpcRequest request, List`1 candidateMethodTargets, SynchronizationContext fallbackSynchronizationContext)
      at StreamJsonRpc.Reflection.RpcTargetInfo.TryGetTargetMethod(JsonRpcRequest request, TargetMethod& targetMethod)
      at StreamJsonRpc.JsonRpc.DispatchIncomingRequestAsync(JsonRpcRequest request)
<---
nojaf commented 1 year ago

As for this last issue, @deviousasti a fix was made in Fantomas.Client 0.7.0. Please update the extension to that version. The fix is on both sides, users would need to update to fantomas 5.1.2 (or higher) in order for selection to work.

deviousasti commented 1 year ago

Will update Fantomas client.

deviousasti commented 1 year ago

Should be closed by #43