From cad33e95493deb2ba6d39e2b22a90683073c7d2a Mon Sep 17 00:00:00 2001 From: Alex Berezhnykh Date: Mon, 5 Apr 2021 15:07:10 +0300 Subject: [PATCH 01/17] Move Fantomas out-of-process --- ReSharper.FSharp/ReSharper.FSharp.sln | 14 +++ .../FSharp.ExternalFormatter.Protocol.csproj | 11 +++ .../src/ExternalFormatterConnection.cs | 17 ++++ .../src/ExternalFormatterProcess.cs | 69 +++++++++++++ .../src/ExternalFormatterProcessFactory.cs | 36 +++++++ .../src/ProtocolConstants.cs | 12 +++ .../FSharp.ExternalFormatter.csproj | 25 +++++ ...Sharp.ExternalFormatter.runtimeconfig.json | 9 ++ .../src/CodeFormatterProvider.cs | 98 +++++++++++++++++++ .../src/ExternalFormatterAssemblyResolver.cs | 43 ++++++++ .../src/ExternalFormatterEndPoint.cs | 51 ++++++++++ .../FSharp.ExternalFormatter/src/Program.cs | 27 +++++ .../FSharp.Psi.Features.fsproj | 3 +- .../src/Formatter/CodeFormatterProvider.fs | 62 ++++++++++++ .../src/Formatter/FSharpReformatCode.fs | 56 ++--------- rider-fsharp/build.gradle.kts | 31 +++++- .../model/RdFSharpExternalFormatterModel.kt | 70 +++++++++++++ 17 files changed, 581 insertions(+), 53 deletions(-) create mode 100644 ReSharper.FSharp/src/FSharp.ExternalFormatter.Protocol/FSharp.ExternalFormatter.Protocol.csproj create mode 100644 ReSharper.FSharp/src/FSharp.ExternalFormatter.Protocol/src/ExternalFormatterConnection.cs create mode 100644 ReSharper.FSharp/src/FSharp.ExternalFormatter.Protocol/src/ExternalFormatterProcess.cs create mode 100644 ReSharper.FSharp/src/FSharp.ExternalFormatter.Protocol/src/ExternalFormatterProcessFactory.cs create mode 100644 ReSharper.FSharp/src/FSharp.ExternalFormatter.Protocol/src/ProtocolConstants.cs create mode 100644 ReSharper.FSharp/src/FSharp.ExternalFormatter/FSharp.ExternalFormatter.csproj create mode 100644 ReSharper.FSharp/src/FSharp.ExternalFormatter/JetBrains.ReSharper.Plugins.FSharp.ExternalFormatter.runtimeconfig.json create mode 100644 ReSharper.FSharp/src/FSharp.ExternalFormatter/src/CodeFormatterProvider.cs create mode 100644 ReSharper.FSharp/src/FSharp.ExternalFormatter/src/ExternalFormatterAssemblyResolver.cs create mode 100644 ReSharper.FSharp/src/FSharp.ExternalFormatter/src/ExternalFormatterEndPoint.cs create mode 100644 ReSharper.FSharp/src/FSharp.ExternalFormatter/src/Program.cs create mode 100644 ReSharper.FSharp/src/FSharp.Psi.Features/src/Formatter/CodeFormatterProvider.fs create mode 100644 rider-fsharp/protocol/src/kotlin/model/RdFSharpExternalFormatterModel.kt diff --git a/ReSharper.FSharp/ReSharper.FSharp.sln b/ReSharper.FSharp/ReSharper.FSharp.sln index fc5dcbe0f8..a47de5a49f 100644 --- a/ReSharper.FSharp/ReSharper.FSharp.sln +++ b/ReSharper.FSharp/ReSharper.FSharp.sln @@ -25,6 +25,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FSharp.TypeProviders.Host", EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FSharp.TypeProviders.Protocol", "src\FSharp.TypeProviders.Protocol\FSharp.TypeProviders.Protocol.csproj", "{912A7F5F-73F2-4DFE-B81A-C13A4F58F31C}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FSharp.ExternalFormatter", "src\FSharp.ExternalFormatter\FSharp.ExternalFormatter.csproj", "{CF12A71A-1296-418B-8C0A-CC4B398AAB16}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FSharp.ExternalFormatter.Protocol", "src\FSharp.ExternalFormatter.Protocol\FSharp.ExternalFormatter.Protocol.csproj", "{D8DE097E-04DC-4A9B-88BF-10923FF44F8B}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -67,6 +71,14 @@ Global {912A7F5F-73F2-4DFE-B81A-C13A4F58F31C}.Debug|Any CPU.Build.0 = Debug|Any CPU {912A7F5F-73F2-4DFE-B81A-C13A4F58F31C}.Release|Any CPU.ActiveCfg = Release|Any CPU {912A7F5F-73F2-4DFE-B81A-C13A4F58F31C}.Release|Any CPU.Build.0 = Release|Any CPU + {CF12A71A-1296-418B-8C0A-CC4B398AAB16}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {CF12A71A-1296-418B-8C0A-CC4B398AAB16}.Debug|Any CPU.Build.0 = Debug|Any CPU + {CF12A71A-1296-418B-8C0A-CC4B398AAB16}.Release|Any CPU.ActiveCfg = Release|Any CPU + {CF12A71A-1296-418B-8C0A-CC4B398AAB16}.Release|Any CPU.Build.0 = Release|Any CPU + {D8DE097E-04DC-4A9B-88BF-10923FF44F8B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D8DE097E-04DC-4A9B-88BF-10923FF44F8B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D8DE097E-04DC-4A9B-88BF-10923FF44F8B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D8DE097E-04DC-4A9B-88BF-10923FF44F8B}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -81,5 +93,7 @@ Global {83C5104C-057E-4AF8-B3FE-3437968CA621} = {7B41BA27-ACA5-43D2-9EBA-2E604D63A4E2} {4EB01188-F511-4991-9A0F-604EE28E8F9B} = {2E19336B-3133-4C1A-8E65-E2F7C465663B} {912A7F5F-73F2-4DFE-B81A-C13A4F58F31C} = {2E19336B-3133-4C1A-8E65-E2F7C465663B} + {CF12A71A-1296-418B-8C0A-CC4B398AAB16} = {2E19336B-3133-4C1A-8E65-E2F7C465663B} + {D8DE097E-04DC-4A9B-88BF-10923FF44F8B} = {2E19336B-3133-4C1A-8E65-E2F7C465663B} EndGlobalSection EndGlobal diff --git a/ReSharper.FSharp/src/FSharp.ExternalFormatter.Protocol/FSharp.ExternalFormatter.Protocol.csproj b/ReSharper.FSharp/src/FSharp.ExternalFormatter.Protocol/FSharp.ExternalFormatter.Protocol.csproj new file mode 100644 index 0000000000..dcf597898e --- /dev/null +++ b/ReSharper.FSharp/src/FSharp.ExternalFormatter.Protocol/FSharp.ExternalFormatter.Protocol.csproj @@ -0,0 +1,11 @@ + + + + net461 + $(CSharpLanguageVersion) + JetBrains.ReSharper.Plugins.FSharp.ExternalFormatter.Protocol + + + + + diff --git a/ReSharper.FSharp/src/FSharp.ExternalFormatter.Protocol/src/ExternalFormatterConnection.cs b/ReSharper.FSharp/src/FSharp.ExternalFormatter.Protocol/src/ExternalFormatterConnection.cs new file mode 100644 index 0000000000..37fb8234f6 --- /dev/null +++ b/ReSharper.FSharp/src/FSharp.ExternalFormatter.Protocol/src/ExternalFormatterConnection.cs @@ -0,0 +1,17 @@ +using JetBrains.DataFlow; +using JetBrains.Lifetimes; +using JetBrains.Platform.RdFramework.ExternalProcess; +using JetBrains.Rd; +using JetBrains.Rider.FSharp.ExternalFormatter.Server; + +namespace FSharp.ExternalFormatter.Protocol +{ + public class ExternalFormatterConnection : ProtocolConnection + { + public ExternalFormatterConnection(Lifetime lifetime, RdFSharpExternalFormatterModel protocolModel, + IProtocol protocol, StartupOutputWriter startupOutputWriter, int processId, ISignal processUnexpectedExited) + : base(lifetime, protocolModel, protocol, startupOutputWriter, processId, processUnexpectedExited) + { + } + } +} diff --git a/ReSharper.FSharp/src/FSharp.ExternalFormatter.Protocol/src/ExternalFormatterProcess.cs b/ReSharper.FSharp/src/FSharp.ExternalFormatter.Protocol/src/ExternalFormatterProcess.cs new file mode 100644 index 0000000000..1d39be4c97 --- /dev/null +++ b/ReSharper.FSharp/src/FSharp.ExternalFormatter.Protocol/src/ExternalFormatterProcess.cs @@ -0,0 +1,69 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using JetBrains.Application.Processes; +using JetBrains.Application.Threading; +using JetBrains.DataFlow; +using JetBrains.Diagnostics; +using JetBrains.Lifetimes; +using JetBrains.Platform.RdFramework.ExternalProcess; +using JetBrains.Rd; +using JetBrains.Rider.FSharp.ExternalFormatter.Server; +using JetBrains.Util; + +namespace FSharp.ExternalFormatter.Protocol +{ + public class + ExternalFormatterProcess : ProtocolExternalProcess + { + protected override string Name => "External Formatter"; + + protected override RdFSharpExternalFormatterModel CreateModel(Lifetime lifetime, IProtocol protocol) => + new RdFSharpExternalFormatterModel(lifetime, protocol); + + protected override ExternalFormatterConnection CreateConnection(Lifetime lifetime, + RdFSharpExternalFormatterModel model, IProtocol protocol, StartupOutputWriter outputWriter, int processId, + Signal processUnexpectedExited) => + new ExternalFormatterConnection(lifetime, model, protocol, outputWriter, processId, + processUnexpectedExited); + + protected override ProcessStartInfo GetProcessStartInfo(int port) + { + var launchPath = GetType().Assembly.GetPath().Directory.Combine(ProtocolConstants.PROCESS_FILENAME); + Assertion.Assert(launchPath.ExistsFile, $"can't find '{ProtocolConstants.PROCESS_FILENAME}'"); + + return new ProcessStartInfo + { + Arguments = + $"{port} \"{ProtocolConstants.LogFolder.Combine($"{DateTime.UtcNow:yyyy_MM_dd_HH_mm_ss_ffff}.log")}\"", + FileName = launchPath.FullPath + }; + } + + protected override IDictionary GetAdditionalProcessEnvVars() + { + return new Dictionary() + { + { + "RIDER_PLUGIN_ADDITIONAL_PROBING_PATHS", + Environment.GetEnvironmentVariable("RIDER_PLUGIN_ADDITIONAL_PROBING_PATHS") + }, + { + ProtocolConstants.PARENT_PROCESS_PID_ENV_VARIABLE, + Process.GetCurrentProcess().Id.ToString() + }, + }; + } + + protected override bool Shutdown(RdFSharpExternalFormatterModel model) + { + return true; //todo + } + + public ExternalFormatterProcess(Lifetime lifetime, ILogger logger, IShellLocks locks, + IProcessStartInfoPatcher processInfoPatcher, JetProcessRuntimeRequest request) + : base(lifetime, logger, locks, processInfoPatcher, request) + { + } + } +} diff --git a/ReSharper.FSharp/src/FSharp.ExternalFormatter.Protocol/src/ExternalFormatterProcessFactory.cs b/ReSharper.FSharp/src/FSharp.ExternalFormatter.Protocol/src/ExternalFormatterProcessFactory.cs new file mode 100644 index 0000000000..7e589910ed --- /dev/null +++ b/ReSharper.FSharp/src/FSharp.ExternalFormatter.Protocol/src/ExternalFormatterProcessFactory.cs @@ -0,0 +1,36 @@ +using JetBrains.Annotations; +using JetBrains.Application.Processes; +using JetBrains.Application.Threading; +using JetBrains.Lifetimes; +using JetBrains.ProjectModel; +using JetBrains.Util; + +namespace FSharp.ExternalFormatter.Protocol +{ + [SolutionComponent] + public class ExternalFormatterProcessFactory + { + [NotNull] private readonly ISolutionProcessStartInfoPatcher mySolutionProcessStartInfoPatcher; + [NotNull] private readonly ILogger myLogger; + [NotNull] private readonly IShellLocks myShellLocks; + + public ExternalFormatterProcessFactory( + [NotNull] ISolutionProcessStartInfoPatcher solutionProcessStartInfoPatcher, + [NotNull] ILogger logger, + [NotNull] IShellLocks shellLocks) + { + mySolutionProcessStartInfoPatcher = solutionProcessStartInfoPatcher; + myLogger = logger; + myShellLocks = shellLocks; + } + + public ExternalFormatterProcess Create(Lifetime lifetime) + { + return new ExternalFormatterProcess(lifetime, + myLogger, + myShellLocks, + mySolutionProcessStartInfoPatcher, + JetProcessRuntimeRequest.CreateInternalRuntime()); + } + } +} diff --git a/ReSharper.FSharp/src/FSharp.ExternalFormatter.Protocol/src/ProtocolConstants.cs b/ReSharper.FSharp/src/FSharp.ExternalFormatter.Protocol/src/ProtocolConstants.cs new file mode 100644 index 0000000000..844635eda5 --- /dev/null +++ b/ReSharper.FSharp/src/FSharp.ExternalFormatter.Protocol/src/ProtocolConstants.cs @@ -0,0 +1,12 @@ +using JetBrains.Util; +using JetBrains.Util.Logging; + +namespace FSharp.ExternalFormatter.Protocol +{ + public static class ProtocolConstants + { + public const string PROCESS_FILENAME = "JetBrains.ReSharper.Plugins.FSharp.ExternalFormatter.dll"; + public const string PARENT_PROCESS_PID_ENV_VARIABLE = "FSHARP_EXTERNAL_FORMATTER_PROCESS_PID"; + public static readonly FileSystemPath LogFolder = Logger.LogFolderPath.Combine("ExternalFormatter"); + } +} diff --git a/ReSharper.FSharp/src/FSharp.ExternalFormatter/FSharp.ExternalFormatter.csproj b/ReSharper.FSharp/src/FSharp.ExternalFormatter/FSharp.ExternalFormatter.csproj new file mode 100644 index 0000000000..c45776315f --- /dev/null +++ b/ReSharper.FSharp/src/FSharp.ExternalFormatter/FSharp.ExternalFormatter.csproj @@ -0,0 +1,25 @@ + + + + net461 + JetBrains.ReSharper.Plugins.FSharp.ExternalFormatter + false + + + + + + + + + + + + + Always + + + + + + diff --git a/ReSharper.FSharp/src/FSharp.ExternalFormatter/JetBrains.ReSharper.Plugins.FSharp.ExternalFormatter.runtimeconfig.json b/ReSharper.FSharp/src/FSharp.ExternalFormatter/JetBrains.ReSharper.Plugins.FSharp.ExternalFormatter.runtimeconfig.json new file mode 100644 index 0000000000..ec942fede6 --- /dev/null +++ b/ReSharper.FSharp/src/FSharp.ExternalFormatter/JetBrains.ReSharper.Plugins.FSharp.ExternalFormatter.runtimeconfig.json @@ -0,0 +1,9 @@ +{ + "runtimeOptions": { + "tfm": "netcoreapp3.1", + "framework": { + "name": "Microsoft.NETCore.App", + "version": "3.1.0" + } + } +} diff --git a/ReSharper.FSharp/src/FSharp.ExternalFormatter/src/CodeFormatterProvider.cs b/ReSharper.FSharp/src/FSharp.ExternalFormatter/src/CodeFormatterProvider.cs new file mode 100644 index 0000000000..bff0364e00 --- /dev/null +++ b/ReSharper.FSharp/src/FSharp.ExternalFormatter/src/CodeFormatterProvider.cs @@ -0,0 +1,98 @@ +using Fantomas; +using FSharp.Compiler; +using FSharp.Compiler.CodeAnalysis; +using FSharp.Compiler.Diagnostics; +using FSharp.Compiler.SourceCodeServices; +using FSharp.Compiler.Text; +using JetBrains.Rider.FSharp.ExternalFormatter.Client; +using Microsoft.FSharp.Collections; +using Microsoft.FSharp.Control; + +namespace FSharp.ExternalFormatter +{ + internal interface ICodeFormatterProvider + { + string FormatSelection(RdFormatSelectionArgs args); + string FormatDocument(RdFormatDocumentArgs args); + } + + internal class BundledCodeFormatter : ICodeFormatterProvider + { + private readonly FSharpChecker myChecker = + FSharpChecker.Create(null, null, null, null, null, null, null, null, null, null); + + private readonly FormatConfig.FormatConfig myDefaultFormatConfig = FormatConfig.FormatConfig.Default; + + public string FormatSelection(RdFormatSelectionArgs args) => + FSharpAsync.StartAsTask( + CodeFormatter.FormatSelectionAsync( + args.FileName, + Convert(args.Range), + SourceOrigin.SourceOrigin.NewSourceString(args.Source), + Convert(args.FormatConfig), + Convert(args.ParsingOptions), + myChecker), null, null) + .Result; + + public string FormatDocument(RdFormatDocumentArgs args) => + FSharpAsync.StartAsTask( + CodeFormatter.FormatDocumentAsync( + args.FileName, + SourceOrigin.SourceOrigin.NewSourceString(args.Source), + Convert(args.FormatConfig), + Convert(args.ParsingOptions), + myChecker), null, null) + .Result; + + private static Range Convert(RdRange range) => + CodeFormatter.MakeRange(range.FileName, range.StartLine, range.StartCol, range.EndLine, range.EndCol); + + private static FSharpParsingOptions Convert(RdParsingOptions options) => + new FSharpParsingOptions( + options.SourceFiles, + FSharpList.Empty, + FSharpDiagnosticOptions.Default, + false, + options.LightSyntax, + false, + false); + + private FormatConfig.FormatConfig Convert(RdFormatConfig config) => + new FormatConfig.FormatConfig( + config.IndentSize, + config.MaxLineLength, + myDefaultFormatConfig.SemicolonAtEndOfLine, + config.SpaceBeforeParameter, + config.SpaceBeforeLowercaseInvocation, + config.SpaceBeforeUppercaseInvocation, + config.SpaceBeforeClassConstructor, + config.SpaceBeforeMember, + config.SpaceBeforeColon, + config.SpaceAfterComma, + config.SpaceBeforeSemicolon, + config.SpaceAfterSemicolon, + config.IndentOnTryWith, + config.SpaceAroundDelimiter, + config.MaxIfThenElseShortWidth, + config.MaxInfixOperatorExpression, + config.MaxRecordWidth, + myDefaultFormatConfig.MaxRecordNumberOfItems, + myDefaultFormatConfig.RecordMultilineFormatter, + config.MaxArrayOrListWidth, + myDefaultFormatConfig.MaxArrayOrListNumberOfItems, + myDefaultFormatConfig.ArrayOrListMultilineFormatter, + config.MaxValueBindingWidth, + config.MaxFunctionBindingWidth, + myDefaultFormatConfig.MaxDotGetExpressionWidth, + config.MultilineBlockBracketsOnSameColumn, + config.NewlineBetweenTypeDefinitionAndMembers, + config.KeepIfThenInSameLine, + config.MaxElmishWidth, + config.SingleArgumentWebMode, + config.AlignFunctionSignatureToIndentation, + config.AlternativeLongMemberDefinitions, + myDefaultFormatConfig.MultiLineLambdaClosingNewline, + myDefaultFormatConfig.DisableElmishSyntax, myDefaultFormatConfig.EndOfLine, + myDefaultFormatConfig.StrictMode); + } +} diff --git a/ReSharper.FSharp/src/FSharp.ExternalFormatter/src/ExternalFormatterAssemblyResolver.cs b/ReSharper.FSharp/src/FSharp.ExternalFormatter/src/ExternalFormatterAssemblyResolver.cs new file mode 100644 index 0000000000..5bbfadb0d5 --- /dev/null +++ b/ReSharper.FSharp/src/FSharp.ExternalFormatter/src/ExternalFormatterAssemblyResolver.cs @@ -0,0 +1,43 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Reflection; + +namespace FSharp.ExternalFormatter +{ + public static class ExternalFormatterAssemblyResolver + { + private const string AdditionalProbingPathsEnvVar = "RIDER_PLUGIN_ADDITIONAL_PROBING_PATHS"; + private static readonly List OurAdditionalProbingPaths = new List(); + + static ExternalFormatterAssemblyResolver() + { + var paths = Environment.GetEnvironmentVariable(AdditionalProbingPathsEnvVar); + if (string.IsNullOrWhiteSpace(paths)) return; + + foreach (var path in paths.Split(';')) + { + if (!string.IsNullOrEmpty(path)) OurAdditionalProbingPaths.Add(path); + } + } + + public static Assembly Resolve(object sender, ResolveEventArgs eventArgs) + { + var assemblyName = $"{new AssemblyName(eventArgs.Name).Name}.dll"; + + foreach (var path in OurAdditionalProbingPaths) + { + var assemblyPath = Path.Combine(path, assemblyName); + if (!File.Exists(assemblyPath)) continue; + + var assembly = Assembly.LoadFrom(assemblyPath); + return assembly; + } + + Console.Error.Write($"\nFailed to resolve assembly by name '{eventArgs.Name}'" + + $"\n Requesting assembly: {eventArgs.RequestingAssembly?.FullName}" + + $"\n Probing paths: {string.Join("\n", OurAdditionalProbingPaths)}"); + return null; + } + } +} diff --git a/ReSharper.FSharp/src/FSharp.ExternalFormatter/src/ExternalFormatterEndPoint.cs b/ReSharper.FSharp/src/FSharp.ExternalFormatter/src/ExternalFormatterEndPoint.cs new file mode 100644 index 0000000000..69e100d695 --- /dev/null +++ b/ReSharper.FSharp/src/FSharp.ExternalFormatter/src/ExternalFormatterEndPoint.cs @@ -0,0 +1,51 @@ +using FSharp.ExternalFormatter.Protocol; +using JetBrains.Diagnostics; +using JetBrains.Lifetimes; +using JetBrains.Platform.RdFramework.ExternalProcess; +using JetBrains.Rd.Impl; +using JetBrains.Rider.FSharp.ExternalFormatter.Client; +using JetBrains.Util; +using JetBrains.Util.Logging; +using JetBrains.Rd.Tasks; + +namespace FSharp.ExternalFormatter +{ + internal class ExternalFormatterEndPoint : ProtocolEndPoint + { + private readonly ICodeFormatterProvider myCodeFormatter; + protected override string ProtocolName => "External Formatter Host"; + + public ExternalFormatterEndPoint() : base(ProtocolConstants.PARENT_PROCESS_PID_ENV_VARIABLE) + { + myCodeFormatter = new BundledCodeFormatter(); + } + + protected override RdSimpleDispatcher InitDispatcher(Lifetime lifetime, ILogger logger) => + new RdSimpleDispatcher(lifetime, logger); + + protected override void InitLogger(Lifetime lifetime, string path) + { + LogManager.Instance.SetConfig(new XmlLogConfigModel()); + var logPath = FileSystemPath.TryParse(path); + if (logPath.IsNullOrEmpty()) return; + + var logEventListener = new FileLogEventListener(logPath); + LogManager.Instance.AddOmnipresentLogger(lifetime, logEventListener, LoggingLevel.TRACE); + } + + protected override RdFSharpExternalFormatterModel InitModel(Lifetime lifetime, JetBrains.Rd.Impl.Protocol protocol) + { + var model = new RdFSharpExternalFormatterModel(lifetime, protocol); + + model.FormatSelection.Set(FormatSelection); + model.FormatDocument.Set(FormatDocument); + + return model; + } + + private string FormatSelection(RdFormatSelectionArgs args) => myCodeFormatter.FormatSelection(args); + private string FormatDocument(RdFormatDocumentArgs args) => myCodeFormatter.FormatDocument(args); + + protected override void Run(Lifetime lifetime, RdSimpleDispatcher dispatcher) => dispatcher.Run(); + } +} diff --git a/ReSharper.FSharp/src/FSharp.ExternalFormatter/src/Program.cs b/ReSharper.FSharp/src/FSharp.ExternalFormatter/src/Program.cs new file mode 100644 index 0000000000..79fa037956 --- /dev/null +++ b/ReSharper.FSharp/src/FSharp.ExternalFormatter/src/Program.cs @@ -0,0 +1,27 @@ +using System; + +namespace FSharp.ExternalFormatter +{ + public static class Program + { + public static void Main(string[] args) + { + AppDomain.CurrentDomain.AssemblyResolve += ExternalFormatterAssemblyResolver.Resolve; + MainInternal(args); + } + + private static void MainInternal(string[] args) + { + var endPoint = new ExternalFormatterEndPoint(); + + var portValue = args[0]; + var logPath = string.Empty; + if (args.Length > 1) + { + logPath = args[1]; + } + + endPoint.Start(portValue, logPath); + } + } +} diff --git a/ReSharper.FSharp/src/FSharp.Psi.Features/FSharp.Psi.Features.fsproj b/ReSharper.FSharp/src/FSharp.Psi.Features/FSharp.Psi.Features.fsproj index c2f09e7232..7f3ff02036 100644 --- a/ReSharper.FSharp/src/FSharp.Psi.Features/FSharp.Psi.Features.fsproj +++ b/ReSharper.FSharp/src/FSharp.Psi.Features/FSharp.Psi.Features.fsproj @@ -105,6 +105,7 @@ + @@ -230,11 +231,11 @@ - + diff --git a/ReSharper.FSharp/src/FSharp.Psi.Features/src/Formatter/CodeFormatterProvider.fs b/ReSharper.FSharp/src/FSharp.Psi.Features/src/Formatter/CodeFormatterProvider.fs new file mode 100644 index 0000000000..c41fe2aadd --- /dev/null +++ b/ReSharper.FSharp/src/FSharp.Psi.Features/src/Formatter/CodeFormatterProvider.fs @@ -0,0 +1,62 @@ +namespace JetBrains.ReSharper.Plugins.FSharp.Services.Formatter + +open System +open FSharp.Compiler.CodeAnalysis +open FSharp.Compiler.Text +open FSharp.ExternalFormatter.Protocol +open JetBrains.Lifetimes +open JetBrains.ProjectModel +open JetBrains.Rider.FSharp.ExternalFormatter.Server + +[] +type CodeFormatterProvider(solution: ISolution, externalFormatterFactory: ExternalFormatterProcessFactory) = + let mutable connection: ExternalFormatterConnection = null + + let isConnectionAlive () = + isNotNull connection && connection.IsActive + + let connect () = + if isConnectionAlive () then () else + let formatterHostLifetime = Lifetime.Define(solution.GetLifetime()) + connection <- externalFormatterFactory.Create(formatterHostLifetime.Lifetime).Run() + + let execute (action: unit -> string) = + connect () + connection.Execute(action) + + let convertRange (range: range) = + RdRange(range.FileName, range.StartLine, range.StartColumn, range.EndLine, range.EndColumn) + + let convertFormatSettings (settings: FSharpFormatSettingsKey) = + RdFormatConfig + (settings.INDENT_SIZE, settings.WRAP_LIMIT, settings.SpaceBeforeParameter, + settings.SpaceBeforeLowercaseInvocation, settings.SpaceBeforeUppercaseInvocation, + settings.SpaceBeforeClassConstructor, settings.SpaceBeforeMember, settings.SpaceBeforeColon, + settings.SpaceAfterComma, settings.SpaceBeforeSemicolon, settings.SpaceAfterSemicolon, + settings.IndentOnTryWith, settings.SpaceAroundDelimiter, settings.MaxIfThenElseShortWidth, + settings.MaxInfixOperatorExpression, settings.MaxRecordWidth, settings.MaxArrayOrListWidth, + settings.MaxValueBindingWidth, settings.MaxFunctionBindingWidth, + settings.MultilineBlockBracketsOnSameColumn, settings.NewlineBetweenTypeDefinitionAndMembers, + settings.KeepIfThenInSameLine, settings.MaxElmishWidth, settings.SingleArgumentWebMode, + settings.AlignFunctionSignatureToIndentation, settings.AlternativeLongMemberDefinitions) + + let convertParsingOptions (options: FSharpParsingOptions) = + let lightSyntax = + match options.LightSyntax with + | Some x -> Nullable x + | None -> Nullable() + + RdParsingOptions(options.SourceFiles, lightSyntax) + + member x.FormatSelection(filePath: string, range: range, source: string, settings: FSharpFormatSettingsKey, + options: FSharpParsingOptions) = + let args = RdFormatSelectionArgs(filePath, convertRange range, source, convertFormatSettings settings, + convertParsingOptions options) + + execute (fun () -> connection.ProtocolModel.FormatSelection.Sync(args)) + + member x.FormatDocument(filePath: string, source: string, settings: FSharpFormatSettingsKey, + options: FSharpParsingOptions) = + let args = RdFormatDocumentArgs(filePath, source, convertFormatSettings settings, convertParsingOptions options) + + execute (fun () -> connection.ProtocolModel.FormatDocument.Sync(args)) diff --git a/ReSharper.FSharp/src/FSharp.Psi.Features/src/Formatter/FSharpReformatCode.fs b/ReSharper.FSharp/src/FSharp.Psi.Features/src/Formatter/FSharpReformatCode.fs index 37b82b1f2c..9a6e48b298 100644 --- a/ReSharper.FSharp/src/FSharp.Psi.Features/src/Formatter/FSharpReformatCode.fs +++ b/ReSharper.FSharp/src/FSharp.Psi.Features/src/Formatter/FSharpReformatCode.fs @@ -1,14 +1,11 @@ namespace JetBrains.ReSharper.Plugins.FSharp.Services.Formatter -open FSharp.Compiler.Text -open Fantomas -open Fantomas.FormatConfig open JetBrains.Application.Infra open JetBrains.DocumentModel open JetBrains.DocumentModel.Impl +open JetBrains.ProjectModel open JetBrains.ReSharper.Feature.Services.CSharp.CodeCleanup open JetBrains.ReSharper.Feature.Services.CodeCleanup -open JetBrains.ReSharper.Plugins.FSharp open JetBrains.ReSharper.Plugins.FSharp.Psi open JetBrains.ReSharper.Plugins.FSharp.Util open JetBrains.ReSharper.Psi @@ -39,57 +36,26 @@ type FSharpReformatCode() = match fsFile.ParseTree with // todo: completion on enter after with | None -> () - | Some parseTree -> + | Some _ -> let filePath = sourceFile.GetLocation().FullPath let document = sourceFile.Document :?> DocumentBase let text = document.GetText() - let source = SourceOrigin.SourceText(SourceText.ofString(document.GetText())) let checkerService = fsFile.CheckerService - let solution = fsFile.GetSolution() let settings = sourceFile.GetSettingsStoreWithEditorConfig() let languageService = fsFile.Language.LanguageServiceNotNull() let formatter = languageService.CodeFormatter + let codeFormatterProvider = solution.GetComponent() let settings = formatter.GetFormatterSettings(solution, sourceFile, settings, false) :?> FSharpFormatSettingsKey - let formatConfig = - { FormatConfig.Default with - IndentSize = settings.INDENT_SIZE - MaxLineLength = settings.WRAP_LIMIT - SpaceBeforeParameter = settings.SpaceBeforeParameter - SpaceBeforeLowercaseInvocation = settings.SpaceBeforeLowercaseInvocation - SpaceBeforeUppercaseInvocation = settings.SpaceBeforeUppercaseInvocation - SpaceBeforeClassConstructor = settings.SpaceBeforeClassConstructor - SpaceBeforeMember = settings.SpaceBeforeMember - SpaceBeforeColon = settings.SpaceBeforeColon - SpaceAfterComma = settings.SpaceAfterComma - SpaceBeforeSemicolon = settings.SpaceBeforeSemicolon - SpaceAfterSemicolon = settings.SpaceAfterSemicolon - IndentOnTryWith = settings.IndentOnTryWith - SpaceAroundDelimiter = settings.SpaceAroundDelimiter - MaxIfThenElseShortWidth = settings.MaxIfThenElseShortWidth - MaxInfixOperatorExpression = settings.MaxInfixOperatorExpression - MaxRecordWidth = settings.MaxRecordWidth - MaxArrayOrListWidth = settings.MaxArrayOrListWidth - MaxValueBindingWidth = settings.MaxValueBindingWidth - MaxFunctionBindingWidth = settings.MaxFunctionBindingWidth - MultilineBlockBracketsOnSameColumn = settings.MultilineBlockBracketsOnSameColumn - NewlineBetweenTypeDefinitionAndMembers = settings.NewlineBetweenTypeDefinitionAndMembers - KeepIfThenInSameLine = settings.KeepIfThenInSameLine - MaxElmishWidth = settings.MaxElmishWidth - SingleArgumentWebMode = settings.SingleArgumentWebMode - AlignFunctionSignatureToIndentation = settings.AlignFunctionSignatureToIndentation - AlternativeLongMemberDefinitions = settings.AlternativeLongMemberDefinitions } - let stamp = document.LastModificationStamp let modificationSide = TextModificationSide.NotSpecified let newLineText = sourceFile.DetectLineEnding().GetPresentation() let parsingOptions = checkerService.FcsProjectProvider.GetParsingOptions(sourceFile) - let checker = checkerService.Checker let change = if isNotNull rangeMarker then @@ -97,25 +63,17 @@ type FSharpReformatCode() = let range = ofDocumentRange rangeMarker.DocumentRange let formatted = - CodeFormatter - .FormatSelectionAsync(filePath, range, source, formatConfig, parsingOptions, checker) - .RunAsTask() + codeFormatterProvider + .FormatSelection(filePath, range, text, settings, parsingOptions) .Replace("\r\n", newLineText) let offset = rangeMarker.DocumentRange.StartOffset.Offset let oldLength = rangeMarker.DocumentRange.Length Some(DocumentChange(document, offset, oldLength, formatted, stamp, modificationSide)) with _ -> None else - let parsingOptions = checkerService.FcsProjectProvider.GetParsingOptions(sourceFile) - let defines = parsingOptions.ConditionalCompilationDefines - let formatTask = - if List.isEmpty defines - then CodeFormatter.FormatASTAsync(parseTree, filePath, defines, Some source, formatConfig) - else CodeFormatter.FormatDocumentAsync(filePath, source, formatConfig, parsingOptions, checker) - let formatted = - formatTask - .RunAsTask() + codeFormatterProvider + .FormatDocument(filePath, text, settings, parsingOptions) .Replace("\r\n", newLineText) Some(DocumentChange(document, 0, text.Length, formatted, stamp, modificationSide)) diff --git a/rider-fsharp/build.gradle.kts b/rider-fsharp/build.gradle.kts index 303c4dfbcf..e3261090f0 100644 --- a/rider-fsharp/build.gradle.kts +++ b/rider-fsharp/build.gradle.kts @@ -107,8 +107,7 @@ val libFiles = listOf( "FSharp.Common/bin/$buildConfiguration/net461/FSharp.Core.xml", "FSharp.Common/bin/$buildConfiguration/net461/FSharp.Compiler.Service.dll", // todo: add pdb after next repack "FSharp.Common/bin/$buildConfiguration/net461/FSharp.DependencyManager.Nuget.dll", - "FSharp.Common/bin/$buildConfiguration/net461/FSharp.Compiler.Interactive.Settings.dll", - "FSharp.Psi.Features/bin/$buildConfiguration/net461/Fantomas.dll") + "FSharp.Common/bin/$buildConfiguration/net461/FSharp.Compiler.Interactive.Settings.dll") val pluginFiles = listOf( "FSharp.ProjectModelBase/bin/$buildConfiguration/net461/JetBrains.ReSharper.Plugins.FSharp.ProjectModelBase", @@ -129,6 +128,14 @@ val typeProvidersFiles = listOf( "FSharp.TypeProviders.Host/bin/$buildConfiguration/netcoreapp3.1/tploader5.win.runtimeconfig.json", "FSharp.TypeProviders.Host/bin/$buildConfiguration/netcoreapp3.1/tploader5.unix.runtimeconfig.json") +val externalFormatterFiles = listOf( + "FSharp.ExternalFormatter.Protocol/bin/$buildConfiguration/net461/JetBrains.ReSharper.Plugins.FSharp.ExternalFormatter.Protocol.dll", + "FSharp.ExternalFormatter.Protocol/bin/$buildConfiguration/net461/JetBrains.ReSharper.Plugins.FSharp.ExternalFormatter.Protocol.pdb", + "FSharp.ExternalFormatter/bin/$buildConfiguration/net461/JetBrains.ReSharper.Plugins.FSharp.ExternalFormatter.dll", + "FSharp.ExternalFormatter/bin/$buildConfiguration/net461/JetBrains.ReSharper.Plugins.FSharp.ExternalFormatter.runtimeconfig.json", + "FSharp.ExternalFormatter/bin/$buildConfiguration/net461/JetBrains.ReSharper.Plugins.FSharp.ExternalFormatter.pdb", + "FSharp.ExternalFormatter/bin/$buildConfiguration/net461/Fantomas.dll") + val dotNetSdkPath by lazy { val sdkPath = intellij.ideaDependency.classes.resolve("lib").resolve("DotNetSdkForRdPlugins") if (sdkPath.isDirectory.not()) error("$sdkPath does not exist or not a directory") @@ -159,6 +166,9 @@ configure { val typeProviderClientOutput = File(repoRoot, "ReSharper.FSharp/src/FSharp.TypeProviders.Protocol/src/Client") val typeProviderServerOutput = File(repoRoot, "ReSharper.FSharp/src/FSharp.TypeProviders.Protocol/src/Server") + val externalFormatterServerOutput = File(repoRoot, "ReSharper.FSharp/src/FSharp.ExternalFormatter.Protocol/src/Server") + val externalFormatterClientOutput = File(repoRoot, "ReSharper.FSharp/src/FSharp.ExternalFormatter.Protocol/src/Client") + verbose = true hashFolder = "build/rdgen" logger.info("Configuring rdgen params") @@ -202,11 +212,26 @@ configure { namespace = "JetBrains.Rider.FSharp.TypeProviders.Protocol.Server" directory = "$typeProviderServerOutput" } + + generator { + language = "csharp" + transform = "asis" + root = "model.RdFSharpExternalFormatterModel" + namespace = "JetBrains.Rider.FSharp.ExternalFormatter.Server" + directory = "$externalFormatterServerOutput" + } + generator { + language = "csharp" + transform = "reversed" + root = "model.RdFSharpExternalFormatterModel" + namespace = "JetBrains.Rider.FSharp.ExternalFormatter.Client" + directory = "$externalFormatterClientOutput" + } } tasks { withType { - var files = libFiles + pluginFiles.map { "$it.dll" } + pluginFiles.map { "$it.pdb" } + typeProvidersFiles + var files = libFiles + pluginFiles.map { "$it.dll" } + pluginFiles.map { "$it.pdb" } + typeProvidersFiles + externalFormatterFiles files = files.map { "$resharperPluginPath/src/$it" } if (name == IntelliJPlugin.PREPARE_TESTING_SANDBOX_TASK_NAME) { diff --git a/rider-fsharp/protocol/src/kotlin/model/RdFSharpExternalFormatterModel.kt b/rider-fsharp/protocol/src/kotlin/model/RdFSharpExternalFormatterModel.kt new file mode 100644 index 0000000000..199f6f5c67 --- /dev/null +++ b/rider-fsharp/protocol/src/kotlin/model/RdFSharpExternalFormatterModel.kt @@ -0,0 +1,70 @@ +package model + +import com.jetbrains.rider.model.nova.ide.SolutionModel +import com.jetbrains.rd.generator.nova.* +import com.jetbrains.rd.generator.nova.PredefinedType.* +import com.jetbrains.rd.generator.nova.csharp.CSharp50Generator +import java.io.File + +@Suppress("unused") +object RdFSharpExternalFormatterModel : Root() { + + private val rdParsingOptions = structdef { + field("sourceFiles", array(string)) + field("lightSyntax", bool.nullable) + } + + private val rdRange = structdef { + field("fileName", string) + field("startLine", int) + field("startCol", int) + field("endLine", int) + field("endCol", int) + } + + private val rdFormatConfig = structdef { + field("indentSize", int) + field("maxLineLength", int) + field("spaceBeforeParameter", bool) + field("spaceBeforeLowercaseInvocation", bool) + field("spaceBeforeUppercaseInvocation", bool) + field("spaceBeforeClassConstructor", bool) + field("spaceBeforeMember", bool) + field("spaceBeforeColon", bool) + field("spaceAfterComma", bool) + field("spaceBeforeSemicolon", bool) + field("spaceAfterSemicolon", bool) + field("indentOnTryWith", bool) + field("spaceAroundDelimiter", bool) + field("maxIfThenElseShortWidth", int) + field("maxInfixOperatorExpression", int) + field("maxRecordWidth", int) + field("maxArrayOrListWidth", int) + field("maxValueBindingWidth", int) + field("maxFunctionBindingWidth", int) + field("multilineBlockBracketsOnSameColumn", bool) + field("newlineBetweenTypeDefinitionAndMembers", bool) + field("keepIfThenInSameLine", bool) + field("maxElmishWidth", int) + field("singleArgumentWebMode", bool) + field("alignFunctionSignatureToIndentation", bool) + field("alternativeLongMemberDefinitions", bool) + } + + init { + call("formatSelection", structdef("rdFormatSelectionArgs") { + field("fileName", string) + field("range", rdRange) + field("source", string) + field("formatConfig", rdFormatConfig) + field("parsingOptions", rdParsingOptions) + }, string) + + call("formatDocument", structdef("rdFormatDocumentArgs") { + field("fileName", string) + field("source", string) + field("formatConfig", rdFormatConfig) + field("parsingOptions", rdParsingOptions) + }, string) + } +} From a8dadc98ad859fa7846962ad9338819b5702ab26 Mon Sep 17 00:00:00 2001 From: Alex Berezhnykh Date: Mon, 5 Apr 2021 15:23:06 +0300 Subject: [PATCH 02/17] reformat --- .../src/CodeFormatterProvider.cs | 80 +++++-------------- 1 file changed, 21 insertions(+), 59 deletions(-) diff --git a/ReSharper.FSharp/src/FSharp.ExternalFormatter/src/CodeFormatterProvider.cs b/ReSharper.FSharp/src/FSharp.ExternalFormatter/src/CodeFormatterProvider.cs index bff0364e00..b8dc275851 100644 --- a/ReSharper.FSharp/src/FSharp.ExternalFormatter/src/CodeFormatterProvider.cs +++ b/ReSharper.FSharp/src/FSharp.ExternalFormatter/src/CodeFormatterProvider.cs @@ -1,8 +1,6 @@ using Fantomas; -using FSharp.Compiler; using FSharp.Compiler.CodeAnalysis; using FSharp.Compiler.Diagnostics; -using FSharp.Compiler.SourceCodeServices; using FSharp.Compiler.Text; using JetBrains.Rider.FSharp.ExternalFormatter.Client; using Microsoft.FSharp.Collections; @@ -25,74 +23,38 @@ internal class BundledCodeFormatter : ICodeFormatterProvider public string FormatSelection(RdFormatSelectionArgs args) => FSharpAsync.StartAsTask( - CodeFormatter.FormatSelectionAsync( - args.FileName, - Convert(args.Range), - SourceOrigin.SourceOrigin.NewSourceString(args.Source), - Convert(args.FormatConfig), - Convert(args.ParsingOptions), - myChecker), null, null) + CodeFormatter.FormatSelectionAsync(args.FileName, Convert(args.Range), + SourceOrigin.SourceOrigin.NewSourceString(args.Source), Convert(args.FormatConfig), + Convert(args.ParsingOptions), myChecker), null, null) .Result; public string FormatDocument(RdFormatDocumentArgs args) => FSharpAsync.StartAsTask( - CodeFormatter.FormatDocumentAsync( - args.FileName, - SourceOrigin.SourceOrigin.NewSourceString(args.Source), - Convert(args.FormatConfig), - Convert(args.ParsingOptions), - myChecker), null, null) + CodeFormatter.FormatDocumentAsync(args.FileName, SourceOrigin.SourceOrigin.NewSourceString(args.Source), + Convert(args.FormatConfig), Convert(args.ParsingOptions), myChecker), null, null) .Result; private static Range Convert(RdRange range) => CodeFormatter.MakeRange(range.FileName, range.StartLine, range.StartCol, range.EndLine, range.EndCol); private static FSharpParsingOptions Convert(RdParsingOptions options) => - new FSharpParsingOptions( - options.SourceFiles, - FSharpList.Empty, - FSharpDiagnosticOptions.Default, - false, - options.LightSyntax, - false, - false); + new FSharpParsingOptions(options.SourceFiles, FSharpList.Empty, FSharpDiagnosticOptions.Default, false, + options.LightSyntax, false, false); private FormatConfig.FormatConfig Convert(RdFormatConfig config) => - new FormatConfig.FormatConfig( - config.IndentSize, - config.MaxLineLength, - myDefaultFormatConfig.SemicolonAtEndOfLine, - config.SpaceBeforeParameter, - config.SpaceBeforeLowercaseInvocation, - config.SpaceBeforeUppercaseInvocation, - config.SpaceBeforeClassConstructor, - config.SpaceBeforeMember, - config.SpaceBeforeColon, - config.SpaceAfterComma, - config.SpaceBeforeSemicolon, - config.SpaceAfterSemicolon, - config.IndentOnTryWith, - config.SpaceAroundDelimiter, - config.MaxIfThenElseShortWidth, - config.MaxInfixOperatorExpression, - config.MaxRecordWidth, - myDefaultFormatConfig.MaxRecordNumberOfItems, - myDefaultFormatConfig.RecordMultilineFormatter, - config.MaxArrayOrListWidth, - myDefaultFormatConfig.MaxArrayOrListNumberOfItems, - myDefaultFormatConfig.ArrayOrListMultilineFormatter, - config.MaxValueBindingWidth, - config.MaxFunctionBindingWidth, - myDefaultFormatConfig.MaxDotGetExpressionWidth, - config.MultilineBlockBracketsOnSameColumn, - config.NewlineBetweenTypeDefinitionAndMembers, - config.KeepIfThenInSameLine, - config.MaxElmishWidth, - config.SingleArgumentWebMode, - config.AlignFunctionSignatureToIndentation, - config.AlternativeLongMemberDefinitions, - myDefaultFormatConfig.MultiLineLambdaClosingNewline, - myDefaultFormatConfig.DisableElmishSyntax, myDefaultFormatConfig.EndOfLine, - myDefaultFormatConfig.StrictMode); + new FormatConfig.FormatConfig(config.IndentSize, config.MaxLineLength, myDefaultFormatConfig.SemicolonAtEndOfLine, + config.SpaceBeforeParameter, config.SpaceBeforeLowercaseInvocation, config.SpaceBeforeUppercaseInvocation, + config.SpaceBeforeClassConstructor, config.SpaceBeforeMember, config.SpaceBeforeColon, config.SpaceAfterComma, + config.SpaceBeforeSemicolon, config.SpaceAfterSemicolon, config.IndentOnTryWith, config.SpaceAroundDelimiter, + config.MaxIfThenElseShortWidth, config.MaxInfixOperatorExpression, config.MaxRecordWidth, + myDefaultFormatConfig.MaxRecordNumberOfItems, myDefaultFormatConfig.RecordMultilineFormatter, + config.MaxArrayOrListWidth, myDefaultFormatConfig.MaxArrayOrListNumberOfItems, + myDefaultFormatConfig.ArrayOrListMultilineFormatter, config.MaxValueBindingWidth, + config.MaxFunctionBindingWidth, myDefaultFormatConfig.MaxDotGetExpressionWidth, + config.MultilineBlockBracketsOnSameColumn, config.NewlineBetweenTypeDefinitionAndMembers, + config.KeepIfThenInSameLine, config.MaxElmishWidth, config.SingleArgumentWebMode, + config.AlignFunctionSignatureToIndentation, config.AlternativeLongMemberDefinitions, + myDefaultFormatConfig.MultiLineLambdaClosingNewline, myDefaultFormatConfig.DisableElmishSyntax, + myDefaultFormatConfig.EndOfLine, myDefaultFormatConfig.StrictMode); } } From 9ef81d7767b33cb0e375c6449e585c6fbb5c7ab9 Mon Sep 17 00:00:00 2001 From: Alex Berezhnykh Date: Mon, 5 Apr 2021 17:53:58 +0300 Subject: [PATCH 03/17] =?UTF-8?q?=D1=86=D1=88=D0=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FSharp.ExternalFormatter.Protocol/src/ProtocolConstants.cs | 2 +- .../FSharp.ExternalFormatter/FSharp.ExternalFormatter.csproj | 1 + rider-fsharp/build.gradle.kts | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/ReSharper.FSharp/src/FSharp.ExternalFormatter.Protocol/src/ProtocolConstants.cs b/ReSharper.FSharp/src/FSharp.ExternalFormatter.Protocol/src/ProtocolConstants.cs index 844635eda5..2a187a6f3f 100644 --- a/ReSharper.FSharp/src/FSharp.ExternalFormatter.Protocol/src/ProtocolConstants.cs +++ b/ReSharper.FSharp/src/FSharp.ExternalFormatter.Protocol/src/ProtocolConstants.cs @@ -5,7 +5,7 @@ namespace FSharp.ExternalFormatter.Protocol { public static class ProtocolConstants { - public const string PROCESS_FILENAME = "JetBrains.ReSharper.Plugins.FSharp.ExternalFormatter.dll"; + public const string PROCESS_FILENAME = "JetBrains.ReSharper.Plugins.FSharp.ExternalFormatter.exe"; public const string PARENT_PROCESS_PID_ENV_VARIABLE = "FSHARP_EXTERNAL_FORMATTER_PROCESS_PID"; public static readonly FileSystemPath LogFolder = Logger.LogFolderPath.Combine("ExternalFormatter"); } diff --git a/ReSharper.FSharp/src/FSharp.ExternalFormatter/FSharp.ExternalFormatter.csproj b/ReSharper.FSharp/src/FSharp.ExternalFormatter/FSharp.ExternalFormatter.csproj index c45776315f..cd8df7facd 100644 --- a/ReSharper.FSharp/src/FSharp.ExternalFormatter/FSharp.ExternalFormatter.csproj +++ b/ReSharper.FSharp/src/FSharp.ExternalFormatter/FSharp.ExternalFormatter.csproj @@ -3,6 +3,7 @@ net461 JetBrains.ReSharper.Plugins.FSharp.ExternalFormatter + Exe false diff --git a/rider-fsharp/build.gradle.kts b/rider-fsharp/build.gradle.kts index e3261090f0..5f4a46c8b9 100644 --- a/rider-fsharp/build.gradle.kts +++ b/rider-fsharp/build.gradle.kts @@ -131,7 +131,7 @@ val typeProvidersFiles = listOf( val externalFormatterFiles = listOf( "FSharp.ExternalFormatter.Protocol/bin/$buildConfiguration/net461/JetBrains.ReSharper.Plugins.FSharp.ExternalFormatter.Protocol.dll", "FSharp.ExternalFormatter.Protocol/bin/$buildConfiguration/net461/JetBrains.ReSharper.Plugins.FSharp.ExternalFormatter.Protocol.pdb", - "FSharp.ExternalFormatter/bin/$buildConfiguration/net461/JetBrains.ReSharper.Plugins.FSharp.ExternalFormatter.dll", + "FSharp.ExternalFormatter/bin/$buildConfiguration/net461/JetBrains.ReSharper.Plugins.FSharp.ExternalFormatter.exe", "FSharp.ExternalFormatter/bin/$buildConfiguration/net461/JetBrains.ReSharper.Plugins.FSharp.ExternalFormatter.runtimeconfig.json", "FSharp.ExternalFormatter/bin/$buildConfiguration/net461/JetBrains.ReSharper.Plugins.FSharp.ExternalFormatter.pdb", "FSharp.ExternalFormatter/bin/$buildConfiguration/net461/Fantomas.dll") From 6657060c2443306d8bf190da190c002cd6a2169c Mon Sep 17 00:00:00 2001 From: Alex Berezhnykh Date: Tue, 6 Apr 2021 22:42:20 +0300 Subject: [PATCH 04/17] exit signal added --- .../src/ExternalFormatterProcess.cs | 4 +++- .../src/ExternalFormatterEndPoint.cs | 2 ++ .../src/Formatter/CodeFormatterProvider.fs | 5 +++-- .../src/kotlin/model/RdFSharpExternalFormatterModel.kt | 2 ++ 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/ReSharper.FSharp/src/FSharp.ExternalFormatter.Protocol/src/ExternalFormatterProcess.cs b/ReSharper.FSharp/src/FSharp.ExternalFormatter.Protocol/src/ExternalFormatterProcess.cs index 1d39be4c97..d0a053c42b 100644 --- a/ReSharper.FSharp/src/FSharp.ExternalFormatter.Protocol/src/ExternalFormatterProcess.cs +++ b/ReSharper.FSharp/src/FSharp.ExternalFormatter.Protocol/src/ExternalFormatterProcess.cs @@ -3,6 +3,7 @@ using System.Diagnostics; using JetBrains.Application.Processes; using JetBrains.Application.Threading; +using JetBrains.Core; using JetBrains.DataFlow; using JetBrains.Diagnostics; using JetBrains.Lifetimes; @@ -57,7 +58,8 @@ protected override IDictionary GetAdditionalProcessEnvVars() protected override bool Shutdown(RdFSharpExternalFormatterModel model) { - return true; //todo + model.Proto.Scheduler.Queue(() => model.Exit.Fire(Unit.Instance)); + return true; } public ExternalFormatterProcess(Lifetime lifetime, ILogger logger, IShellLocks locks, diff --git a/ReSharper.FSharp/src/FSharp.ExternalFormatter/src/ExternalFormatterEndPoint.cs b/ReSharper.FSharp/src/FSharp.ExternalFormatter/src/ExternalFormatterEndPoint.cs index 69e100d695..7057f6abc6 100644 --- a/ReSharper.FSharp/src/FSharp.ExternalFormatter/src/ExternalFormatterEndPoint.cs +++ b/ReSharper.FSharp/src/FSharp.ExternalFormatter/src/ExternalFormatterEndPoint.cs @@ -1,4 +1,5 @@ using FSharp.ExternalFormatter.Protocol; +using JetBrains.Collections.Viewable; using JetBrains.Diagnostics; using JetBrains.Lifetimes; using JetBrains.Platform.RdFramework.ExternalProcess; @@ -39,6 +40,7 @@ protected override RdFSharpExternalFormatterModel InitModel(Lifetime lifetime, J model.FormatSelection.Set(FormatSelection); model.FormatDocument.Set(FormatDocument); + model.Exit.Advise(lifetime, Terminate); return model; } diff --git a/ReSharper.FSharp/src/FSharp.Psi.Features/src/Formatter/CodeFormatterProvider.fs b/ReSharper.FSharp/src/FSharp.Psi.Features/src/Formatter/CodeFormatterProvider.fs index c41fe2aadd..800b67c5c1 100644 --- a/ReSharper.FSharp/src/FSharp.Psi.Features/src/Formatter/CodeFormatterProvider.fs +++ b/ReSharper.FSharp/src/FSharp.Psi.Features/src/Formatter/CodeFormatterProvider.fs @@ -6,6 +6,7 @@ open FSharp.Compiler.Text open FSharp.ExternalFormatter.Protocol open JetBrains.Lifetimes open JetBrains.ProjectModel +open JetBrains.Rd.Tasks open JetBrains.Rider.FSharp.ExternalFormatter.Server [] @@ -53,10 +54,10 @@ type CodeFormatterProvider(solution: ISolution, externalFormatterFactory: Extern let args = RdFormatSelectionArgs(filePath, convertRange range, source, convertFormatSettings settings, convertParsingOptions options) - execute (fun () -> connection.ProtocolModel.FormatSelection.Sync(args)) + execute (fun () -> connection.ProtocolModel.FormatSelection.Sync(args, RpcTimeouts.Maximal)) member x.FormatDocument(filePath: string, source: string, settings: FSharpFormatSettingsKey, options: FSharpParsingOptions) = let args = RdFormatDocumentArgs(filePath, source, convertFormatSettings settings, convertParsingOptions options) - execute (fun () -> connection.ProtocolModel.FormatDocument.Sync(args)) + execute (fun () -> connection.ProtocolModel.FormatDocument.Sync(args, RpcTimeouts.Maximal)) diff --git a/rider-fsharp/protocol/src/kotlin/model/RdFSharpExternalFormatterModel.kt b/rider-fsharp/protocol/src/kotlin/model/RdFSharpExternalFormatterModel.kt index 199f6f5c67..e0e44b680e 100644 --- a/rider-fsharp/protocol/src/kotlin/model/RdFSharpExternalFormatterModel.kt +++ b/rider-fsharp/protocol/src/kotlin/model/RdFSharpExternalFormatterModel.kt @@ -66,5 +66,7 @@ object RdFSharpExternalFormatterModel : Root() { field("formatConfig", rdFormatConfig) field("parsingOptions", rdParsingOptions) }, string) + + signal("Exit", void) } } From 2281cae958bd01d552ca108c1d2e92b6d6b550d5 Mon Sep 17 00:00:00 2001 From: Alex Berezhnykh Date: Thu, 22 Apr 2021 13:28:40 +0300 Subject: [PATCH 05/17] rename --- ReSharper.FSharp/ReSharper.FSharp.sln | 2 +- .../FSharp.ExternalFormatter.Host.csproj} | 4 ++-- ...gins.FSharp.ExternalFormatter.Host.runtimeconfig.json} | 0 .../src/CodeFormatterProvider.cs | 5 +++-- .../src/ExternalFormatterAssemblyResolver.cs | 2 +- .../src/ExternalFormatterEndPoint.cs | 2 +- .../src/Program.cs | 2 +- .../src/ProtocolConstants.cs | 2 +- rider-fsharp/build.gradle.kts | 8 ++++---- 9 files changed, 14 insertions(+), 13 deletions(-) rename ReSharper.FSharp/src/{FSharp.ExternalFormatter/FSharp.ExternalFormatter.csproj => FSharp.ExternalFormatter.Host/FSharp.ExternalFormatter.Host.csproj} (94%) rename ReSharper.FSharp/src/{FSharp.ExternalFormatter/JetBrains.ReSharper.Plugins.FSharp.ExternalFormatter.runtimeconfig.json => FSharp.ExternalFormatter.Host/JetBrains.ReSharper.Plugins.FSharp.ExternalFormatter.Host.runtimeconfig.json} (100%) rename ReSharper.FSharp/src/{FSharp.ExternalFormatter => FSharp.ExternalFormatter.Host}/src/CodeFormatterProvider.cs (96%) rename ReSharper.FSharp/src/{FSharp.ExternalFormatter => FSharp.ExternalFormatter.Host}/src/ExternalFormatterAssemblyResolver.cs (97%) rename ReSharper.FSharp/src/{FSharp.ExternalFormatter => FSharp.ExternalFormatter.Host}/src/ExternalFormatterEndPoint.cs (98%) rename ReSharper.FSharp/src/{FSharp.ExternalFormatter => FSharp.ExternalFormatter.Host}/src/Program.cs (92%) diff --git a/ReSharper.FSharp/ReSharper.FSharp.sln b/ReSharper.FSharp/ReSharper.FSharp.sln index a47de5a49f..c78ab36146 100644 --- a/ReSharper.FSharp/ReSharper.FSharp.sln +++ b/ReSharper.FSharp/ReSharper.FSharp.sln @@ -25,7 +25,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FSharp.TypeProviders.Host", EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FSharp.TypeProviders.Protocol", "src\FSharp.TypeProviders.Protocol\FSharp.TypeProviders.Protocol.csproj", "{912A7F5F-73F2-4DFE-B81A-C13A4F58F31C}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FSharp.ExternalFormatter", "src\FSharp.ExternalFormatter\FSharp.ExternalFormatter.csproj", "{CF12A71A-1296-418B-8C0A-CC4B398AAB16}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FSharp.ExternalFormatter.Host", "src\FSharp.ExternalFormatter.Host\FSharp.ExternalFormatter.Host.csproj", "{CF12A71A-1296-418B-8C0A-CC4B398AAB16}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FSharp.ExternalFormatter.Protocol", "src\FSharp.ExternalFormatter.Protocol\FSharp.ExternalFormatter.Protocol.csproj", "{D8DE097E-04DC-4A9B-88BF-10923FF44F8B}" EndProject diff --git a/ReSharper.FSharp/src/FSharp.ExternalFormatter/FSharp.ExternalFormatter.csproj b/ReSharper.FSharp/src/FSharp.ExternalFormatter.Host/FSharp.ExternalFormatter.Host.csproj similarity index 94% rename from ReSharper.FSharp/src/FSharp.ExternalFormatter/FSharp.ExternalFormatter.csproj rename to ReSharper.FSharp/src/FSharp.ExternalFormatter.Host/FSharp.ExternalFormatter.Host.csproj index cd8df7facd..a05270738b 100644 --- a/ReSharper.FSharp/src/FSharp.ExternalFormatter/FSharp.ExternalFormatter.csproj +++ b/ReSharper.FSharp/src/FSharp.ExternalFormatter.Host/FSharp.ExternalFormatter.Host.csproj @@ -2,7 +2,7 @@ net461 - JetBrains.ReSharper.Plugins.FSharp.ExternalFormatter + JetBrains.ReSharper.Plugins.FSharp.ExternalFormatter.Host Exe false @@ -16,7 +16,7 @@ - + Always diff --git a/ReSharper.FSharp/src/FSharp.ExternalFormatter/JetBrains.ReSharper.Plugins.FSharp.ExternalFormatter.runtimeconfig.json b/ReSharper.FSharp/src/FSharp.ExternalFormatter.Host/JetBrains.ReSharper.Plugins.FSharp.ExternalFormatter.Host.runtimeconfig.json similarity index 100% rename from ReSharper.FSharp/src/FSharp.ExternalFormatter/JetBrains.ReSharper.Plugins.FSharp.ExternalFormatter.runtimeconfig.json rename to ReSharper.FSharp/src/FSharp.ExternalFormatter.Host/JetBrains.ReSharper.Plugins.FSharp.ExternalFormatter.Host.runtimeconfig.json diff --git a/ReSharper.FSharp/src/FSharp.ExternalFormatter/src/CodeFormatterProvider.cs b/ReSharper.FSharp/src/FSharp.ExternalFormatter.Host/src/CodeFormatterProvider.cs similarity index 96% rename from ReSharper.FSharp/src/FSharp.ExternalFormatter/src/CodeFormatterProvider.cs rename to ReSharper.FSharp/src/FSharp.ExternalFormatter.Host/src/CodeFormatterProvider.cs index b8dc275851..1c89b06f34 100644 --- a/ReSharper.FSharp/src/FSharp.ExternalFormatter/src/CodeFormatterProvider.cs +++ b/ReSharper.FSharp/src/FSharp.ExternalFormatter.Host/src/CodeFormatterProvider.cs @@ -6,7 +6,7 @@ using Microsoft.FSharp.Collections; using Microsoft.FSharp.Control; -namespace FSharp.ExternalFormatter +namespace FSharp.ExternalFormatter.Host { internal interface ICodeFormatterProvider { @@ -42,7 +42,8 @@ private static FSharpParsingOptions Convert(RdParsingOptions options) => options.LightSyntax, false, false); private FormatConfig.FormatConfig Convert(RdFormatConfig config) => - new FormatConfig.FormatConfig(config.IndentSize, config.MaxLineLength, myDefaultFormatConfig.SemicolonAtEndOfLine, + new FormatConfig.FormatConfig(config.IndentSize, config.MaxLineLength, + myDefaultFormatConfig.SemicolonAtEndOfLine, config.SpaceBeforeParameter, config.SpaceBeforeLowercaseInvocation, config.SpaceBeforeUppercaseInvocation, config.SpaceBeforeClassConstructor, config.SpaceBeforeMember, config.SpaceBeforeColon, config.SpaceAfterComma, config.SpaceBeforeSemicolon, config.SpaceAfterSemicolon, config.IndentOnTryWith, config.SpaceAroundDelimiter, diff --git a/ReSharper.FSharp/src/FSharp.ExternalFormatter/src/ExternalFormatterAssemblyResolver.cs b/ReSharper.FSharp/src/FSharp.ExternalFormatter.Host/src/ExternalFormatterAssemblyResolver.cs similarity index 97% rename from ReSharper.FSharp/src/FSharp.ExternalFormatter/src/ExternalFormatterAssemblyResolver.cs rename to ReSharper.FSharp/src/FSharp.ExternalFormatter.Host/src/ExternalFormatterAssemblyResolver.cs index 5bbfadb0d5..c88e82f23b 100644 --- a/ReSharper.FSharp/src/FSharp.ExternalFormatter/src/ExternalFormatterAssemblyResolver.cs +++ b/ReSharper.FSharp/src/FSharp.ExternalFormatter.Host/src/ExternalFormatterAssemblyResolver.cs @@ -3,7 +3,7 @@ using System.IO; using System.Reflection; -namespace FSharp.ExternalFormatter +namespace FSharp.ExternalFormatter.Host { public static class ExternalFormatterAssemblyResolver { diff --git a/ReSharper.FSharp/src/FSharp.ExternalFormatter/src/ExternalFormatterEndPoint.cs b/ReSharper.FSharp/src/FSharp.ExternalFormatter.Host/src/ExternalFormatterEndPoint.cs similarity index 98% rename from ReSharper.FSharp/src/FSharp.ExternalFormatter/src/ExternalFormatterEndPoint.cs rename to ReSharper.FSharp/src/FSharp.ExternalFormatter.Host/src/ExternalFormatterEndPoint.cs index 7057f6abc6..4de31f2e6f 100644 --- a/ReSharper.FSharp/src/FSharp.ExternalFormatter/src/ExternalFormatterEndPoint.cs +++ b/ReSharper.FSharp/src/FSharp.ExternalFormatter.Host/src/ExternalFormatterEndPoint.cs @@ -9,7 +9,7 @@ using JetBrains.Util.Logging; using JetBrains.Rd.Tasks; -namespace FSharp.ExternalFormatter +namespace FSharp.ExternalFormatter.Host { internal class ExternalFormatterEndPoint : ProtocolEndPoint { diff --git a/ReSharper.FSharp/src/FSharp.ExternalFormatter/src/Program.cs b/ReSharper.FSharp/src/FSharp.ExternalFormatter.Host/src/Program.cs similarity index 92% rename from ReSharper.FSharp/src/FSharp.ExternalFormatter/src/Program.cs rename to ReSharper.FSharp/src/FSharp.ExternalFormatter.Host/src/Program.cs index 79fa037956..dbc79959a2 100644 --- a/ReSharper.FSharp/src/FSharp.ExternalFormatter/src/Program.cs +++ b/ReSharper.FSharp/src/FSharp.ExternalFormatter.Host/src/Program.cs @@ -1,6 +1,6 @@ using System; -namespace FSharp.ExternalFormatter +namespace FSharp.ExternalFormatter.Host { public static class Program { diff --git a/ReSharper.FSharp/src/FSharp.ExternalFormatter.Protocol/src/ProtocolConstants.cs b/ReSharper.FSharp/src/FSharp.ExternalFormatter.Protocol/src/ProtocolConstants.cs index 2a187a6f3f..d60b1c63ce 100644 --- a/ReSharper.FSharp/src/FSharp.ExternalFormatter.Protocol/src/ProtocolConstants.cs +++ b/ReSharper.FSharp/src/FSharp.ExternalFormatter.Protocol/src/ProtocolConstants.cs @@ -5,7 +5,7 @@ namespace FSharp.ExternalFormatter.Protocol { public static class ProtocolConstants { - public const string PROCESS_FILENAME = "JetBrains.ReSharper.Plugins.FSharp.ExternalFormatter.exe"; + public const string PROCESS_FILENAME = "JetBrains.ReSharper.Plugins.FSharp.ExternalFormatter.Host.exe"; public const string PARENT_PROCESS_PID_ENV_VARIABLE = "FSHARP_EXTERNAL_FORMATTER_PROCESS_PID"; public static readonly FileSystemPath LogFolder = Logger.LogFolderPath.Combine("ExternalFormatter"); } diff --git a/rider-fsharp/build.gradle.kts b/rider-fsharp/build.gradle.kts index 5f4a46c8b9..c090ed263f 100644 --- a/rider-fsharp/build.gradle.kts +++ b/rider-fsharp/build.gradle.kts @@ -131,10 +131,10 @@ val typeProvidersFiles = listOf( val externalFormatterFiles = listOf( "FSharp.ExternalFormatter.Protocol/bin/$buildConfiguration/net461/JetBrains.ReSharper.Plugins.FSharp.ExternalFormatter.Protocol.dll", "FSharp.ExternalFormatter.Protocol/bin/$buildConfiguration/net461/JetBrains.ReSharper.Plugins.FSharp.ExternalFormatter.Protocol.pdb", - "FSharp.ExternalFormatter/bin/$buildConfiguration/net461/JetBrains.ReSharper.Plugins.FSharp.ExternalFormatter.exe", - "FSharp.ExternalFormatter/bin/$buildConfiguration/net461/JetBrains.ReSharper.Plugins.FSharp.ExternalFormatter.runtimeconfig.json", - "FSharp.ExternalFormatter/bin/$buildConfiguration/net461/JetBrains.ReSharper.Plugins.FSharp.ExternalFormatter.pdb", - "FSharp.ExternalFormatter/bin/$buildConfiguration/net461/Fantomas.dll") + "FSharp.ExternalFormatter.Host/bin/$buildConfiguration/net461/JetBrains.ReSharper.Plugins.FSharp.ExternalFormatter.Host.exe", + "FSharp.ExternalFormatter.Host/bin/$buildConfiguration/net461/JetBrains.ReSharper.Plugins.FSharp.ExternalFormatter.Host.runtimeconfig.json", + "FSharp.ExternalFormatter.Host/bin/$buildConfiguration/net461/JetBrains.ReSharper.Plugins.FSharp.ExternalFormatter.Host.pdb", + "FSharp.ExternalFormatter.Host/bin/$buildConfiguration/net461/Fantomas.dll") val dotNetSdkPath by lazy { val sdkPath = intellij.ideaDependency.classes.resolve("lib").resolve("DotNetSdkForRdPlugins") From 176d1928044ac3e259914d391b74c4c5ab1b0ccd Mon Sep 17 00:00:00 2001 From: Alex Berezhnykh Date: Tue, 27 Apr 2021 13:55:31 +0300 Subject: [PATCH 06/17] different review fixes --- .../src/CodeFormatterProvider.cs | 26 ++++++-------- .../src/ExternalFormatterEndPoint.cs | 6 ++-- .../src/ExternalFormatterProcess.cs | 8 ++--- ...stants.cs => FantomasProtocolConstants.cs} | 2 +- .../src/Formatter/CodeFormatterProvider.fs | 20 +++++------ .../src/Formatter/FSharpReformatCode.fs | 9 ++--- .../src/TypeProvidersEndPoint.cs | 2 +- .../src/TypeProvidersExternalProcess.cs | 12 +++---- ...s.cs => TypeProvidersProtocolConstants.cs} | 2 +- .../model/RdFSharpExternalFormatterModel.kt | 34 +++++++++---------- 10 files changed, 55 insertions(+), 66 deletions(-) rename ReSharper.FSharp/src/FSharp.ExternalFormatter.Protocol/src/{ProtocolConstants.cs => FantomasProtocolConstants.cs} (89%) rename ReSharper.FSharp/src/FSharp.TypeProviders.Protocol/src/{ProtocolConstants.cs => TypeProvidersProtocolConstants.cs} (93%) diff --git a/ReSharper.FSharp/src/FSharp.ExternalFormatter.Host/src/CodeFormatterProvider.cs b/ReSharper.FSharp/src/FSharp.ExternalFormatter.Host/src/CodeFormatterProvider.cs index 1c89b06f34..59740fd5a7 100644 --- a/ReSharper.FSharp/src/FSharp.ExternalFormatter.Host/src/CodeFormatterProvider.cs +++ b/ReSharper.FSharp/src/FSharp.ExternalFormatter.Host/src/CodeFormatterProvider.cs @@ -8,13 +8,7 @@ namespace FSharp.ExternalFormatter.Host { - internal interface ICodeFormatterProvider - { - string FormatSelection(RdFormatSelectionArgs args); - string FormatDocument(RdFormatDocumentArgs args); - } - - internal class BundledCodeFormatter : ICodeFormatterProvider + internal class ExternalCodeFormatter { private readonly FSharpChecker myChecker = FSharpChecker.Create(null, null, null, null, null, null, null, null, null, null); @@ -26,24 +20,24 @@ public string FormatSelection(RdFormatSelectionArgs args) => CodeFormatter.FormatSelectionAsync(args.FileName, Convert(args.Range), SourceOrigin.SourceOrigin.NewSourceString(args.Source), Convert(args.FormatConfig), Convert(args.ParsingOptions), myChecker), null, null) - .Result; + .Result.Replace("\r\n", args.NewLineText); public string FormatDocument(RdFormatDocumentArgs args) => FSharpAsync.StartAsTask( CodeFormatter.FormatDocumentAsync(args.FileName, SourceOrigin.SourceOrigin.NewSourceString(args.Source), Convert(args.FormatConfig), Convert(args.ParsingOptions), myChecker), null, null) - .Result; + .Result.Replace("\r\n", args.NewLineText); - private static Range Convert(RdRange range) => + private static Range Convert(RdFcsRange range) => CodeFormatter.MakeRange(range.FileName, range.StartLine, range.StartCol, range.EndLine, range.EndCol); - private static FSharpParsingOptions Convert(RdParsingOptions options) => - new FSharpParsingOptions(options.SourceFiles, FSharpList.Empty, FSharpDiagnosticOptions.Default, false, - options.LightSyntax, false, false); + private static FSharpParsingOptions Convert(RdFcsParsingOptions options) => + new FSharpParsingOptions(new[] {options.LastSourceFile}, + ListModule.OfArray(options.ConditionalCompilationDefines), FSharpDiagnosticOptions.Default, false, + options.LightSyntax, false, options.IsExe); - private FormatConfig.FormatConfig Convert(RdFormatConfig config) => - new FormatConfig.FormatConfig(config.IndentSize, config.MaxLineLength, - myDefaultFormatConfig.SemicolonAtEndOfLine, + private FormatConfig.FormatConfig Convert(RdFantomasFormatConfig config) => + new FormatConfig.FormatConfig(config.IndentSize, config.MaxLineLength, myDefaultFormatConfig.SemicolonAtEndOfLine, config.SpaceBeforeParameter, config.SpaceBeforeLowercaseInvocation, config.SpaceBeforeUppercaseInvocation, config.SpaceBeforeClassConstructor, config.SpaceBeforeMember, config.SpaceBeforeColon, config.SpaceAfterComma, config.SpaceBeforeSemicolon, config.SpaceAfterSemicolon, config.IndentOnTryWith, config.SpaceAroundDelimiter, diff --git a/ReSharper.FSharp/src/FSharp.ExternalFormatter.Host/src/ExternalFormatterEndPoint.cs b/ReSharper.FSharp/src/FSharp.ExternalFormatter.Host/src/ExternalFormatterEndPoint.cs index 4de31f2e6f..917cbf7eff 100644 --- a/ReSharper.FSharp/src/FSharp.ExternalFormatter.Host/src/ExternalFormatterEndPoint.cs +++ b/ReSharper.FSharp/src/FSharp.ExternalFormatter.Host/src/ExternalFormatterEndPoint.cs @@ -13,12 +13,12 @@ namespace FSharp.ExternalFormatter.Host { internal class ExternalFormatterEndPoint : ProtocolEndPoint { - private readonly ICodeFormatterProvider myCodeFormatter; + private readonly ExternalCodeFormatter myCodeFormatter; protected override string ProtocolName => "External Formatter Host"; - public ExternalFormatterEndPoint() : base(ProtocolConstants.PARENT_PROCESS_PID_ENV_VARIABLE) + public ExternalFormatterEndPoint() : base(FantomasProtocolConstants.PARENT_PROCESS_PID_ENV_VARIABLE) { - myCodeFormatter = new BundledCodeFormatter(); + myCodeFormatter = new ExternalCodeFormatter(); } protected override RdSimpleDispatcher InitDispatcher(Lifetime lifetime, ILogger logger) => diff --git a/ReSharper.FSharp/src/FSharp.ExternalFormatter.Protocol/src/ExternalFormatterProcess.cs b/ReSharper.FSharp/src/FSharp.ExternalFormatter.Protocol/src/ExternalFormatterProcess.cs index d0a053c42b..95d17dfc2a 100644 --- a/ReSharper.FSharp/src/FSharp.ExternalFormatter.Protocol/src/ExternalFormatterProcess.cs +++ b/ReSharper.FSharp/src/FSharp.ExternalFormatter.Protocol/src/ExternalFormatterProcess.cs @@ -30,13 +30,13 @@ protected override ExternalFormatterConnection CreateConnection(Lifetime lifetim protected override ProcessStartInfo GetProcessStartInfo(int port) { - var launchPath = GetType().Assembly.GetPath().Directory.Combine(ProtocolConstants.PROCESS_FILENAME); - Assertion.Assert(launchPath.ExistsFile, $"can't find '{ProtocolConstants.PROCESS_FILENAME}'"); + var launchPath = GetType().Assembly.GetPath().Directory.Combine(FantomasProtocolConstants.PROCESS_FILENAME); + Assertion.Assert(launchPath.ExistsFile, $"can't find '{FantomasProtocolConstants.PROCESS_FILENAME}'"); return new ProcessStartInfo { Arguments = - $"{port} \"{ProtocolConstants.LogFolder.Combine($"{DateTime.UtcNow:yyyy_MM_dd_HH_mm_ss_ffff}.log")}\"", + $"{port} \"{FantomasProtocolConstants.LogFolder.Combine($"{DateTime.UtcNow:yyyy_MM_dd_HH_mm_ss_ffff}.log")}\"", FileName = launchPath.FullPath }; } @@ -50,7 +50,7 @@ protected override IDictionary GetAdditionalProcessEnvVars() Environment.GetEnvironmentVariable("RIDER_PLUGIN_ADDITIONAL_PROBING_PATHS") }, { - ProtocolConstants.PARENT_PROCESS_PID_ENV_VARIABLE, + FantomasProtocolConstants.PARENT_PROCESS_PID_ENV_VARIABLE, Process.GetCurrentProcess().Id.ToString() }, }; diff --git a/ReSharper.FSharp/src/FSharp.ExternalFormatter.Protocol/src/ProtocolConstants.cs b/ReSharper.FSharp/src/FSharp.ExternalFormatter.Protocol/src/FantomasProtocolConstants.cs similarity index 89% rename from ReSharper.FSharp/src/FSharp.ExternalFormatter.Protocol/src/ProtocolConstants.cs rename to ReSharper.FSharp/src/FSharp.ExternalFormatter.Protocol/src/FantomasProtocolConstants.cs index d60b1c63ce..46d1c17315 100644 --- a/ReSharper.FSharp/src/FSharp.ExternalFormatter.Protocol/src/ProtocolConstants.cs +++ b/ReSharper.FSharp/src/FSharp.ExternalFormatter.Protocol/src/FantomasProtocolConstants.cs @@ -3,7 +3,7 @@ namespace FSharp.ExternalFormatter.Protocol { - public static class ProtocolConstants + public static class FantomasProtocolConstants { public const string PROCESS_FILENAME = "JetBrains.ReSharper.Plugins.FSharp.ExternalFormatter.Host.exe"; public const string PARENT_PROCESS_PID_ENV_VARIABLE = "FSHARP_EXTERNAL_FORMATTER_PROCESS_PID"; diff --git a/ReSharper.FSharp/src/FSharp.Psi.Features/src/Formatter/CodeFormatterProvider.fs b/ReSharper.FSharp/src/FSharp.Psi.Features/src/Formatter/CodeFormatterProvider.fs index 800b67c5c1..c1f8bc9add 100644 --- a/ReSharper.FSharp/src/FSharp.Psi.Features/src/Formatter/CodeFormatterProvider.fs +++ b/ReSharper.FSharp/src/FSharp.Psi.Features/src/Formatter/CodeFormatterProvider.fs @@ -26,10 +26,10 @@ type CodeFormatterProvider(solution: ISolution, externalFormatterFactory: Extern connection.Execute(action) let convertRange (range: range) = - RdRange(range.FileName, range.StartLine, range.StartColumn, range.EndLine, range.EndColumn) + RdFcsRange(range.FileName, range.StartLine, range.StartColumn, range.EndLine, range.EndColumn) let convertFormatSettings (settings: FSharpFormatSettingsKey) = - RdFormatConfig + RdFantomasFormatConfig (settings.INDENT_SIZE, settings.WRAP_LIMIT, settings.SpaceBeforeParameter, settings.SpaceBeforeLowercaseInvocation, settings.SpaceBeforeUppercaseInvocation, settings.SpaceBeforeClassConstructor, settings.SpaceBeforeMember, settings.SpaceBeforeColon, @@ -47,17 +47,17 @@ type CodeFormatterProvider(solution: ISolution, externalFormatterFactory: Extern | Some x -> Nullable x | None -> Nullable() - RdParsingOptions(options.SourceFiles, lightSyntax) + RdFcsParsingOptions(Array.last options.SourceFiles, lightSyntax, + List.toArray options.ConditionalCompilationDefines, options.IsExe) - member x.FormatSelection(filePath: string, range: range, source: string, settings: FSharpFormatSettingsKey, - options: FSharpParsingOptions) = - let args = RdFormatSelectionArgs(filePath, convertRange range, source, convertFormatSettings settings, - convertParsingOptions options) + member x.FormatSelection(filePath, range, source, settings, options, newLineText) = + let args = RdFormatSelectionArgs(convertRange range, filePath, source, convertFormatSettings settings, + convertParsingOptions options, newLineText) execute (fun () -> connection.ProtocolModel.FormatSelection.Sync(args, RpcTimeouts.Maximal)) - member x.FormatDocument(filePath: string, source: string, settings: FSharpFormatSettingsKey, - options: FSharpParsingOptions) = - let args = RdFormatDocumentArgs(filePath, source, convertFormatSettings settings, convertParsingOptions options) + member x.FormatDocument(filePath, source, settings, options, newLineText) = + let args = RdFormatDocumentArgs(filePath, source, convertFormatSettings settings, convertParsingOptions options, + newLineText) execute (fun () -> connection.ProtocolModel.FormatDocument.Sync(args, RpcTimeouts.Maximal)) diff --git a/ReSharper.FSharp/src/FSharp.Psi.Features/src/Formatter/FSharpReformatCode.fs b/ReSharper.FSharp/src/FSharp.Psi.Features/src/Formatter/FSharpReformatCode.fs index 9a6e48b298..dde688d833 100644 --- a/ReSharper.FSharp/src/FSharp.Psi.Features/src/Formatter/FSharpReformatCode.fs +++ b/ReSharper.FSharp/src/FSharp.Psi.Features/src/Formatter/FSharpReformatCode.fs @@ -61,20 +61,15 @@ type FSharpReformatCode() = if isNotNull rangeMarker then try let range = ofDocumentRange rangeMarker.DocumentRange - let formatted = - codeFormatterProvider - .FormatSelection(filePath, range, text, settings, parsingOptions) - .Replace("\r\n", newLineText) + codeFormatterProvider.FormatSelection(filePath, range, text, settings, parsingOptions, newLineText) let offset = rangeMarker.DocumentRange.StartOffset.Offset let oldLength = rangeMarker.DocumentRange.Length Some(DocumentChange(document, offset, oldLength, formatted, stamp, modificationSide)) with _ -> None else let formatted = - codeFormatterProvider - .FormatDocument(filePath, text, settings, parsingOptions) - .Replace("\r\n", newLineText) + codeFormatterProvider.FormatDocument(filePath, text, settings, parsingOptions, newLineText) Some(DocumentChange(document, 0, text.Length, formatted, stamp, modificationSide)) match change with diff --git a/ReSharper.FSharp/src/FSharp.TypeProviders.Host/src/TypeProvidersEndPoint.cs b/ReSharper.FSharp/src/FSharp.TypeProviders.Host/src/TypeProvidersEndPoint.cs index a0634c10b6..1d16c59472 100644 --- a/ReSharper.FSharp/src/FSharp.TypeProviders.Host/src/TypeProvidersEndPoint.cs +++ b/ReSharper.FSharp/src/FSharp.TypeProviders.Host/src/TypeProvidersEndPoint.cs @@ -18,7 +18,7 @@ public class protected override string ProtocolName => "Out-of-Process Type Providers Host"; - public TypeProvidersEndPoint() : base(ProtocolConstants.TypeProvidersHostPid) + public TypeProvidersEndPoint() : base(TypeProvidersProtocolConstants.TypeProvidersHostPid) { } diff --git a/ReSharper.FSharp/src/FSharp.TypeProviders.Protocol/src/TypeProvidersExternalProcess.cs b/ReSharper.FSharp/src/FSharp.TypeProviders.Protocol/src/TypeProvidersExternalProcess.cs index e3216d74b3..77b794468d 100644 --- a/ReSharper.FSharp/src/FSharp.TypeProviders.Protocol/src/TypeProvidersExternalProcess.cs +++ b/ReSharper.FSharp/src/FSharp.TypeProviders.Protocol/src/TypeProvidersExternalProcess.cs @@ -47,8 +47,8 @@ protected override ProcessStartInfo GetProcessStartInfo(int port) private ProcessStartInfo GetCoreProcessStartInfo(int port, FileSystemPath basePath) { var sdkMajorVersion = myNuGetVersion.Major < 3 ? 3 : myNuGetVersion.Major; - var runtimeConfigPath = basePath.Combine(ProtocolConstants.CoreRuntimeConfigFilename(sdkMajorVersion)); - var fileSystemPath = basePath.Combine(ProtocolConstants.TypeProvidersHostCoreFilename); + var runtimeConfigPath = basePath.Combine(TypeProvidersProtocolConstants.CoreRuntimeConfigFilename(sdkMajorVersion)); + var fileSystemPath = basePath.Combine(TypeProvidersProtocolConstants.TypeProvidersHostCoreFilename); var dotnetArgs = $"--runtimeconfig \"{runtimeConfigPath}\""; Assertion.Assert(fileSystemPath.ExistsFile, $"can't find '{fileSystemPath.FullPath}'"); @@ -57,7 +57,7 @@ private ProcessStartInfo GetCoreProcessStartInfo(int port, FileSystemPath basePa var processStartInfo = new ProcessStartInfo { Arguments = - $"{dotnetArgs} \"{fileSystemPath.FullPath}\" {port} \"{ProtocolConstants.LogFolder.Combine($"{DateTime.UtcNow:yyyy_MM_dd_HH_mm_ss_ffff}.log")}\"", + $"{dotnetArgs} \"{fileSystemPath.FullPath}\" {port} \"{TypeProvidersProtocolConstants.LogFolder.Combine($"{DateTime.UtcNow:yyyy_MM_dd_HH_mm_ss_ffff}.log")}\"", FileName = "exec" }; @@ -66,13 +66,13 @@ private ProcessStartInfo GetCoreProcessStartInfo(int port, FileSystemPath basePa private static ProcessStartInfo GetFrameworkProcessStartInfo(int port, FileSystemPath basePath) { - var fileSystemPath = basePath.Combine(ProtocolConstants.TypeProvidersHostFrameworkFilename); + var fileSystemPath = basePath.Combine(TypeProvidersProtocolConstants.TypeProvidersHostFrameworkFilename); Assertion.Assert(fileSystemPath.ExistsFile, $"can't find '{fileSystemPath.FullPath}'"); var processStartInfo = new ProcessStartInfo { Arguments = - $"{port} \"{ProtocolConstants.LogFolder.Combine($"{DateTime.UtcNow:yyyy_MM_dd_HH_mm_ss_ffff}.log")}\"", + $"{port} \"{TypeProvidersProtocolConstants.LogFolder.Combine($"{DateTime.UtcNow:yyyy_MM_dd_HH_mm_ss_ffff}.log")}\"", FileName = fileSystemPath.FullPath }; @@ -88,7 +88,7 @@ protected override IDictionary GetAdditionalProcessEnvVars() Environment.GetEnvironmentVariable("RIDER_PLUGIN_ADDITIONAL_PROBING_PATHS") }, { - ProtocolConstants.TypeProvidersHostPid, + TypeProvidersProtocolConstants.TypeProvidersHostPid, Process.GetCurrentProcess().Id.ToString() } }; diff --git a/ReSharper.FSharp/src/FSharp.TypeProviders.Protocol/src/ProtocolConstants.cs b/ReSharper.FSharp/src/FSharp.TypeProviders.Protocol/src/TypeProvidersProtocolConstants.cs similarity index 93% rename from ReSharper.FSharp/src/FSharp.TypeProviders.Protocol/src/ProtocolConstants.cs rename to ReSharper.FSharp/src/FSharp.TypeProviders.Protocol/src/TypeProvidersProtocolConstants.cs index fab0435497..734eb5ffd3 100644 --- a/ReSharper.FSharp/src/FSharp.TypeProviders.Protocol/src/ProtocolConstants.cs +++ b/ReSharper.FSharp/src/FSharp.TypeProviders.Protocol/src/TypeProvidersProtocolConstants.cs @@ -3,7 +3,7 @@ namespace JetBrains.ReSharper.Plugins.FSharp.TypeProviders.Protocol { - public static class ProtocolConstants + public static class TypeProvidersProtocolConstants { public const string TypeProvidersHostPid = "TypeProvidersHost"; diff --git a/rider-fsharp/protocol/src/kotlin/model/RdFSharpExternalFormatterModel.kt b/rider-fsharp/protocol/src/kotlin/model/RdFSharpExternalFormatterModel.kt index e0e44b680e..48ad757c5a 100644 --- a/rider-fsharp/protocol/src/kotlin/model/RdFSharpExternalFormatterModel.kt +++ b/rider-fsharp/protocol/src/kotlin/model/RdFSharpExternalFormatterModel.kt @@ -9,12 +9,14 @@ import java.io.File @Suppress("unused") object RdFSharpExternalFormatterModel : Root() { - private val rdParsingOptions = structdef { - field("sourceFiles", array(string)) + private val rdFcsParsingOptions = structdef { + field("lastSourceFile", string) field("lightSyntax", bool.nullable) + field("conditionalCompilationDefines", array(string)) + field("isExe", bool) } - private val rdRange = structdef { + private val rdFcsRange = structdef { field("fileName", string) field("startLine", int) field("startCol", int) @@ -22,7 +24,7 @@ object RdFSharpExternalFormatterModel : Root() { field("endCol", int) } - private val rdFormatConfig = structdef { + private val rdFantomasFormatConfig = structdef { field("indentSize", int) field("maxLineLength", int) field("spaceBeforeParameter", bool) @@ -51,20 +53,18 @@ object RdFSharpExternalFormatterModel : Root() { field("alternativeLongMemberDefinitions", bool) } - init { - call("formatSelection", structdef("rdFormatSelectionArgs") { - field("fileName", string) - field("range", rdRange) - field("source", string) - field("formatConfig", rdFormatConfig) - field("parsingOptions", rdParsingOptions) - }, string) + private val rdFormatArgs = basestruct { + field("fileName", string) + field("source", string) + field("formatConfig", rdFantomasFormatConfig) + field("parsingOptions", rdFcsParsingOptions) + field("newLineText", string) + } - call("formatDocument", structdef("rdFormatDocumentArgs") { - field("fileName", string) - field("source", string) - field("formatConfig", rdFormatConfig) - field("parsingOptions", rdParsingOptions) + init { + call("formatDocument", structdef("rdFormatDocumentArgs") extends rdFormatArgs {}, string) + call("formatSelection", structdef("rdFormatSelectionArgs") extends rdFormatArgs { + field("range", rdFcsRange) }, string) signal("Exit", void) From 6995099d3e62d5eedfe46f4d9bb2dcc4cce619df Mon Sep 17 00:00:00 2001 From: Alex Berezhnykh Date: Tue, 27 Apr 2021 18:36:22 +0300 Subject: [PATCH 07/17] update runtimeconfig.json --- ...lugins.FSharp.ExternalFormatter.Host.runtimeconfig.json | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/ReSharper.FSharp/src/FSharp.ExternalFormatter.Host/JetBrains.ReSharper.Plugins.FSharp.ExternalFormatter.Host.runtimeconfig.json b/ReSharper.FSharp/src/FSharp.ExternalFormatter.Host/JetBrains.ReSharper.Plugins.FSharp.ExternalFormatter.Host.runtimeconfig.json index ec942fede6..0228bbe4b3 100644 --- a/ReSharper.FSharp/src/FSharp.ExternalFormatter.Host/JetBrains.ReSharper.Plugins.FSharp.ExternalFormatter.Host.runtimeconfig.json +++ b/ReSharper.FSharp/src/FSharp.ExternalFormatter.Host/JetBrains.ReSharper.Plugins.FSharp.ExternalFormatter.Host.runtimeconfig.json @@ -1,9 +1,10 @@ { "runtimeOptions": { - "tfm": "netcoreapp3.1", + "tfm": "netcoreapp5.0", "framework": { "name": "Microsoft.NETCore.App", - "version": "3.1.0" - } + "version": "5.0.0" + }, + "rollForward": "Major" } } From d2c72216074a8ec36e60dc8c168c52f3eee0e475 Mon Sep 17 00:00:00 2001 From: Alex Berezhnykh Date: Wed, 28 Apr 2021 13:59:52 +0300 Subject: [PATCH 08/17] fix --- .../FSharp.ExternalFormatter.Host.csproj | 1 + 1 file changed, 1 insertion(+) diff --git a/ReSharper.FSharp/src/FSharp.ExternalFormatter.Host/FSharp.ExternalFormatter.Host.csproj b/ReSharper.FSharp/src/FSharp.ExternalFormatter.Host/FSharp.ExternalFormatter.Host.csproj index a05270738b..2339793921 100644 --- a/ReSharper.FSharp/src/FSharp.ExternalFormatter.Host/FSharp.ExternalFormatter.Host.csproj +++ b/ReSharper.FSharp/src/FSharp.ExternalFormatter.Host/FSharp.ExternalFormatter.Host.csproj @@ -5,6 +5,7 @@ JetBrains.ReSharper.Plugins.FSharp.ExternalFormatter.Host Exe false + $(CSharpLanguageVersion) From 0a796106ee5e832a783d902ae820b00e4b1b5b9b Mon Sep 17 00:00:00 2001 From: Alex Berezhnykh Date: Mon, 3 May 2021 13:48:29 +0300 Subject: [PATCH 09/17] update logger --- .../src/ExternalFormatterEndPoint.cs | 17 +++++------------ ...tterProvider.cs => FantomasCodeFormatter.cs} | 2 +- .../src/TypeProvidersEndPoint.cs | 9 ++------- 3 files changed, 8 insertions(+), 20 deletions(-) rename ReSharper.FSharp/src/FSharp.ExternalFormatter.Host/src/{CodeFormatterProvider.cs => FantomasCodeFormatter.cs} (98%) diff --git a/ReSharper.FSharp/src/FSharp.ExternalFormatter.Host/src/ExternalFormatterEndPoint.cs b/ReSharper.FSharp/src/FSharp.ExternalFormatter.Host/src/ExternalFormatterEndPoint.cs index 917cbf7eff..2795c6d573 100644 --- a/ReSharper.FSharp/src/FSharp.ExternalFormatter.Host/src/ExternalFormatterEndPoint.cs +++ b/ReSharper.FSharp/src/FSharp.ExternalFormatter.Host/src/ExternalFormatterEndPoint.cs @@ -3,36 +3,29 @@ using JetBrains.Diagnostics; using JetBrains.Lifetimes; using JetBrains.Platform.RdFramework.ExternalProcess; +using JetBrains.Platform.RdFramework.ExternalProcess.Util; using JetBrains.Rd.Impl; using JetBrains.Rider.FSharp.ExternalFormatter.Client; using JetBrains.Util; -using JetBrains.Util.Logging; using JetBrains.Rd.Tasks; namespace FSharp.ExternalFormatter.Host { internal class ExternalFormatterEndPoint : ProtocolEndPoint { - private readonly ExternalCodeFormatter myCodeFormatter; + private readonly FantomasCodeFormatter myCodeFormatter; protected override string ProtocolName => "External Formatter Host"; public ExternalFormatterEndPoint() : base(FantomasProtocolConstants.PARENT_PROCESS_PID_ENV_VARIABLE) { - myCodeFormatter = new ExternalCodeFormatter(); + myCodeFormatter = new FantomasCodeFormatter(); } protected override RdSimpleDispatcher InitDispatcher(Lifetime lifetime, ILogger logger) => new RdSimpleDispatcher(lifetime, logger); - protected override void InitLogger(Lifetime lifetime, string path) - { - LogManager.Instance.SetConfig(new XmlLogConfigModel()); - var logPath = FileSystemPath.TryParse(path); - if (logPath.IsNullOrEmpty()) return; - - var logEventListener = new FileLogEventListener(logPath); - LogManager.Instance.AddOmnipresentLogger(lifetime, logEventListener, LoggingLevel.TRACE); - } + protected override void InitLogger(Lifetime lifetime, string path) => + ProtocolEndPointUtil.InitLogger(path, lifetime, LoggingLevel.TRACE); protected override RdFSharpExternalFormatterModel InitModel(Lifetime lifetime, JetBrains.Rd.Impl.Protocol protocol) { diff --git a/ReSharper.FSharp/src/FSharp.ExternalFormatter.Host/src/CodeFormatterProvider.cs b/ReSharper.FSharp/src/FSharp.ExternalFormatter.Host/src/FantomasCodeFormatter.cs similarity index 98% rename from ReSharper.FSharp/src/FSharp.ExternalFormatter.Host/src/CodeFormatterProvider.cs rename to ReSharper.FSharp/src/FSharp.ExternalFormatter.Host/src/FantomasCodeFormatter.cs index 59740fd5a7..92f0cb55f6 100644 --- a/ReSharper.FSharp/src/FSharp.ExternalFormatter.Host/src/CodeFormatterProvider.cs +++ b/ReSharper.FSharp/src/FSharp.ExternalFormatter.Host/src/FantomasCodeFormatter.cs @@ -8,7 +8,7 @@ namespace FSharp.ExternalFormatter.Host { - internal class ExternalCodeFormatter + internal class FantomasCodeFormatter { private readonly FSharpChecker myChecker = FSharpChecker.Create(null, null, null, null, null, null, null, null, null, null); diff --git a/ReSharper.FSharp/src/FSharp.TypeProviders.Host/src/TypeProvidersEndPoint.cs b/ReSharper.FSharp/src/FSharp.TypeProviders.Host/src/TypeProvidersEndPoint.cs index 1d16c59472..9bb640d78e 100644 --- a/ReSharper.FSharp/src/FSharp.TypeProviders.Host/src/TypeProvidersEndPoint.cs +++ b/ReSharper.FSharp/src/FSharp.TypeProviders.Host/src/TypeProvidersEndPoint.cs @@ -2,12 +2,12 @@ using JetBrains.Diagnostics; using JetBrains.Lifetimes; using JetBrains.Platform.RdFramework.ExternalProcess; +using JetBrains.Platform.RdFramework.ExternalProcess.Util; using JetBrains.Rd.Impl; using JetBrains.ReSharper.Plugins.FSharp.TypeProviders.Host.Hosts; using JetBrains.ReSharper.Plugins.FSharp.TypeProviders.Protocol; using JetBrains.Rider.FSharp.TypeProviders.Protocol.Server; using JetBrains.Util; -using JetBrains.Util.Logging; namespace JetBrains.ReSharper.Plugins.FSharp.TypeProviders.Host { @@ -30,12 +30,7 @@ protected override RdSimpleDispatcher InitDispatcher(Lifetime lifetime, ILogger protected override void InitLogger(Lifetime lifetime, string path) { - LogManager.Instance.SetConfig(new XmlLogConfigModel()); - var logPath = FileSystemPath.TryParse(path); - if (logPath.IsNullOrEmpty()) return; - - var logEventListener = new FileLogEventListener(logPath); - LogManager.Instance.AddOmnipresentLogger(lifetime, logEventListener, LoggingLevel.TRACE); + ProtocolEndPointUtil.InitLogger(path, lifetime, LoggingLevel.TRACE); Logger.Log(LoggingLevel.INFO, $"Process Runtime: {RuntimeInformation.FrameworkDescription}"); } From 9129175c71463761eb4e8c5325273cc51b8c1586 Mon Sep 17 00:00:00 2001 From: Alex Berezhnykh Date: Tue, 4 May 2021 13:23:53 +0300 Subject: [PATCH 10/17] add yet another FantomasConfig property --- .../FSharp.ExternalFormatter.Host/src/FantomasCodeFormatter.cs | 2 +- .../FSharp.Psi.Features/src/Formatter/CodeFormatterProvider.fs | 3 ++- .../src/kotlin/model/RdFSharpExternalFormatterModel.kt | 1 + 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/ReSharper.FSharp/src/FSharp.ExternalFormatter.Host/src/FantomasCodeFormatter.cs b/ReSharper.FSharp/src/FSharp.ExternalFormatter.Host/src/FantomasCodeFormatter.cs index 92f0cb55f6..150f1c5210 100644 --- a/ReSharper.FSharp/src/FSharp.ExternalFormatter.Host/src/FantomasCodeFormatter.cs +++ b/ReSharper.FSharp/src/FSharp.ExternalFormatter.Host/src/FantomasCodeFormatter.cs @@ -37,7 +37,7 @@ private static FSharpParsingOptions Convert(RdFcsParsingOptions options) => options.LightSyntax, false, options.IsExe); private FormatConfig.FormatConfig Convert(RdFantomasFormatConfig config) => - new FormatConfig.FormatConfig(config.IndentSize, config.MaxLineLength, myDefaultFormatConfig.SemicolonAtEndOfLine, + new FormatConfig.FormatConfig(config.IndentSize, config.MaxLineLength, config.SemicolonAtEndOfLine, config.SpaceBeforeParameter, config.SpaceBeforeLowercaseInvocation, config.SpaceBeforeUppercaseInvocation, config.SpaceBeforeClassConstructor, config.SpaceBeforeMember, config.SpaceBeforeColon, config.SpaceAfterComma, config.SpaceBeforeSemicolon, config.SpaceAfterSemicolon, config.IndentOnTryWith, config.SpaceAroundDelimiter, diff --git a/ReSharper.FSharp/src/FSharp.Psi.Features/src/Formatter/CodeFormatterProvider.fs b/ReSharper.FSharp/src/FSharp.Psi.Features/src/Formatter/CodeFormatterProvider.fs index c1f8bc9add..75e7e9eac5 100644 --- a/ReSharper.FSharp/src/FSharp.Psi.Features/src/Formatter/CodeFormatterProvider.fs +++ b/ReSharper.FSharp/src/FSharp.Psi.Features/src/Formatter/CodeFormatterProvider.fs @@ -39,7 +39,8 @@ type CodeFormatterProvider(solution: ISolution, externalFormatterFactory: Extern settings.MaxValueBindingWidth, settings.MaxFunctionBindingWidth, settings.MultilineBlockBracketsOnSameColumn, settings.NewlineBetweenTypeDefinitionAndMembers, settings.KeepIfThenInSameLine, settings.MaxElmishWidth, settings.SingleArgumentWebMode, - settings.AlignFunctionSignatureToIndentation, settings.AlternativeLongMemberDefinitions) + settings.AlignFunctionSignatureToIndentation, settings.AlternativeLongMemberDefinitions, + settings.SemicolonAtEndOfLine) let convertParsingOptions (options: FSharpParsingOptions) = let lightSyntax = diff --git a/rider-fsharp/protocol/src/kotlin/model/RdFSharpExternalFormatterModel.kt b/rider-fsharp/protocol/src/kotlin/model/RdFSharpExternalFormatterModel.kt index 48ad757c5a..4ffc30c6cf 100644 --- a/rider-fsharp/protocol/src/kotlin/model/RdFSharpExternalFormatterModel.kt +++ b/rider-fsharp/protocol/src/kotlin/model/RdFSharpExternalFormatterModel.kt @@ -51,6 +51,7 @@ object RdFSharpExternalFormatterModel : Root() { field("singleArgumentWebMode", bool) field("alignFunctionSignatureToIndentation", bool) field("alternativeLongMemberDefinitions", bool) + field("semicolonAtEndOfLine", bool) } private val rdFormatArgs = basestruct { From 4d8fc1dabaad28dcf2dbbed46804e355bf5dade5 Mon Sep 17 00:00:00 2001 From: Alex Berezhnykh Date: Tue, 4 May 2021 21:55:31 +0300 Subject: [PATCH 11/17] renames --- ReSharper.FSharp/ReSharper.FSharp.sln | 4 +-- .../FSharp.Fantomas.Host.csproj} | 8 ++--- ...s.FSharp.Fantomas.Host.runtimeconfig.json} | 0 .../src/FantomasCodeFormatter.cs | 4 +-- .../src/FantomasEndPoint.cs} | 14 ++++---- .../src/Program.cs | 4 +-- .../src/RiderAssemblyResolver.cs} | 6 ++-- .../FSharp.Fantomas.Protocol.csproj} | 3 +- .../src/FantomasConnection.cs} | 8 ++--- .../src/FantomasProcess.cs} | 21 ++++++------ .../src/FantomasProcessFactory.cs} | 10 +++--- .../src/FantomasProtocolConstants.cs | 4 +-- .../FSharp.Psi.Features.fsproj | 2 +- .../src/Formatter/CodeFormatterProvider.fs | 10 +++--- rider-fsharp/build.gradle.kts | 32 +++++++++---------- ...alFormatterModel.kt => RdFantomasModel.kt} | 2 +- 16 files changed, 66 insertions(+), 66 deletions(-) rename ReSharper.FSharp/src/{FSharp.ExternalFormatter.Host/FSharp.ExternalFormatter.Host.csproj => FSharp.Fantomas.Host/FSharp.Fantomas.Host.csproj} (71%) rename ReSharper.FSharp/src/{FSharp.ExternalFormatter.Host/JetBrains.ReSharper.Plugins.FSharp.ExternalFormatter.Host.runtimeconfig.json => FSharp.Fantomas.Host/JetBrains.ReSharper.Plugins.FSharp.Fantomas.Host.runtimeconfig.json} (100%) rename ReSharper.FSharp/src/{FSharp.ExternalFormatter.Host => FSharp.Fantomas.Host}/src/FantomasCodeFormatter.cs (96%) rename ReSharper.FSharp/src/{FSharp.ExternalFormatter.Host/src/ExternalFormatterEndPoint.cs => FSharp.Fantomas.Host/src/FantomasEndPoint.cs} (76%) rename ReSharper.FSharp/src/{FSharp.ExternalFormatter.Host => FSharp.Fantomas.Host}/src/Program.cs (75%) rename ReSharper.FSharp/src/{FSharp.ExternalFormatter.Host/src/ExternalFormatterAssemblyResolver.cs => FSharp.Fantomas.Host/src/RiderAssemblyResolver.cs} (90%) rename ReSharper.FSharp/src/{FSharp.ExternalFormatter.Protocol/FSharp.ExternalFormatter.Protocol.csproj => FSharp.Fantomas.Protocol/FSharp.Fantomas.Protocol.csproj} (77%) rename ReSharper.FSharp/src/{FSharp.ExternalFormatter.Protocol/src/ExternalFormatterConnection.cs => FSharp.Fantomas.Protocol/src/FantomasConnection.cs} (55%) rename ReSharper.FSharp/src/{FSharp.ExternalFormatter.Protocol/src/ExternalFormatterProcess.cs => FSharp.Fantomas.Protocol/src/FantomasProcess.cs} (67%) rename ReSharper.FSharp/src/{FSharp.ExternalFormatter.Protocol/src/ExternalFormatterProcessFactory.cs => FSharp.Fantomas.Protocol/src/FantomasProcessFactory.cs} (78%) rename ReSharper.FSharp/src/{FSharp.ExternalFormatter.Protocol => FSharp.Fantomas.Protocol}/src/FantomasProtocolConstants.cs (79%) rename rider-fsharp/protocol/src/kotlin/model/{RdFSharpExternalFormatterModel.kt => RdFantomasModel.kt} (98%) diff --git a/ReSharper.FSharp/ReSharper.FSharp.sln b/ReSharper.FSharp/ReSharper.FSharp.sln index c78ab36146..e851548b5c 100644 --- a/ReSharper.FSharp/ReSharper.FSharp.sln +++ b/ReSharper.FSharp/ReSharper.FSharp.sln @@ -25,9 +25,9 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FSharp.TypeProviders.Host", EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FSharp.TypeProviders.Protocol", "src\FSharp.TypeProviders.Protocol\FSharp.TypeProviders.Protocol.csproj", "{912A7F5F-73F2-4DFE-B81A-C13A4F58F31C}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FSharp.ExternalFormatter.Host", "src\FSharp.ExternalFormatter.Host\FSharp.ExternalFormatter.Host.csproj", "{CF12A71A-1296-418B-8C0A-CC4B398AAB16}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FSharp.Fantomas.Host", "src\FSharp.Fantomas.Host\FSharp.Fantomas.Host.csproj", "{CF12A71A-1296-418B-8C0A-CC4B398AAB16}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FSharp.ExternalFormatter.Protocol", "src\FSharp.ExternalFormatter.Protocol\FSharp.ExternalFormatter.Protocol.csproj", "{D8DE097E-04DC-4A9B-88BF-10923FF44F8B}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FSharp.Fantomas.Protocol", "src\FSharp.Fantomas.Protocol\FSharp.Fantomas.Protocol.csproj", "{D8DE097E-04DC-4A9B-88BF-10923FF44F8B}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/ReSharper.FSharp/src/FSharp.ExternalFormatter.Host/FSharp.ExternalFormatter.Host.csproj b/ReSharper.FSharp/src/FSharp.Fantomas.Host/FSharp.Fantomas.Host.csproj similarity index 71% rename from ReSharper.FSharp/src/FSharp.ExternalFormatter.Host/FSharp.ExternalFormatter.Host.csproj rename to ReSharper.FSharp/src/FSharp.Fantomas.Host/FSharp.Fantomas.Host.csproj index 2339793921..1b5a6147ad 100644 --- a/ReSharper.FSharp/src/FSharp.ExternalFormatter.Host/FSharp.ExternalFormatter.Host.csproj +++ b/ReSharper.FSharp/src/FSharp.Fantomas.Host/FSharp.Fantomas.Host.csproj @@ -2,14 +2,14 @@ net461 - JetBrains.ReSharper.Plugins.FSharp.ExternalFormatter.Host + JetBrains.ReSharper.Plugins.FSharp.Fantomas.Host Exe - false $(CSharpLanguageVersion) + JetBrains.ReSharper.Plugins.FSharp.Fantomas.Host - + @@ -17,7 +17,7 @@ - + Always diff --git a/ReSharper.FSharp/src/FSharp.ExternalFormatter.Host/JetBrains.ReSharper.Plugins.FSharp.ExternalFormatter.Host.runtimeconfig.json b/ReSharper.FSharp/src/FSharp.Fantomas.Host/JetBrains.ReSharper.Plugins.FSharp.Fantomas.Host.runtimeconfig.json similarity index 100% rename from ReSharper.FSharp/src/FSharp.ExternalFormatter.Host/JetBrains.ReSharper.Plugins.FSharp.ExternalFormatter.Host.runtimeconfig.json rename to ReSharper.FSharp/src/FSharp.Fantomas.Host/JetBrains.ReSharper.Plugins.FSharp.Fantomas.Host.runtimeconfig.json diff --git a/ReSharper.FSharp/src/FSharp.ExternalFormatter.Host/src/FantomasCodeFormatter.cs b/ReSharper.FSharp/src/FSharp.Fantomas.Host/src/FantomasCodeFormatter.cs similarity index 96% rename from ReSharper.FSharp/src/FSharp.ExternalFormatter.Host/src/FantomasCodeFormatter.cs rename to ReSharper.FSharp/src/FSharp.Fantomas.Host/src/FantomasCodeFormatter.cs index 150f1c5210..5ccfae8bbf 100644 --- a/ReSharper.FSharp/src/FSharp.ExternalFormatter.Host/src/FantomasCodeFormatter.cs +++ b/ReSharper.FSharp/src/FSharp.Fantomas.Host/src/FantomasCodeFormatter.cs @@ -2,11 +2,11 @@ using FSharp.Compiler.CodeAnalysis; using FSharp.Compiler.Diagnostics; using FSharp.Compiler.Text; -using JetBrains.Rider.FSharp.ExternalFormatter.Client; +using JetBrains.ReSharper.Plugins.FSharp.Fantomas.Server; using Microsoft.FSharp.Collections; using Microsoft.FSharp.Control; -namespace FSharp.ExternalFormatter.Host +namespace JetBrains.ReSharper.Plugins.FSharp.Fantomas.Host { internal class FantomasCodeFormatter { diff --git a/ReSharper.FSharp/src/FSharp.ExternalFormatter.Host/src/ExternalFormatterEndPoint.cs b/ReSharper.FSharp/src/FSharp.Fantomas.Host/src/FantomasEndPoint.cs similarity index 76% rename from ReSharper.FSharp/src/FSharp.ExternalFormatter.Host/src/ExternalFormatterEndPoint.cs rename to ReSharper.FSharp/src/FSharp.Fantomas.Host/src/FantomasEndPoint.cs index 2795c6d573..7831ebda55 100644 --- a/ReSharper.FSharp/src/FSharp.ExternalFormatter.Host/src/ExternalFormatterEndPoint.cs +++ b/ReSharper.FSharp/src/FSharp.Fantomas.Host/src/FantomasEndPoint.cs @@ -1,17 +1,17 @@ -using FSharp.ExternalFormatter.Protocol; -using JetBrains.Collections.Viewable; +using JetBrains.Collections.Viewable; using JetBrains.Diagnostics; using JetBrains.Lifetimes; using JetBrains.Platform.RdFramework.ExternalProcess; using JetBrains.Platform.RdFramework.ExternalProcess.Util; using JetBrains.Rd.Impl; -using JetBrains.Rider.FSharp.ExternalFormatter.Client; using JetBrains.Util; using JetBrains.Rd.Tasks; +using JetBrains.ReSharper.Plugins.FSharp.Fantomas.Protocol; +using JetBrains.ReSharper.Plugins.FSharp.Fantomas.Server; -namespace FSharp.ExternalFormatter.Host +namespace JetBrains.ReSharper.Plugins.FSharp.Fantomas.Host { - internal class ExternalFormatterEndPoint : ProtocolEndPoint + internal class ExternalFormatterEndPoint : ProtocolEndPoint { private readonly FantomasCodeFormatter myCodeFormatter; protected override string ProtocolName => "External Formatter Host"; @@ -27,9 +27,9 @@ protected override RdSimpleDispatcher InitDispatcher(Lifetime lifetime, ILogger protected override void InitLogger(Lifetime lifetime, string path) => ProtocolEndPointUtil.InitLogger(path, lifetime, LoggingLevel.TRACE); - protected override RdFSharpExternalFormatterModel InitModel(Lifetime lifetime, JetBrains.Rd.Impl.Protocol protocol) + protected override RdFantomasModel InitModel(Lifetime lifetime, JetBrains.Rd.Impl.Protocol protocol) { - var model = new RdFSharpExternalFormatterModel(lifetime, protocol); + var model = new RdFantomasModel(lifetime, protocol); model.FormatSelection.Set(FormatSelection); model.FormatDocument.Set(FormatDocument); diff --git a/ReSharper.FSharp/src/FSharp.ExternalFormatter.Host/src/Program.cs b/ReSharper.FSharp/src/FSharp.Fantomas.Host/src/Program.cs similarity index 75% rename from ReSharper.FSharp/src/FSharp.ExternalFormatter.Host/src/Program.cs rename to ReSharper.FSharp/src/FSharp.Fantomas.Host/src/Program.cs index dbc79959a2..5e3fe59e19 100644 --- a/ReSharper.FSharp/src/FSharp.ExternalFormatter.Host/src/Program.cs +++ b/ReSharper.FSharp/src/FSharp.Fantomas.Host/src/Program.cs @@ -1,12 +1,12 @@ using System; -namespace FSharp.ExternalFormatter.Host +namespace JetBrains.ReSharper.Plugins.FSharp.Fantomas.Host { public static class Program { public static void Main(string[] args) { - AppDomain.CurrentDomain.AssemblyResolve += ExternalFormatterAssemblyResolver.Resolve; + AppDomain.CurrentDomain.AssemblyResolve += RiderAssemblyResolver.Resolve; MainInternal(args); } diff --git a/ReSharper.FSharp/src/FSharp.ExternalFormatter.Host/src/ExternalFormatterAssemblyResolver.cs b/ReSharper.FSharp/src/FSharp.Fantomas.Host/src/RiderAssemblyResolver.cs similarity index 90% rename from ReSharper.FSharp/src/FSharp.ExternalFormatter.Host/src/ExternalFormatterAssemblyResolver.cs rename to ReSharper.FSharp/src/FSharp.Fantomas.Host/src/RiderAssemblyResolver.cs index c88e82f23b..7b5be05c40 100644 --- a/ReSharper.FSharp/src/FSharp.ExternalFormatter.Host/src/ExternalFormatterAssemblyResolver.cs +++ b/ReSharper.FSharp/src/FSharp.Fantomas.Host/src/RiderAssemblyResolver.cs @@ -3,14 +3,14 @@ using System.IO; using System.Reflection; -namespace FSharp.ExternalFormatter.Host +namespace JetBrains.ReSharper.Plugins.FSharp.Fantomas.Host { - public static class ExternalFormatterAssemblyResolver + public static class RiderAssemblyResolver { private const string AdditionalProbingPathsEnvVar = "RIDER_PLUGIN_ADDITIONAL_PROBING_PATHS"; private static readonly List OurAdditionalProbingPaths = new List(); - static ExternalFormatterAssemblyResolver() + static RiderAssemblyResolver() { var paths = Environment.GetEnvironmentVariable(AdditionalProbingPathsEnvVar); if (string.IsNullOrWhiteSpace(paths)) return; diff --git a/ReSharper.FSharp/src/FSharp.ExternalFormatter.Protocol/FSharp.ExternalFormatter.Protocol.csproj b/ReSharper.FSharp/src/FSharp.Fantomas.Protocol/FSharp.Fantomas.Protocol.csproj similarity index 77% rename from ReSharper.FSharp/src/FSharp.ExternalFormatter.Protocol/FSharp.ExternalFormatter.Protocol.csproj rename to ReSharper.FSharp/src/FSharp.Fantomas.Protocol/FSharp.Fantomas.Protocol.csproj index dcf597898e..d948d35971 100644 --- a/ReSharper.FSharp/src/FSharp.ExternalFormatter.Protocol/FSharp.ExternalFormatter.Protocol.csproj +++ b/ReSharper.FSharp/src/FSharp.Fantomas.Protocol/FSharp.Fantomas.Protocol.csproj @@ -3,7 +3,8 @@ net461 $(CSharpLanguageVersion) - JetBrains.ReSharper.Plugins.FSharp.ExternalFormatter.Protocol + JetBrains.ReSharper.Plugins.FSharp.Fantomas.Protocol + JetBrains.ReSharper.Plugins.FSharp.Fantomas.Protocol diff --git a/ReSharper.FSharp/src/FSharp.ExternalFormatter.Protocol/src/ExternalFormatterConnection.cs b/ReSharper.FSharp/src/FSharp.Fantomas.Protocol/src/FantomasConnection.cs similarity index 55% rename from ReSharper.FSharp/src/FSharp.ExternalFormatter.Protocol/src/ExternalFormatterConnection.cs rename to ReSharper.FSharp/src/FSharp.Fantomas.Protocol/src/FantomasConnection.cs index 37fb8234f6..943f696362 100644 --- a/ReSharper.FSharp/src/FSharp.ExternalFormatter.Protocol/src/ExternalFormatterConnection.cs +++ b/ReSharper.FSharp/src/FSharp.Fantomas.Protocol/src/FantomasConnection.cs @@ -2,13 +2,13 @@ using JetBrains.Lifetimes; using JetBrains.Platform.RdFramework.ExternalProcess; using JetBrains.Rd; -using JetBrains.Rider.FSharp.ExternalFormatter.Server; +using JetBrains.ReSharper.Plugins.FSharp.Fantomas.Client; -namespace FSharp.ExternalFormatter.Protocol +namespace JetBrains.ReSharper.Plugins.FSharp.Fantomas.Protocol { - public class ExternalFormatterConnection : ProtocolConnection + public class FantomasConnection : ProtocolConnection { - public ExternalFormatterConnection(Lifetime lifetime, RdFSharpExternalFormatterModel protocolModel, + public FantomasConnection(Lifetime lifetime, RdFantomasModel protocolModel, IProtocol protocol, StartupOutputWriter startupOutputWriter, int processId, ISignal processUnexpectedExited) : base(lifetime, protocolModel, protocol, startupOutputWriter, processId, processUnexpectedExited) { diff --git a/ReSharper.FSharp/src/FSharp.ExternalFormatter.Protocol/src/ExternalFormatterProcess.cs b/ReSharper.FSharp/src/FSharp.Fantomas.Protocol/src/FantomasProcess.cs similarity index 67% rename from ReSharper.FSharp/src/FSharp.ExternalFormatter.Protocol/src/ExternalFormatterProcess.cs rename to ReSharper.FSharp/src/FSharp.Fantomas.Protocol/src/FantomasProcess.cs index 95d17dfc2a..21beda8840 100644 --- a/ReSharper.FSharp/src/FSharp.ExternalFormatter.Protocol/src/ExternalFormatterProcess.cs +++ b/ReSharper.FSharp/src/FSharp.Fantomas.Protocol/src/FantomasProcess.cs @@ -9,23 +9,22 @@ using JetBrains.Lifetimes; using JetBrains.Platform.RdFramework.ExternalProcess; using JetBrains.Rd; -using JetBrains.Rider.FSharp.ExternalFormatter.Server; +using JetBrains.ReSharper.Plugins.FSharp.Fantomas.Client; using JetBrains.Util; -namespace FSharp.ExternalFormatter.Protocol +namespace JetBrains.ReSharper.Plugins.FSharp.Fantomas.Protocol { - public class - ExternalFormatterProcess : ProtocolExternalProcess + public class FantomasProcess : ProtocolExternalProcess { protected override string Name => "External Formatter"; - protected override RdFSharpExternalFormatterModel CreateModel(Lifetime lifetime, IProtocol protocol) => - new RdFSharpExternalFormatterModel(lifetime, protocol); + protected override RdFantomasModel CreateModel(Lifetime lifetime, IProtocol protocol) => + new RdFantomasModel(lifetime, protocol); - protected override ExternalFormatterConnection CreateConnection(Lifetime lifetime, - RdFSharpExternalFormatterModel model, IProtocol protocol, StartupOutputWriter outputWriter, int processId, + protected override FantomasConnection CreateConnection(Lifetime lifetime, + RdFantomasModel model, IProtocol protocol, StartupOutputWriter outputWriter, int processId, Signal processUnexpectedExited) => - new ExternalFormatterConnection(lifetime, model, protocol, outputWriter, processId, + new FantomasConnection(lifetime, model, protocol, outputWriter, processId, processUnexpectedExited); protected override ProcessStartInfo GetProcessStartInfo(int port) @@ -56,13 +55,13 @@ protected override IDictionary GetAdditionalProcessEnvVars() }; } - protected override bool Shutdown(RdFSharpExternalFormatterModel model) + protected override bool Shutdown(RdFantomasModel model) { model.Proto.Scheduler.Queue(() => model.Exit.Fire(Unit.Instance)); return true; } - public ExternalFormatterProcess(Lifetime lifetime, ILogger logger, IShellLocks locks, + public FantomasProcess(Lifetime lifetime, ILogger logger, IShellLocks locks, IProcessStartInfoPatcher processInfoPatcher, JetProcessRuntimeRequest request) : base(lifetime, logger, locks, processInfoPatcher, request) { diff --git a/ReSharper.FSharp/src/FSharp.ExternalFormatter.Protocol/src/ExternalFormatterProcessFactory.cs b/ReSharper.FSharp/src/FSharp.Fantomas.Protocol/src/FantomasProcessFactory.cs similarity index 78% rename from ReSharper.FSharp/src/FSharp.ExternalFormatter.Protocol/src/ExternalFormatterProcessFactory.cs rename to ReSharper.FSharp/src/FSharp.Fantomas.Protocol/src/FantomasProcessFactory.cs index 7e589910ed..5280a6ada4 100644 --- a/ReSharper.FSharp/src/FSharp.ExternalFormatter.Protocol/src/ExternalFormatterProcessFactory.cs +++ b/ReSharper.FSharp/src/FSharp.Fantomas.Protocol/src/FantomasProcessFactory.cs @@ -5,16 +5,16 @@ using JetBrains.ProjectModel; using JetBrains.Util; -namespace FSharp.ExternalFormatter.Protocol +namespace JetBrains.ReSharper.Plugins.FSharp.Fantomas.Protocol { [SolutionComponent] - public class ExternalFormatterProcessFactory + public class FantomasProcessFactory { [NotNull] private readonly ISolutionProcessStartInfoPatcher mySolutionProcessStartInfoPatcher; [NotNull] private readonly ILogger myLogger; [NotNull] private readonly IShellLocks myShellLocks; - public ExternalFormatterProcessFactory( + public FantomasProcessFactory( [NotNull] ISolutionProcessStartInfoPatcher solutionProcessStartInfoPatcher, [NotNull] ILogger logger, [NotNull] IShellLocks shellLocks) @@ -24,9 +24,9 @@ public ExternalFormatterProcessFactory( myShellLocks = shellLocks; } - public ExternalFormatterProcess Create(Lifetime lifetime) + public FantomasProcess Create(Lifetime lifetime) { - return new ExternalFormatterProcess(lifetime, + return new FantomasProcess(lifetime, myLogger, myShellLocks, mySolutionProcessStartInfoPatcher, diff --git a/ReSharper.FSharp/src/FSharp.ExternalFormatter.Protocol/src/FantomasProtocolConstants.cs b/ReSharper.FSharp/src/FSharp.Fantomas.Protocol/src/FantomasProtocolConstants.cs similarity index 79% rename from ReSharper.FSharp/src/FSharp.ExternalFormatter.Protocol/src/FantomasProtocolConstants.cs rename to ReSharper.FSharp/src/FSharp.Fantomas.Protocol/src/FantomasProtocolConstants.cs index 46d1c17315..ebdb75ea40 100644 --- a/ReSharper.FSharp/src/FSharp.ExternalFormatter.Protocol/src/FantomasProtocolConstants.cs +++ b/ReSharper.FSharp/src/FSharp.Fantomas.Protocol/src/FantomasProtocolConstants.cs @@ -1,11 +1,11 @@ using JetBrains.Util; using JetBrains.Util.Logging; -namespace FSharp.ExternalFormatter.Protocol +namespace JetBrains.ReSharper.Plugins.FSharp.Fantomas.Protocol { public static class FantomasProtocolConstants { - public const string PROCESS_FILENAME = "JetBrains.ReSharper.Plugins.FSharp.ExternalFormatter.Host.exe"; + public const string PROCESS_FILENAME = "JetBrains.ReSharper.Plugins.FSharp.Fantomas.Host.exe"; public const string PARENT_PROCESS_PID_ENV_VARIABLE = "FSHARP_EXTERNAL_FORMATTER_PROCESS_PID"; public static readonly FileSystemPath LogFolder = Logger.LogFolderPath.Combine("ExternalFormatter"); } diff --git a/ReSharper.FSharp/src/FSharp.Psi.Features/FSharp.Psi.Features.fsproj b/ReSharper.FSharp/src/FSharp.Psi.Features/FSharp.Psi.Features.fsproj index 7f3ff02036..de5b370793 100644 --- a/ReSharper.FSharp/src/FSharp.Psi.Features/FSharp.Psi.Features.fsproj +++ b/ReSharper.FSharp/src/FSharp.Psi.Features/FSharp.Psi.Features.fsproj @@ -235,7 +235,7 @@ - + diff --git a/ReSharper.FSharp/src/FSharp.Psi.Features/src/Formatter/CodeFormatterProvider.fs b/ReSharper.FSharp/src/FSharp.Psi.Features/src/Formatter/CodeFormatterProvider.fs index 75e7e9eac5..286e08990d 100644 --- a/ReSharper.FSharp/src/FSharp.Psi.Features/src/Formatter/CodeFormatterProvider.fs +++ b/ReSharper.FSharp/src/FSharp.Psi.Features/src/Formatter/CodeFormatterProvider.fs @@ -3,15 +3,15 @@ namespace JetBrains.ReSharper.Plugins.FSharp.Services.Formatter open System open FSharp.Compiler.CodeAnalysis open FSharp.Compiler.Text -open FSharp.ExternalFormatter.Protocol open JetBrains.Lifetimes open JetBrains.ProjectModel open JetBrains.Rd.Tasks -open JetBrains.Rider.FSharp.ExternalFormatter.Server +open JetBrains.ReSharper.Plugins.FSharp.Fantomas.Client +open JetBrains.ReSharper.Plugins.FSharp.Fantomas.Protocol [] -type CodeFormatterProvider(solution: ISolution, externalFormatterFactory: ExternalFormatterProcessFactory) = - let mutable connection: ExternalFormatterConnection = null +type CodeFormatterProvider(solution: ISolution, fantomasFactory: FantomasProcessFactory) = + let mutable connection: FantomasConnection = null let isConnectionAlive () = isNotNull connection && connection.IsActive @@ -19,7 +19,7 @@ type CodeFormatterProvider(solution: ISolution, externalFormatterFactory: Extern let connect () = if isConnectionAlive () then () else let formatterHostLifetime = Lifetime.Define(solution.GetLifetime()) - connection <- externalFormatterFactory.Create(formatterHostLifetime.Lifetime).Run() + connection <- fantomasFactory.Create(formatterHostLifetime.Lifetime).Run() let execute (action: unit -> string) = connect () diff --git a/rider-fsharp/build.gradle.kts b/rider-fsharp/build.gradle.kts index c090ed263f..1e0a1cf8b9 100644 --- a/rider-fsharp/build.gradle.kts +++ b/rider-fsharp/build.gradle.kts @@ -128,13 +128,13 @@ val typeProvidersFiles = listOf( "FSharp.TypeProviders.Host/bin/$buildConfiguration/netcoreapp3.1/tploader5.win.runtimeconfig.json", "FSharp.TypeProviders.Host/bin/$buildConfiguration/netcoreapp3.1/tploader5.unix.runtimeconfig.json") -val externalFormatterFiles = listOf( - "FSharp.ExternalFormatter.Protocol/bin/$buildConfiguration/net461/JetBrains.ReSharper.Plugins.FSharp.ExternalFormatter.Protocol.dll", - "FSharp.ExternalFormatter.Protocol/bin/$buildConfiguration/net461/JetBrains.ReSharper.Plugins.FSharp.ExternalFormatter.Protocol.pdb", - "FSharp.ExternalFormatter.Host/bin/$buildConfiguration/net461/JetBrains.ReSharper.Plugins.FSharp.ExternalFormatter.Host.exe", - "FSharp.ExternalFormatter.Host/bin/$buildConfiguration/net461/JetBrains.ReSharper.Plugins.FSharp.ExternalFormatter.Host.runtimeconfig.json", - "FSharp.ExternalFormatter.Host/bin/$buildConfiguration/net461/JetBrains.ReSharper.Plugins.FSharp.ExternalFormatter.Host.pdb", - "FSharp.ExternalFormatter.Host/bin/$buildConfiguration/net461/Fantomas.dll") +val fantomasFiles = listOf( + "FSharp.Fantomas.Protocol/bin/$buildConfiguration/net461/JetBrains.ReSharper.Plugins.FSharp.Fantomas.Protocol.dll", + "FSharp.Fantomas.Protocol/bin/$buildConfiguration/net461/JetBrains.ReSharper.Plugins.FSharp.Fantomas.Protocol.pdb", + "FSharp.Fantomas.Host/bin/$buildConfiguration/net461/JetBrains.ReSharper.Plugins.FSharp.Fantomas.Host.exe", + "FSharp.Fantomas.Host/bin/$buildConfiguration/net461/JetBrains.ReSharper.Plugins.FSharp.Fantomas.Host.runtimeconfig.json", + "FSharp.Fantomas.Host/bin/$buildConfiguration/net461/JetBrains.ReSharper.Plugins.FSharp.Fantomas.Host.pdb", + "FSharp.Fantomas.Host/bin/$buildConfiguration/net461/Fantomas.dll") val dotNetSdkPath by lazy { val sdkPath = intellij.ideaDependency.classes.resolve("lib").resolve("DotNetSdkForRdPlugins") @@ -166,8 +166,8 @@ configure { val typeProviderClientOutput = File(repoRoot, "ReSharper.FSharp/src/FSharp.TypeProviders.Protocol/src/Client") val typeProviderServerOutput = File(repoRoot, "ReSharper.FSharp/src/FSharp.TypeProviders.Protocol/src/Server") - val externalFormatterServerOutput = File(repoRoot, "ReSharper.FSharp/src/FSharp.ExternalFormatter.Protocol/src/Server") - val externalFormatterClientOutput = File(repoRoot, "ReSharper.FSharp/src/FSharp.ExternalFormatter.Protocol/src/Client") + val fantomasServerOutput = File(repoRoot, "ReSharper.FSharp/src/FSharp.Fantomas.Protocol/src/Server") + val fantomasClientOutput = File(repoRoot, "ReSharper.FSharp/src/FSharp.Fantomas.Protocol/src/Client") verbose = true hashFolder = "build/rdgen" @@ -216,22 +216,22 @@ configure { generator { language = "csharp" transform = "asis" - root = "model.RdFSharpExternalFormatterModel" - namespace = "JetBrains.Rider.FSharp.ExternalFormatter.Server" - directory = "$externalFormatterServerOutput" + root = "model.RdFantomasModel" + namespace = "JetBrains.ReSharper.Plugins.FSharp.Fantomas.Client" + directory = "$fantomasClientOutput" } generator { language = "csharp" transform = "reversed" - root = "model.RdFSharpExternalFormatterModel" - namespace = "JetBrains.Rider.FSharp.ExternalFormatter.Client" - directory = "$externalFormatterClientOutput" + root = "model.RdFantomasModel" + namespace = "JetBrains.ReSharper.Plugins.FSharp.Fantomas.Server" + directory = "$fantomasServerOutput" } } tasks { withType { - var files = libFiles + pluginFiles.map { "$it.dll" } + pluginFiles.map { "$it.pdb" } + typeProvidersFiles + externalFormatterFiles + var files = libFiles + pluginFiles.map { "$it.dll" } + pluginFiles.map { "$it.pdb" } + typeProvidersFiles + fantomasFiles files = files.map { "$resharperPluginPath/src/$it" } if (name == IntelliJPlugin.PREPARE_TESTING_SANDBOX_TASK_NAME) { diff --git a/rider-fsharp/protocol/src/kotlin/model/RdFSharpExternalFormatterModel.kt b/rider-fsharp/protocol/src/kotlin/model/RdFantomasModel.kt similarity index 98% rename from rider-fsharp/protocol/src/kotlin/model/RdFSharpExternalFormatterModel.kt rename to rider-fsharp/protocol/src/kotlin/model/RdFantomasModel.kt index 4ffc30c6cf..cbd8759c24 100644 --- a/rider-fsharp/protocol/src/kotlin/model/RdFSharpExternalFormatterModel.kt +++ b/rider-fsharp/protocol/src/kotlin/model/RdFantomasModel.kt @@ -7,7 +7,7 @@ import com.jetbrains.rd.generator.nova.csharp.CSharp50Generator import java.io.File @Suppress("unused") -object RdFSharpExternalFormatterModel : Root() { +object RdFantomasModel : Root() { private val rdFcsParsingOptions = structdef { field("lastSourceFile", string) From ba064a5abd682744e267ac3f252b496f38306a48 Mon Sep 17 00:00:00 2001 From: Alex Berezhnykh Date: Tue, 4 May 2021 22:01:41 +0300 Subject: [PATCH 12/17] fix casing --- rider-fsharp/protocol/src/kotlin/model/RdFantomasModel.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rider-fsharp/protocol/src/kotlin/model/RdFantomasModel.kt b/rider-fsharp/protocol/src/kotlin/model/RdFantomasModel.kt index cbd8759c24..78af82e7a5 100644 --- a/rider-fsharp/protocol/src/kotlin/model/RdFantomasModel.kt +++ b/rider-fsharp/protocol/src/kotlin/model/RdFantomasModel.kt @@ -68,6 +68,6 @@ object RdFantomasModel : Root() { field("range", rdFcsRange) }, string) - signal("Exit", void) + signal("exit", void) } } From c131df58af90bb4e24726abc7028cb66c5037e0a Mon Sep 17 00:00:00 2001 From: Alex Berezhnykh Date: Wed, 5 May 2021 00:00:09 +0300 Subject: [PATCH 13/17] add base tests --- rider-fsharp/src/test/kotlin/Extensions.kt | 17 ++++++-- .../src/test/kotlin/fantomas/FantomasTest.kt | 39 +++++++++++++++++++ .../formatLastFile/gold/formatLastFile.gold | 2 + .../gold/simpleFormatting.gold | 5 +++ .../gold/withEditorConfig.gold | 5 +++ .../solutions/FormatCodeApp/FormatCodeApp.sln | 16 ++++++++ .../FormatCodeApp/Folder/.editorconfig | 2 + .../FormatCodeApp/Folder/EditorConfig.fs | 3 ++ .../FormatCodeApp/FormatCodeApp.fsproj | 15 +++++++ .../FormatCodeApp/FormatCodeApp/Program.fs | 2 + .../FormatCodeApp/FormatCodeApp/Simple.fs | 3 ++ 11 files changed, 105 insertions(+), 4 deletions(-) create mode 100644 rider-fsharp/src/test/kotlin/fantomas/FantomasTest.kt create mode 100644 rider-fsharp/testData/fantomas/FantomasTest/formatLastFile/gold/formatLastFile.gold create mode 100644 rider-fsharp/testData/fantomas/FantomasTest/simpleFormatting/gold/simpleFormatting.gold create mode 100644 rider-fsharp/testData/fantomas/FantomasTest/withEditorConfig/gold/withEditorConfig.gold create mode 100644 rider-fsharp/testData/solutions/FormatCodeApp/FormatCodeApp.sln create mode 100644 rider-fsharp/testData/solutions/FormatCodeApp/FormatCodeApp/Folder/.editorconfig create mode 100644 rider-fsharp/testData/solutions/FormatCodeApp/FormatCodeApp/Folder/EditorConfig.fs create mode 100644 rider-fsharp/testData/solutions/FormatCodeApp/FormatCodeApp/FormatCodeApp.fsproj create mode 100644 rider-fsharp/testData/solutions/FormatCodeApp/FormatCodeApp/Program.fs create mode 100644 rider-fsharp/testData/solutions/FormatCodeApp/FormatCodeApp/Simple.fs diff --git a/rider-fsharp/src/test/kotlin/Extensions.kt b/rider-fsharp/src/test/kotlin/Extensions.kt index f1a6861602..d00fb79990 100644 --- a/rider-fsharp/src/test/kotlin/Extensions.kt +++ b/rider-fsharp/src/test/kotlin/Extensions.kt @@ -1,8 +1,10 @@ +import com.intellij.openapi.project.Project import com.jetbrains.rdclient.protocol.protocolHost import com.jetbrains.rider.inTests.TestHost import com.jetbrains.rider.plugins.fsharp.rdFSharpModel import com.jetbrains.rider.projectView.solution import com.jetbrains.rider.test.base.BaseTestWithSolution +import com.jetbrains.rider.test.base.EditorTestBase import com.jetbrains.rider.test.scriptingApi.dumpSevereHighlighters import java.io.PrintStream @@ -14,12 +16,19 @@ fun com.intellij.openapi.editor.Editor.dumpTypeProviders(stream: PrintStream) { } } -fun BaseTestWithSolution.withTypeProviders(function: () -> Unit) { - val typeProvidersSetting = "FSharp/FSharpOptions/FSharpExperimentalFeatures/OutOfProcessTypeProviders/@EntryValue" - TestHost.getInstance(project.protocolHost).setSetting(typeProvidersSetting, "true") +fun withSetting(project: Project, setting: String, function: () -> Unit) { + TestHost.getInstance(project.protocolHost).setSetting(setting, "true") try { function() } finally { - TestHost.getInstance(project.protocolHost).setSetting(typeProvidersSetting, "false") + TestHost.getInstance(project.protocolHost).setSetting(setting, "false") } } + +fun BaseTestWithSolution.withTypeProviders(function: () -> Unit) { + withSetting(project, "FSharp/FSharpOptions/FSharpExperimentalFeatures/OutOfProcessTypeProviders/@EntryValue", function) +} + +fun withEditorConfig(project: Project, function: () -> Unit) { + withSetting(project, "CodeStyle/EditorConfig/EnableEditorConfigSupport", function) +} diff --git a/rider-fsharp/src/test/kotlin/fantomas/FantomasTest.kt b/rider-fsharp/src/test/kotlin/fantomas/FantomasTest.kt new file mode 100644 index 0000000000..f4f4c10159 --- /dev/null +++ b/rider-fsharp/src/test/kotlin/fantomas/FantomasTest.kt @@ -0,0 +1,39 @@ +package fantomas + +import com.jetbrains.rdclient.testFramework.executeWithGold +import com.jetbrains.rdclient.testFramework.waitForDaemon +import com.jetbrains.rider.test.annotations.TestEnvironment +import com.jetbrains.rider.test.base.EditorTestBase +import com.jetbrains.rider.test.enums.CoreVersion +import com.jetbrains.rider.test.scriptingApi.dumpOpenedDocument +import com.jetbrains.rider.test.scriptingApi.reformatCode +import com.jetbrains.rider.test.scriptingApi.withOpenedEditor +import org.testng.annotations.Test +import withEditorConfig + +@Test +@TestEnvironment(coreVersion = CoreVersion.DEFAULT) +class FantomasTest : EditorTestBase() { + override fun getSolutionDirectoryName() = "FormatCodeApp" + + @Test + fun withEditorConfig() = doTest("EditorConfig.fs") + + @Test + fun simpleFormatting() = doTest("Simple.fs") + + @Test + fun formatLastFile() = doTest("Program.fs") + + private fun doTest(fileName: String) { + withEditorConfig(project) { + withOpenedEditor(fileName) { + waitForDaemon() + reformatCode() + executeWithGold(testGoldFile) { + dumpOpenedDocument(it, project!!, false) + } + } + } + } +} diff --git a/rider-fsharp/testData/fantomas/FantomasTest/formatLastFile/gold/formatLastFile.gold b/rider-fsharp/testData/fantomas/FantomasTest/formatLastFile/gold/formatLastFile.gold new file mode 100644 index 0000000000..5b77edbd9d --- /dev/null +++ b/rider-fsharp/testData/fantomas/FantomasTest/formatLastFile/gold/formatLastFile.gold @@ -0,0 +1,2 @@ +[] +let main argv = 0 diff --git a/rider-fsharp/testData/fantomas/FantomasTest/simpleFormatting/gold/simpleFormatting.gold b/rider-fsharp/testData/fantomas/FantomasTest/simpleFormatting/gold/simpleFormatting.gold new file mode 100644 index 0000000000..ed46f25e8d --- /dev/null +++ b/rider-fsharp/testData/fantomas/FantomasTest/simpleFormatting/gold/simpleFormatting.gold @@ -0,0 +1,5 @@ +module Simple + +type A() = + class + end diff --git a/rider-fsharp/testData/fantomas/FantomasTest/withEditorConfig/gold/withEditorConfig.gold b/rider-fsharp/testData/fantomas/FantomasTest/withEditorConfig/gold/withEditorConfig.gold new file mode 100644 index 0000000000..8aea603375 --- /dev/null +++ b/rider-fsharp/testData/fantomas/FantomasTest/withEditorConfig/gold/withEditorConfig.gold @@ -0,0 +1,5 @@ +module EditorConfig + +type A () = + class + end diff --git a/rider-fsharp/testData/solutions/FormatCodeApp/FormatCodeApp.sln b/rider-fsharp/testData/solutions/FormatCodeApp/FormatCodeApp.sln new file mode 100644 index 0000000000..4994f64918 --- /dev/null +++ b/rider-fsharp/testData/solutions/FormatCodeApp/FormatCodeApp.sln @@ -0,0 +1,16 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "FormatCodeApp", "FormatCodeApp\FormatCodeApp.fsproj", "{CB87B1A7-9600-4AE2-986C-4333196C6AFE}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {CB87B1A7-9600-4AE2-986C-4333196C6AFE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {CB87B1A7-9600-4AE2-986C-4333196C6AFE}.Debug|Any CPU.Build.0 = Debug|Any CPU + {CB87B1A7-9600-4AE2-986C-4333196C6AFE}.Release|Any CPU.ActiveCfg = Release|Any CPU + {CB87B1A7-9600-4AE2-986C-4333196C6AFE}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal diff --git a/rider-fsharp/testData/solutions/FormatCodeApp/FormatCodeApp/Folder/.editorconfig b/rider-fsharp/testData/solutions/FormatCodeApp/FormatCodeApp/Folder/.editorconfig new file mode 100644 index 0000000000..4337b664d0 --- /dev/null +++ b/rider-fsharp/testData/solutions/FormatCodeApp/FormatCodeApp/Folder/.editorconfig @@ -0,0 +1,2 @@ +[*.fs] +fsharp_space_before_class_constructor=true diff --git a/rider-fsharp/testData/solutions/FormatCodeApp/FormatCodeApp/Folder/EditorConfig.fs b/rider-fsharp/testData/solutions/FormatCodeApp/FormatCodeApp/Folder/EditorConfig.fs new file mode 100644 index 0000000000..f226a682d1 --- /dev/null +++ b/rider-fsharp/testData/solutions/FormatCodeApp/FormatCodeApp/Folder/EditorConfig.fs @@ -0,0 +1,3 @@ +module EditorConfig + + type A() = class end diff --git a/rider-fsharp/testData/solutions/FormatCodeApp/FormatCodeApp/FormatCodeApp.fsproj b/rider-fsharp/testData/solutions/FormatCodeApp/FormatCodeApp/FormatCodeApp.fsproj new file mode 100644 index 0000000000..b57bfd3108 --- /dev/null +++ b/rider-fsharp/testData/solutions/FormatCodeApp/FormatCodeApp/FormatCodeApp.fsproj @@ -0,0 +1,15 @@ + + + + Exe + netcoreapp3.1 + + + + + + + + + + diff --git a/rider-fsharp/testData/solutions/FormatCodeApp/FormatCodeApp/Program.fs b/rider-fsharp/testData/solutions/FormatCodeApp/FormatCodeApp/Program.fs new file mode 100644 index 0000000000..1caf613841 --- /dev/null +++ b/rider-fsharp/testData/solutions/FormatCodeApp/FormatCodeApp/Program.fs @@ -0,0 +1,2 @@ + [] + let main argv = 0 diff --git a/rider-fsharp/testData/solutions/FormatCodeApp/FormatCodeApp/Simple.fs b/rider-fsharp/testData/solutions/FormatCodeApp/FormatCodeApp/Simple.fs new file mode 100644 index 0000000000..d3ccaaec1d --- /dev/null +++ b/rider-fsharp/testData/solutions/FormatCodeApp/FormatCodeApp/Simple.fs @@ -0,0 +1,3 @@ +module Simple + + type A() = class end From 80e302239117ea59a34c52a0cccdc715fdbb0557 Mon Sep 17 00:00:00 2001 From: Alex Berezhnykh Date: Thu, 6 May 2021 11:35:56 +0300 Subject: [PATCH 14/17] rename --- .../{RiderAssemblyResolver.cs => FantomasAssemblyResolver.cs} | 4 ++-- ReSharper.FSharp/src/FSharp.Fantomas.Host/src/Program.cs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) rename ReSharper.FSharp/src/FSharp.Fantomas.Host/src/{RiderAssemblyResolver.cs => FantomasAssemblyResolver.cs} (94%) diff --git a/ReSharper.FSharp/src/FSharp.Fantomas.Host/src/RiderAssemblyResolver.cs b/ReSharper.FSharp/src/FSharp.Fantomas.Host/src/FantomasAssemblyResolver.cs similarity index 94% rename from ReSharper.FSharp/src/FSharp.Fantomas.Host/src/RiderAssemblyResolver.cs rename to ReSharper.FSharp/src/FSharp.Fantomas.Host/src/FantomasAssemblyResolver.cs index 7b5be05c40..eaceb5c582 100644 --- a/ReSharper.FSharp/src/FSharp.Fantomas.Host/src/RiderAssemblyResolver.cs +++ b/ReSharper.FSharp/src/FSharp.Fantomas.Host/src/FantomasAssemblyResolver.cs @@ -5,12 +5,12 @@ namespace JetBrains.ReSharper.Plugins.FSharp.Fantomas.Host { - public static class RiderAssemblyResolver + public static class FantomasAssemblyResolver { private const string AdditionalProbingPathsEnvVar = "RIDER_PLUGIN_ADDITIONAL_PROBING_PATHS"; private static readonly List OurAdditionalProbingPaths = new List(); - static RiderAssemblyResolver() + static FantomasAssemblyResolver() { var paths = Environment.GetEnvironmentVariable(AdditionalProbingPathsEnvVar); if (string.IsNullOrWhiteSpace(paths)) return; diff --git a/ReSharper.FSharp/src/FSharp.Fantomas.Host/src/Program.cs b/ReSharper.FSharp/src/FSharp.Fantomas.Host/src/Program.cs index 5e3fe59e19..794ab4ea6b 100644 --- a/ReSharper.FSharp/src/FSharp.Fantomas.Host/src/Program.cs +++ b/ReSharper.FSharp/src/FSharp.Fantomas.Host/src/Program.cs @@ -6,7 +6,7 @@ public static class Program { public static void Main(string[] args) { - AppDomain.CurrentDomain.AssemblyResolve += RiderAssemblyResolver.Resolve; + AppDomain.CurrentDomain.AssemblyResolve += FantomasAssemblyResolver.Resolve; MainInternal(args); } From e2d6cbcff69518d73405895717e4240b131a872f Mon Sep 17 00:00:00 2001 From: Alex Berezhnykh Date: Tue, 11 May 2021 13:47:14 +0300 Subject: [PATCH 15/17] Fix AnyCPU --- .../src/FSharp.Fantomas.Host/FSharp.Fantomas.Host.csproj | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/ReSharper.FSharp/src/FSharp.Fantomas.Host/FSharp.Fantomas.Host.csproj b/ReSharper.FSharp/src/FSharp.Fantomas.Host/FSharp.Fantomas.Host.csproj index 1b5a6147ad..58b05107fe 100644 --- a/ReSharper.FSharp/src/FSharp.Fantomas.Host/FSharp.Fantomas.Host.csproj +++ b/ReSharper.FSharp/src/FSharp.Fantomas.Host/FSharp.Fantomas.Host.csproj @@ -8,6 +8,14 @@ JetBrains.ReSharper.Plugins.FSharp.Fantomas.Host + + AnyCPU + + + + AnyCPU + + From b1eb5564f1bab516da6779f0f35473d6251f9ee1 Mon Sep 17 00:00:00 2001 From: Alex Berezhnykh Date: Thu, 13 May 2021 12:01:39 +0300 Subject: [PATCH 16/17] TODO: remove AnyCPU --- .../src/FSharp.Fantomas.Host/FSharp.Fantomas.Host.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ReSharper.FSharp/src/FSharp.Fantomas.Host/FSharp.Fantomas.Host.csproj b/ReSharper.FSharp/src/FSharp.Fantomas.Host/FSharp.Fantomas.Host.csproj index 58b05107fe..18cdd6de94 100644 --- a/ReSharper.FSharp/src/FSharp.Fantomas.Host/FSharp.Fantomas.Host.csproj +++ b/ReSharper.FSharp/src/FSharp.Fantomas.Host/FSharp.Fantomas.Host.csproj @@ -8,10 +8,10 @@ JetBrains.ReSharper.Plugins.FSharp.Fantomas.Host + AnyCPU - AnyCPU From 9bc69f612e4d8df3c1dcb768e775ed3aacaed4a9 Mon Sep 17 00:00:00 2001 From: Alex Berezhnykh Date: Thu, 13 May 2021 12:29:00 +0300 Subject: [PATCH 17/17] fix naming --- .../src/FSharp.Psi.Features/FSharp.Psi.Features.fsproj | 2 +- .../src/FSharp.Psi.Features/src/Formatter/FSharpReformatCode.fs | 2 +- .../{CodeFormatterProvider.fs => FantomasFormatterProvider.fs} | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) rename ReSharper.FSharp/src/FSharp.Psi.Features/src/Formatter/{CodeFormatterProvider.fs => FantomasFormatterProvider.fs} (97%) diff --git a/ReSharper.FSharp/src/FSharp.Psi.Features/FSharp.Psi.Features.fsproj b/ReSharper.FSharp/src/FSharp.Psi.Features/FSharp.Psi.Features.fsproj index de5b370793..b7ff0b101f 100644 --- a/ReSharper.FSharp/src/FSharp.Psi.Features/FSharp.Psi.Features.fsproj +++ b/ReSharper.FSharp/src/FSharp.Psi.Features/FSharp.Psi.Features.fsproj @@ -105,7 +105,7 @@ - + diff --git a/ReSharper.FSharp/src/FSharp.Psi.Features/src/Formatter/FSharpReformatCode.fs b/ReSharper.FSharp/src/FSharp.Psi.Features/src/Formatter/FSharpReformatCode.fs index dde688d833..13c3a23fae 100644 --- a/ReSharper.FSharp/src/FSharp.Psi.Features/src/Formatter/FSharpReformatCode.fs +++ b/ReSharper.FSharp/src/FSharp.Psi.Features/src/Formatter/FSharpReformatCode.fs @@ -47,7 +47,7 @@ type FSharpReformatCode() = let settings = sourceFile.GetSettingsStoreWithEditorConfig() let languageService = fsFile.Language.LanguageServiceNotNull() let formatter = languageService.CodeFormatter - let codeFormatterProvider = solution.GetComponent() + let codeFormatterProvider = solution.GetComponent() let settings = formatter.GetFormatterSettings(solution, sourceFile, settings, false) :?> FSharpFormatSettingsKey diff --git a/ReSharper.FSharp/src/FSharp.Psi.Features/src/Formatter/CodeFormatterProvider.fs b/ReSharper.FSharp/src/FSharp.Psi.Features/src/Formatter/FantomasFormatterProvider.fs similarity index 97% rename from ReSharper.FSharp/src/FSharp.Psi.Features/src/Formatter/CodeFormatterProvider.fs rename to ReSharper.FSharp/src/FSharp.Psi.Features/src/Formatter/FantomasFormatterProvider.fs index 286e08990d..3319a817e8 100644 --- a/ReSharper.FSharp/src/FSharp.Psi.Features/src/Formatter/CodeFormatterProvider.fs +++ b/ReSharper.FSharp/src/FSharp.Psi.Features/src/Formatter/FantomasFormatterProvider.fs @@ -10,7 +10,7 @@ open JetBrains.ReSharper.Plugins.FSharp.Fantomas.Client open JetBrains.ReSharper.Plugins.FSharp.Fantomas.Protocol [] -type CodeFormatterProvider(solution: ISolution, fantomasFactory: FantomasProcessFactory) = +type FantomasFormatterProvider(solution: ISolution, fantomasFactory: FantomasProcessFactory) = let mutable connection: FantomasConnection = null let isConnectionAlive () =