Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Service formatting #3542

Closed
Closed
2 changes: 1 addition & 1 deletion src/FSharpSource.targets
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
<NUnitToolsLibDir>$(FSharpSourcesRoot)\..\packages\NUnit.ConsoleRunner\$(NUnitVersion)\tools\</NUnitToolsLibDir>
<FsCheckVersion>2.6.2</FsCheckVersion>
<FsCheckFullVersion>2.6.2.0</FsCheckFullVersion>
<FsCheckLibDir>$(FSharpSourcesRoot)\..\packages\FsCheck.$(FsCheckVersion)\lib\</FsCheckLibDir>
<FsCheckLibDir>$(FSharpSourcesRoot)\..\packages\FsCheck.$(FsCheckVersion)\lib</FsCheckLibDir>
</PropertyGroup>

<Import Project="FSharpSource.Profiles.targets" />
Expand Down
120 changes: 65 additions & 55 deletions src/fsharp/FSharp.Compiler.Private/FSharp.Compiler.Private.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,43 @@
</FilesToSign>
</ItemGroup>
</Target>
<Choose>
Copy link
Contributor

@dsyme dsyme Sep 5, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's this change needed for? There should be no MSBuild dependency added to FSharp.Compiler.Private. I suspect this is not needed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I see, it's been moved around. I guess just move it back

<When Condition="$(MonoPackaging) != 'true'">
<ItemGroup Condition="'$(TargetDotnetProfile)' != 'coreclr'">
<Reference Include="Microsoft.Build.Framework, Version=$(VisualStudioVersion).0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<HintPath>$(FSharpSourcesRoot)\..\packages\Microsoft.VisualFSharp.Msbuild.15.0.1.0.1\lib\net45\Microsoft.Build.Framework.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Build, Version=$(VisualStudioVersion).0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<HintPath>$(FSharpSourcesRoot)\..\packages\Microsoft.VisualFSharp.Msbuild.15.0.1.0.1\lib\net45\Microsoft.Build.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Build.Utilities.Core, Version=$(VisualStudioVersion).0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<HintPath>$(FSharpSourcesRoot)\..\packages\Microsoft.VisualFSharp.Msbuild.15.0.1.0.1\lib\net45\Microsoft.Build.Utilities.Core.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Build.Tasks.Core, Version=$(VisualStudioVersion).0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<HintPath>$(FSharpSourcesRoot)\..\packages\Microsoft.VisualFSharp.Msbuild.15.0.1.0.1\lib\net45\Microsoft.Build.Tasks.Core.dll</HintPath>
</Reference>
</ItemGroup>
</When>
<Otherwise>
<ItemGroup>
<Reference Include="Microsoft.Build.Framework, Version=$(MonoPackagingMSBuildVersionFull), Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Build.Engine, Version=$(MonoPackagingMSBuildVersionFull), Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Build, Version=$(MonoPackagingMSBuildVersionFull), Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Build.Utilities.$(MonoPackagingMSBuildVersionSuffix), Version=$(MonoPackagingMSBuildVersionFull), Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Build.Tasks.$(MonoPackagingMSBuildVersionSuffix), Version=$(MonoPackagingMSBuildVersionFull), Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<Private>True</Private>
</Reference>
</ItemGroup>
</Otherwise>
</Choose>
<ItemGroup>
<FilesToLocalize Include="$(OutDir)$(AssemblyName).dll">
<TranslationFile>$(FSharpSourcesRoot)\..\loc\lcl\{Lang}\$(AssemblyName).dll.lcl</TranslationFile>
Expand Down Expand Up @@ -454,8 +491,6 @@
<Compile Include="..\TypeChecker.fs">
<Link>Logic\TypeChecker.fs</Link>
</Compile>

<!-- includes the optimizer and code generator -->
<Compile Include="..\Optimizer.fsi">
<Link>Optimize\Optimizer.fsi</Link>
</Compile>
Expand Down Expand Up @@ -486,8 +521,6 @@
<Compile Include="..\IlxGen.fs">
<Link>CodeGen\IlxGen.fs</Link>
</Compile>

