@@ -441,12 +441,16 @@ type internal FsiToolWindow() as this =
441441|> Seq.cast< Process>
442442|> Seq.tryFind( fun p -> p.ProcessID= fsiProcId)
443443
444+ let debuggerIsRunning () =
445+ let dte = provider.GetService( typeof< DTE>) :?> DTE
446+ dte.Debugger.DebuggedProcesses<> null && dte.Debugger.DebuggedProcesses.Count> 0
447+
444448let attachDebugger () =
445449let fsiProcId = sessions.ProcessID
446450let dte = provider.GetService( typeof< DTE>) :?> DTE
447451
448452// only attach if no other debugging happening
449- if dte.Debugger.CurrentProcess = null then
453+ if dte.Debugger.DebuggedProcesses = null || dte.Debugger.DebuggedProcesses.Count = 0 then
450454let fsiProc =
451455if dte.Debugger.LocalProcesses= null then Noneelse
452456 dte.Debugger.LocalProcesses
@@ -466,6 +470,10 @@ type internal FsiToolWindow() as this =
466470 attachDebugger()
467471 showNoActivate()
468472
473+ let onDetachDebugger ( sender : obj ) ( args : EventArgs ) =
474+ detachDebugger()
475+ showNoActivate()
476+
469477let sendTextToFSI text =
470478try
471479 showNoActivate()
@@ -637,6 +645,7 @@ type internal FsiToolWindow() as this =
637645 addCommand Guids.guidInteractiveCommands Guids.cmdIDSessionInterrupt onInterrupt None
638646 addCommand Guids.guidInteractiveCommands Guids.cmdIDSessionRestart onRestart None
639647 addCommand Guids.guidFsiConsoleCmdSet Guids.cmdIDAttachDebugger onAttachDebugger None
648+ addCommand Guids.guidFsiConsoleCmdSet Guids.cmdIDDetachDebugger onDetachDebugger None
640649
641650 addCommand Guids.guidInteractiveShell Guids.cmdIDSendSelection onMLSend None
642651 addCommand Guids.guidInteractive Guids.cmdIDDebugSelection onMLDebugSelection None
@@ -659,6 +668,18 @@ type internal FsiToolWindow() as this =
659668 context.AddAttribute( VSUSERCONTEXTATTRIBUTEUSAGE.VSUC_ Usage_ LookupF1, " Keyword" , " VS.FSharpInteractive" ) |> ignore
660669| _ -> Debug.Assert( false )
661670
671+ member __.QueryCommandStatus ( guidCmdGroup : Guid , nCmdId : uint32 ) =
672+ match () with
673+ | _ when guidCmdGroup= Guids.guidFsiConsoleCmdSet&& nCmdId= uint32 Guids.cmdIDAttachDebugger->
674+ if debuggerIsRunning() then Some( OLECMDF.OLECMDF_ INVISIBLE)
675+ else Some( OLECMDF.OLECMDF_ SUPPORTED||| OLECMDF.OLECMDF_ ENABLED)
676+
677+ | _ when guidCmdGroup= Guids.guidFsiConsoleCmdSet&& nCmdId= uint32 Guids.cmdIDDetachDebugger->
678+ if getDebugAttachedFSIProcess() |> Option.isSomethen Some( OLECMDF.OLECMDF_ SUPPORTED||| OLECMDF.OLECMDF_ ENABLED)
679+ else Some( OLECMDF.OLECMDF_ INVISIBLE)
680+
681+ | _ -> None
682+
662683interface ITestVFSIwith
663684/// Send a string; the ';;' will be added to the end; does not interact with history
664685member this.SendTextInteraction ( s : string ) =
@@ -711,6 +732,15 @@ type internal FsiToolWindow() as this =
711732if not ( wpfTextView.HasAggregateFocus) || isFocusedElementInterceptsCommandRouting() then
712733( int Microsoft.VisualStudio.OLE.Interop.Constants.OLECMDERR_ E_ NOTSUPPORTED)
713734else
735+ let mutable allHandled = true
736+ for i= 0 to (( int cCmds) - 1 ) do
737+ match this.QueryCommandStatus( guid, prgCmds.[ i]. cmdID) with
738+ | Some( commandStatus) ->
739+ prgCmds.[ i]. cmdf<- uint32 commandStatus
740+ | None->
741+ allHandled<- false
742+
743+ if allHandledthen 0 else
714744let target : IOleCommandTarget = upcast commandService
715745 target.QueryStatus(& guid, cCmds, prgCmds, pCmdText)
716746