Skip to content

Commit

Permalink
Ctrl+Break in VS on coreclr and desktop (#14218)
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinRansom authored Nov 7, 2022
1 parent 8af363b commit e381e35
Show file tree
Hide file tree
Showing 22 changed files with 135 additions and 200 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ scripts/*.patch
/src/FSharp.Build/*.resx
/src/fsi/*.resx
/src/FSharp.Compiler.Interactive.Settings/*.resx
/src/FSharp.Compiler.Server.Shared/*.resx
/src/fsi/Fsi.sln
/src/FSharp.Build/*.resources
/src/Compiler/*.resx
Expand Down
20 changes: 3 additions & 17 deletions FSharp.sln
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.1.32113.165
MinimumVisualStudioVersion = 10.0.40219.1
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "FSharp.Compiler.Server.Shared", "src\FSharp.Compiler.Server.Shared\FSharp.Compiler.Server.Shared.fsproj", "{D5870CF0-ED51-4CBC-B3D7-6F56DA84AC06}"
EndProject
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "FSharp.Core", "src\FSharp.Core\FSharp.Core.fsproj", "{DED3BBD7-53F4-428A-8C9F-27968E768605}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{CFE3259A-2D30-4EB0-80D5-E8B5F3D01449}"
Expand Down Expand Up @@ -98,9 +96,10 @@ Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "fsiAnyCpu", "src\fsi\fsiAny
EndProject
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "fsiArm64", "src\fsi\fsiArm64Project\fsiArm64.fsproj", "{209C7D37-8C01-413C-8698-EC25F4C86976}"
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "HistoricalBenchmark", "tests\benchmarks\FCSBenchmarks\BenchmarkComparison\HistoricalBenchmark.fsproj", "{BEC6E796-7E53-4888-AAFC-B8FD55C425DF}"
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "HistoricalBenchmark", "tests\benchmarks\FCSBenchmarks\BenchmarkComparison\HistoricalBenchmark.fsproj", "{BEC6E796-7E53-4888-AAFC-B8FD55C425DF}"
EndProject
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "FSharp.Compiler.Benchmarks", "tests\benchmarks\FCSBenchmarks\CompilerServiceBenchmarks\FSharp.Compiler.Benchmarks.fsproj", "{9C7523BA-7AB2-4604-A5FD-653E82C2BAD1}"
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "FSharp.Compiler.Benchmarks", "tests\benchmarks\FCSBenchmarks\CompilerServiceBenchmarks\FSharp.Compiler.Benchmarks.fsproj", "{9C7523BA-7AB2-4604-A5FD-653E82C2BAD1}"
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{D58BFE8B-7C85-4D3B-B5F3-9A7BB90FF1EE}"
ProjectSection(SolutionItems) = preProject
src\Compiler\FSComp.txt = src\Compiler\FSComp.txt
Expand All @@ -116,18 +115,6 @@ Global
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{D5870CF0-ED51-4CBC-B3D7-6F56DA84AC06}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D5870CF0-ED51-4CBC-B3D7-6F56DA84AC06}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D5870CF0-ED51-4CBC-B3D7-6F56DA84AC06}.Debug|x86.ActiveCfg = Debug|Any CPU
{D5870CF0-ED51-4CBC-B3D7-6F56DA84AC06}.Debug|x86.Build.0 = Debug|Any CPU
{D5870CF0-ED51-4CBC-B3D7-6F56DA84AC06}.Proto|Any CPU.ActiveCfg = Release|Any CPU
{D5870CF0-ED51-4CBC-B3D7-6F56DA84AC06}.Proto|Any CPU.Build.0 = Release|Any CPU
{D5870CF0-ED51-4CBC-B3D7-6F56DA84AC06}.Proto|x86.ActiveCfg = Release|Any CPU
{D5870CF0-ED51-4CBC-B3D7-6F56DA84AC06}.Proto|x86.Build.0 = Release|Any CPU
{D5870CF0-ED51-4CBC-B3D7-6F56DA84AC06}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D5870CF0-ED51-4CBC-B3D7-6F56DA84AC06}.Release|Any CPU.Build.0 = Release|Any CPU
{D5870CF0-ED51-4CBC-B3D7-6F56DA84AC06}.Release|x86.ActiveCfg = Release|Any CPU
{D5870CF0-ED51-4CBC-B3D7-6F56DA84AC06}.Release|x86.Build.0 = Release|Any CPU
{DED3BBD7-53F4-428A-8C9F-27968E768605}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DED3BBD7-53F4-428A-8C9F-27968E768605}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DED3BBD7-53F4-428A-8C9F-27968E768605}.Debug|x86.ActiveCfg = Debug|Any CPU
Expand Down Expand Up @@ -433,7 +420,6 @@ Global
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{D5870CF0-ED51-4CBC-B3D7-6F56DA84AC06} = {B8DDA694-7939-42E3-95E5-265C2217C142}
{DED3BBD7-53F4-428A-8C9F-27968E768605} = {3058BC79-8E79-4645-B05D-48CC182FA8A6}
{702A7979-BCF9-4C41-853E-3ADFC9897890} = {B8DDA694-7939-42E3-95E5-265C2217C142}
{649FA588-F02E-457C-9FCF-87E46407481E} = {B8DDA694-7939-42E3-95E5-265C2217C142}
Expand Down
17 changes: 1 addition & 16 deletions VisualFSharp.sln
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "FSharp.VS.FSI", "vsintegrat
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "VisualFSharpFull", "vsintegration\Vsix\VisualFSharpFull\VisualFSharpFull.csproj", "{59ADCE46-9740-4079-834D-9A03A3494EBC}"
EndProject
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "FSharp.Compiler.Server.Shared", "src\FSharp.Compiler.Server.Shared\FSharp.Compiler.Server.Shared.fsproj", "{D5870CF0-ED51-4CBC-B3D7-6F56DA84AC06}"
EndProject
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "FSharp.Core", "src\FSharp.Core\FSharp.Core.fsproj", "{DED3BBD7-53F4-428A-8C9F-27968E768605}"
EndProject
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "FSharp.LanguageService", "vsintegration\src\FSharp.LanguageService\FSharp.LanguageService.fsproj", "{EE85AAB7-CDA0-4C4E-BDA0-A64CCC413E3F}"
Expand Down Expand Up @@ -193,7 +191,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "FCSBenchmarks", "FCSBenchma
tests\benchmarks\FCSBenchmarks\SmokeTestAllBenchmarks.ps1 = tests\benchmarks\FCSBenchmarks\SmokeTestAllBenchmarks.ps1
EndProjectSection
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Fsharp.ProfilingStartpointProject", "tests\benchmarks\Fsharp.ProfilingStartpointProject\Fsharp.ProfilingStartpointProject.fsproj", "{FE23BB65-276A-4E41-8CC7-F7752241DEBA}"
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "Fsharp.ProfilingStartpointProject", "tests\benchmarks\Fsharp.ProfilingStartpointProject\Fsharp.ProfilingStartpointProject.fsproj", "{FE23BB65-276A-4E41-8CC7-F7752241DEBA}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -229,18 +227,6 @@ Global
{59ADCE46-9740-4079-834D-9A03A3494EBC}.Release|Any CPU.Build.0 = Release|Any CPU
{59ADCE46-9740-4079-834D-9A03A3494EBC}.Release|x86.ActiveCfg = Release|Any CPU
{59ADCE46-9740-4079-834D-9A03A3494EBC}.Release|x86.Build.0 = Release|Any CPU
{D5870CF0-ED51-4CBC-B3D7-6F56DA84AC06}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D5870CF0-ED51-4CBC-B3D7-6F56DA84AC06}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D5870CF0-ED51-4CBC-B3D7-6F56DA84AC06}.Debug|x86.ActiveCfg = Debug|Any CPU
{D5870CF0-ED51-4CBC-B3D7-6F56DA84AC06}.Debug|x86.Build.0 = Debug|Any CPU
{D5870CF0-ED51-4CBC-B3D7-6F56DA84AC06}.Proto|Any CPU.ActiveCfg = Release|Any CPU
{D5870CF0-ED51-4CBC-B3D7-6F56DA84AC06}.Proto|Any CPU.Build.0 = Release|Any CPU
{D5870CF0-ED51-4CBC-B3D7-6F56DA84AC06}.Proto|x86.ActiveCfg = Release|Any CPU
{D5870CF0-ED51-4CBC-B3D7-6F56DA84AC06}.Proto|x86.Build.0 = Release|Any CPU
{D5870CF0-ED51-4CBC-B3D7-6F56DA84AC06}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D5870CF0-ED51-4CBC-B3D7-6F56DA84AC06}.Release|Any CPU.Build.0 = Release|Any CPU
{D5870CF0-ED51-4CBC-B3D7-6F56DA84AC06}.Release|x86.ActiveCfg = Release|Any CPU
{D5870CF0-ED51-4CBC-B3D7-6F56DA84AC06}.Release|x86.Build.0 = Release|Any CPU
{DED3BBD7-53F4-428A-8C9F-27968E768605}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DED3BBD7-53F4-428A-8C9F-27968E768605}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DED3BBD7-53F4-428A-8C9F-27968E768605}.Debug|x86.ActiveCfg = Debug|Any CPU
Expand Down Expand Up @@ -1045,7 +1031,6 @@ Global
{CCAB6E50-34C6-42AF-A6B0-567C29FCD91B} = {4C7B48D7-19AF-4AE7-9D1D-3BB289D5480D}
{991DCF75-C2EB-42B6-9A0D-AA1D2409D519} = {4C7B48D7-19AF-4AE7-9D1D-3BB289D5480D}
{59ADCE46-9740-4079-834D-9A03A3494EBC} = {4C7B48D7-19AF-4AE7-9D1D-3BB289D5480D}
{D5870CF0-ED51-4CBC-B3D7-6F56DA84AC06} = {B8DDA694-7939-42E3-95E5-265C2217C142}
{DED3BBD7-53F4-428A-8C9F-27968E768605} = {3058BC79-8E79-4645-B05D-48CC182FA8A6}
{EE85AAB7-CDA0-4C4E-BDA0-A64CCC413E3F} = {CCAB6E50-34C6-42AF-A6B0-567C29FCD91B}
{1C5C163C-37EA-4A3C-8CCC-0D34B74BF8EF} = {CCAB6E50-34C6-42AF-A6B0-567C29FCD91B}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
<ProjectReference Include="$(FSharpSourcesRoot)\fsi\fsiArm64Project\fsiArm64.fsproj" />
<ProjectReference Include="$(FSharpSourcesRoot)\FSharp.Build\FSharp.Build.fsproj" />
<ProjectReference Include="$(FSharpSourcesRoot)\FSharp.Compiler.Interactive.Settings\FSharp.Compiler.Interactive.Settings.fsproj" />
<ProjectReference Include="$(FSharpSourcesRoot)\FSharp.Compiler.Server.Shared\FSharp.Compiler.Server.Shared.fsproj" />
<ProjectReference Include="$(FSharpSourcesRoot)\Compiler\FSharp.Compiler.Service.fsproj" />
<ProjectReference Include="$(FSharpSourcesRoot)\FSharp.Core\FSharp.Core.fsproj" />
<ProjectReference Include="$(FSharpSourcesRoot)\FSharp.DependencyManager.Nuget\FSharp.DependencyManager.Nuget.fsproj" />
Expand Down Expand Up @@ -108,7 +107,6 @@ folder "InstallDir:Common7\IDE\CommonExtensions\Microsoft\FSharp\Tools"
file source="$(BinariesFolder)fsc\$(Configuration)\$(TargetFramework)\Microsoft.Build.Framework.dll"
file source="$(BinariesFolder)fsc\$(Configuration)\$(TargetFramework)\Microsoft.Build.Tasks.Core.dll"
file source="$(BinariesFolder)fsc\$(Configuration)\$(TargetFramework)\Microsoft.Build.Utilities.Core.dll"
file source="$(BinariesFolder)FSharp.Compiler.Server.Shared\$(Configuration)\$(TargetFramework)\FSharp.Compiler.Server.Shared.dll" vs.file.ngen=yes vs.file.ngenArchitecture=All vs.file.ngenPriority=2
file source="$(BinariesFolder)FSharp.Core\$(Configuration)\netstandard2.0\FSharp.Core.dll" vs.file.ngen=yes vs.file.ngenArchitecture=All vs.file.ngenPriority=2
file source="$(BinariesFolder)FSharp.Core\$(Configuration)\netstandard2.0\FSharp.Core.xml"
file source="$(BinariesFolder)FSharp.Build\$(Configuration)\netstandard2.0\FSharp.Build.dll" vs.file.ngen=no vs.file.ngenArchitecture=All vs.file.ngenPriority=2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
<_Dependency Include="FSharp.Compiler.Interactive.Settings" Version="$(FSProductVersion)" />
<_Dependency Include="FSharp.Compiler.Service" Version="$(FSharpCompilerServiceVersion)" />
<_Dependency Include="FSharp.DependencyManager.Nuget" Version="$(FSProductVersion)" />
<_Dependency Include="FSharp.Compiler.Server.Shared" Version="$(FSProductVersion)" />
<_Dependency Include="FSharp.Core" Version="$(FSCoreVersion)" />
<_Dependency Include="FSharp.Editor" Version="$(VSAssemblyVersion)" />
<_Dependency Include="FSharp.LanguageService.Base" Version="$(VSAssemblyVersion)" />
Expand Down
3 changes: 2 additions & 1 deletion src/Compiler/FSharp.Compiler.Service.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@
<InternalsVisibleTo Include="fsi" />
<InternalsVisibleTo Include="fsiAnyCpu" />
<InternalsVisibleTo Include="fsiArm64" />
<InternalsVisibleTo Include="FSharp.Compiler.Server.Shared" />
<InternalsVisibleTo Include="VisualFSharp.Salsa" />
<InternalsVisibleTo Include="VisualFSharp.UnitTests" />
<InternalsVisibleTo Include="FSharp.Compiler.UnitTests" />
Expand Down Expand Up @@ -456,6 +455,8 @@
<Compile Include="Service\ServiceStructure.fs" />
<Compile Include="Service\ServiceAnalysis.fsi" />
<Compile Include="Service\ServiceAnalysis.fs" />
<Compile Include="Interactive\FSharpInteractiveServer.fsi" />
<Compile Include="Interactive\FSharpInteractiveServer.fs" />
<Compile Include="Interactive\ControlledExecution.fs" />
<Compile Include="Interactive\fsi.fsi" />
<Compile Include="Interactive\fsi.fs" />
Expand Down
68 changes: 68 additions & 0 deletions src/Compiler/Interactive/FSharpInteractiveServer.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.
namespace FSharp.Compiler.Interactive

open System
open System.Text
open System.Diagnostics
open System.IO
open System.IO.Pipes
open System.Threading

module CtrlBreakHandlers =

let interuptCommand = "Interactive-CtrlCNotificationCommand-Interupt"

let lineInteruptCommand =
Encoding.UTF8.GetBytes(interuptCommand + Environment.NewLine)

let connectionTimeout = 1000

[<AbstractClass>]
type public CtrlBreakService(channelName: string) =

abstract Interrupt: unit -> unit

// Exceptions percolate to callsite, IO exceptions must be handled by caller
// Should be run on a new thread
member this.Run() : unit =
let service = new NamedPipeServerStream(channelName, PipeDirection.In)

// Wait for a client to connect
service.WaitForConnection()
use stream = new StreamReader(service)

try
while not (stream.EndOfStream) do
let line = stream.ReadLine()

if line = interuptCommand then
this.Interrupt()
finally
stream.Close()
service.Close()

type public CtrlBreakClient(channelName: string) =

let mutable service: NamedPipeClientStream option =
Some(new NamedPipeClientStream(".", channelName, PipeDirection.Out))

member this.Interrupt() =
match service with
| None -> ()
| Some client ->
try
if not (client.IsConnected) then
client.Connect(connectionTimeout)
with _ ->
()

client.Write(lineInteruptCommand, 0, lineInteruptCommand.Length)
client.Flush()

interface IDisposable with
member _.Dispose() =
match service with
| None -> ()
| Some client ->
client.Dispose()
service <- None
22 changes: 22 additions & 0 deletions src/Compiler/Interactive/FSharpInteractiveServer.fsi
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.
namespace FSharp.Compiler.Interactive

open System

module CtrlBreakHandlers =

[<AbstractClass>]
type public CtrlBreakService =
new: channelName: string -> CtrlBreakService

abstract Interrupt: unit -> unit

member Run: unit -> unit

type public CtrlBreakClient =

new: channelName: string -> CtrlBreakClient

member Interrupt: unit -> unit

interface IDisposable
9 changes: 0 additions & 9 deletions src/FSharp.Compiler.Server.Shared/AssemblyInfo.fs

This file was deleted.

9 changes: 0 additions & 9 deletions src/FSharp.Compiler.Server.Shared/Directory.Build.props

This file was deleted.

This file was deleted.

47 changes: 0 additions & 47 deletions src/FSharp.Compiler.Server.Shared/FSharpInteractiveServer.fs

This file was deleted.

3 changes: 0 additions & 3 deletions src/fsi/fsi.targets
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,6 @@
<ProjectReference Include="$(MSBuildThisFileDirectory)..\FSharp.Core\FSharp.Core.fsproj" />
<ProjectReference Include="$(MSBuildThisFileDirectory)..\Compiler\FSharp.Compiler.Service.fsproj" />
<ProjectReference Include="$(MSBuildThisFileDirectory)..\FSharp.Compiler.Interactive.Settings\FSharp.Compiler.Interactive.Settings.fsproj" />

<!-- only used when '$(TargetFramework)' == 'net472' -->
<ProjectReference Include="$(MSBuildThisFileDirectory)..\FSharp.Compiler.Server.Shared\FSharp.Compiler.Server.Shared.fsproj" Condition="'$(TargetFramework)' == 'net472'" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net472'">
Expand Down
12 changes: 6 additions & 6 deletions src/fsi/fsimain.fs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
module internal Sample.FSharp.Compiler.Interactive.Main

open System
open System.Diagnostics
open System.Globalization
open System.IO
open System.Reflection
Expand All @@ -22,6 +23,8 @@ open System.Windows.Forms

open FSharp.Compiler
open FSharp.Compiler.AbstractIL
open FSharp.Compiler.Interactive
open FSharp.Compiler.Interactive.CtrlBreakHandlers
open FSharp.Compiler.Interactive.Shell
open FSharp.Compiler.Interactive.Shell.Settings
open FSharp.Compiler.CodeAnalysis
Expand Down Expand Up @@ -147,9 +150,9 @@ let internal TrySetUnhandledExceptionMode () =

/// Starts the remoting server to handle interrupt reuests from a host tool.
let StartServer (fsiSession: FsiEvaluationSession) (fsiServerName) =
#if FSI_SERVER
let server =
{ new Server.Shared.FSharpInteractiveServer() with

{ new CtrlBreakService(fsiServerName) with
member _.Interrupt() =
//printf "FSI-SERVER: received CTRL-C request...\n"
try
Expand All @@ -160,10 +163,7 @@ let StartServer (fsiSession: FsiEvaluationSession) (fsiServerName) =
()
}

Server.Shared.FSharpInteractiveServer.StartServer(fsiServerName, server)
#else
ignore (fsiSession, fsiServerName)
#endif
server.Run()

//----------------------------------------------------------------------------
// GUI runCodeOnMainThread
Expand Down
Loading

0 comments on commit e381e35

Please sign in to comment.