<!-- includes the core of the F# Compiler fsc.exe implementation -->
<Compile Include="..\CompileOps.fsi">
<Link>Driver\CompileOps.fsi</Link>
</Compile>
Expand All @@ -506,8 +539,6 @@
<Compile Include="..\fsc.fs">
<Link>Driver\fsc.fs</Link>
</Compile>

<!-- the symbol API. -->
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can undo all such changes in this file

<Compile Include="..\symbols\SymbolHelpers.fsi">
<Link>Symbols/SymbolHelpers.fsi</Link>
</Compile>
Expand All @@ -526,8 +557,6 @@
<Compile Include="..\symbols\Exprs.fs">
<Link>Symbols/Exprs.fs</Link>
</Compile>

<!-- the incremental builder and service . -->
<Compile Include="..\vs\IncrementalBuild.fsi">
<Link>Service/IncrementalBuild.fsi</Link>
</Compile>
Expand Down Expand Up @@ -618,7 +647,33 @@
<Compile Include="..\vs\ServiceStructure.fs">
<Link>Service/ServiceStructure.fs</Link>
</Compile>

<Compile Include="..\vs\ServiceFormatting\Utils.fs">
<Link>Service/ServiceFormatting/Utils.fs</Link>
</Compile>
<Compile Include="..\vs\ServiceFormatting\TokenMatcher.fs">
<Link>Service/ServiceFormatting/TokenMatcher.fs</Link>
</Compile>
<Compile Include="..\vs\ServiceFormatting\IndentedTextWriter.fs">
<Link>Service/ServiceFormatting/IndentedTextWriter.fs</Link>
</Compile>
<Compile Include="..\vs\ServiceFormatting\FormatConfig.fs">
<Link>Service/ServiceFormatting/FormatConfig.fs</Link>
</Compile>
<Compile Include="..\vs\ServiceFormatting\SourceParser.fs">
<Link>Service/ServiceFormatting/SourceParser.fs</Link>
</Compile>
<Compile Include="..\vs\ServiceFormatting\SourceTransformer.fs">
<Link>Service/ServiceFormatting/SourceTransformer.fs</Link>
</Compile>
<Compile Include="..\vs\ServiceFormatting\CodePrinter.fs">
<Link>Service/ServiceFormatting/CodePrinter.fs</Link>
</Compile>
<Compile Include="..\vs\ServiceFormatting\CodeFormatterImpl.fs">
<Link>Service/ServiceFormatting/CodeFormatterImpl.fs</Link>
</Compile>
<Compile Include="..\vs\ServiceFormatting\CodeFormatter.fs">
<Link>Service/ServiceFormatting/CodeFormatter.fs</Link>
</Compile>
<!-- the core of the F# Interactive fsi.exe implementation -->
<EmbeddedText Include="..\fsi\FSIstrings.txt">
<Link>FSIstrings.txt</Link>
Expand All @@ -629,25 +684,19 @@
<Compile Include="..\fsi\fsi.fs">
<Link>InteractiveSession\fsi.fs</Link>
</Compile>

<Compile Include="InternalsVisibleTo.fs" Condition="'$(TargetDotnetProfile)' != 'coreclr'">
<Link>Misc/InternalsVisibleTo.fs</Link>
</Compile>
<Compile Include="..\MSBuildReferenceResolver.fs">
<Link>Misc/MSBuildReferenceResolver.fs</Link>
</Compile>
<!-- an old API for testing the compiler and gathering diagnostics in-memory -->
<Compile Include="..\LegacyHostedCompilerForTesting.fs">
<Link>Misc/LegacyHostedCompilerForTesting.fs</Link>
</Compile>
</ItemGroup>
<ItemGroup>
<PackageNuspec Include="FSharp.Compiler.Private.netcore.nuspec" Condition="'$(TargetDotnetProfile)' == 'coreclr'" />
</ItemGroup>
<ItemGroup Condition="'$(TargetDotnetProfile)' == 'coreclr'">
<None Include="project.json" />
</ItemGroup>
<ItemGroup Condition="'$(TargetDotnetProfile)' != 'coreclr'">
<ItemGroup>
<Reference Include="mscorlib" />
<Reference Include="System" />
<Reference Include="System.Core" />
Expand All @@ -669,45 +718,6 @@
<HintPath>..\..\..\packages\System.ValueTuple.4.3.1\lib\netstandard1.0\System.ValueTuple.dll</HintPath>
<Private>true</Private>
</Reference>
</ItemGroup>
<Choose>
<When Condition="$(MonoPackaging) != 'true'">
<ItemGroup Condition="'$(TargetDotnetProfile)' != 'coreclr'">
<Reference Include="Microsoft.Build.Framework, Version=$(VisualStudioVersion).0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<HintPath>$(FSharpSourcesRoot)\..\packages\Microsoft.VisualFSharp.Msbuild.15.0.1.0.1\lib\net45\Microsoft.Build.Framework.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Build, Version=$(VisualStudioVersion).0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<HintPath>$(FSharpSourcesRoot)\..\packages\Microsoft.VisualFSharp.Msbuild.15.0.1.0.1\lib\net45\Microsoft.Build.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Build.Utilities.Core, Version=$(VisualStudioVersion).0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<HintPath>$(FSharpSourcesRoot)\..\packages\Microsoft.VisualFSharp.Msbuild.15.0.1.0.1\lib\net45\Microsoft.Build.Utilities.Core.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Build.Tasks.Core, Version=$(VisualStudioVersion).0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<HintPath>$(FSharpSourcesRoot)\..\packages\Microsoft.VisualFSharp.Msbuild.15.0.1.0.1\lib\net45\Microsoft.Build.Tasks.Core.dll</HintPath>
</Reference>
</ItemGroup>
</When>
<Otherwise>
<ItemGroup>
<Reference Include="Microsoft.Build.Framework, Version=$(MonoPackagingMSBuildVersionFull), Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Build.Engine, Version=$(MonoPackagingMSBuildVersionFull), Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Build, Version=$(MonoPackagingMSBuildVersionFull), Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Build.Utilities.$(MonoPackagingMSBuildVersionSuffix), Version=$(MonoPackagingMSBuildVersionFull), Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Build.Tasks.$(MonoPackagingMSBuildVersionSuffix), Version=$(MonoPackagingMSBuildVersionFull), Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<Private>True</Private>
</Reference>
</ItemGroup>
</Otherwise>
</Choose>
<ItemGroup>
<ProjectReference Include="$(FSharpSourcesRoot)\fsharp\FSharp.Core\FSharp.Core.fsproj">
<Project>{DED3BBD7-53F4-428A-8C9F-27968E768605}</Project>
<Name>FSharp.Core</Name>
Expand Down
24 changes: 24 additions & 0 deletions src/fsharp/vs/ServiceFormatting/CodeFormatter.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copied from https://github.com/dungpa/fantomas and modified by Vasily Kirichenko

namespace Microsoft.FSharp.Compiler.SourceCodeServices.ServiceFormatting

[<Sealed>]
type internal CodeFormatter =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be public in the FCS API #if COMPILER_PUBLIC_API but we could do that in a separate PR

static member FormatSelection(fileName, selection, source, config, ast) =
CodeFormatterImpl.formatSelection selection config fileName source ast

static member FormatAroundCursor(fileName, cursorPos, source, config, ast) =
CodeFormatterImpl.formatAroundCursor cursorPos config fileName source ast

static member InferSelectionFromCursorPos(fileName, cursorPos, source) =
CodeFormatterImpl.inferSelectionFromCursorPos cursorPos fileName source

static member internal FormatSelectionInDocument(fileName, selection, source, config, ast) =
CodeFormatterImpl.formatSelectionInDocument selection config fileName source ast

static member FormatAST(ast, fileName, source, config) = CodeFormatterImpl.formatAST ast fileName source config

static member MakePos(line, col) = CodeFormatterImpl.makePos line col

static member MakeRange(fileName, startLine, startCol, endLine, endCol) =
CodeFormatterImpl.makeRange fileName startLine startCol endLine endCol
Loading