Skip to content

Commit a55c3c8

Browse files
committed
prompt
1 parent 92b2b5d commit a55c3c8

File tree

4 files changed

+51
-19
lines changed

4 files changed

+51
-19
lines changed

VisualFSharp.sln

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "FCSBenchmarks", "FCSBenchma
193193
EndProject
194194
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "Fsharp.ProfilingStartpointProject", "tests\benchmarks\Fsharp.ProfilingStartpointProject\Fsharp.ProfilingStartpointProject.fsproj", "{FE23BB65-276A-4E41-8CC7-F7752241DEBA}"
195195
EndProject
196-
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "FSharp.Editor.Tests", "vsintegration\tests\FSharp.Editor.Tests\FSharp.Editor.Tests.fsproj", "{CBC96CC7-65AB-46EA-A82E-F6A788DABF80}"
196+
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "FSharp.Editor.Tests", "vsintegration\tests\FSharp.Editor.Tests\FSharp.Editor.Tests.fsproj", "{CBC96CC7-65AB-46EA-A82E-F6A788DABF80}"
197197
EndProject
198198
Global
199199
GlobalSection(SolutionConfigurationPlatforms) = preSolution

src/Compiler/Interactive/fsi.fs

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1127,15 +1127,38 @@ type internal FsiConsolePrompt(fsiOptions: FsiCommandLineOptions, fsiConsoleOutp
11271127
// A prompt gets "printed ahead" at start up. Tells users to start type while initialisation completes.
11281128
// A prompt can be skipped by "silent directives", e.g. ones sent to FSI by VS.
11291129
let mutable dropPrompt = 0
1130+
let mutable showPrompt = true
1131+
11301132
// NOTE: SERVER-PROMPT is not user displayed, rather it's a prefix that code elsewhere
11311133
// uses to identify the prompt, see service\FsPkgs\FSharp.VS.FSI\fsiSessionToolWindow.fs
1132-
let prompt = if fsiOptions.UseServerPrompt then "SERVER-PROMPT>\n" else "> "
11331134

1134-
member _.Print() = if dropPrompt = 0 then fsiConsoleOutput.uprintf "%s" prompt else dropPrompt <- dropPrompt - 1
1135+
let prompt =
1136+
if fsiOptions.UseServerPrompt then
1137+
"SERVER-PROMPT>" + Environment.NewLine
1138+
else
1139+
"> "
1140+
1141+
member _.Print() =
1142+
if showPrompt then
1143+
if dropPrompt = 0 then
1144+
fsiConsoleOutput.uprintf "%s" prompt
1145+
else
1146+
dropPrompt <- dropPrompt - 1
1147+
1148+
member _.PrintAhead() =
1149+
if showPrompt then
1150+
dropPrompt <- dropPrompt + 1
1151+
fsiConsoleOutput.uprintf "%s" prompt
11351152

1136-
member _.PrintAhead() = dropPrompt <- dropPrompt + 1; fsiConsoleOutput.uprintf "%s" prompt
1153+
// Can be turned off when executing blocks of code using:
1154+
// # silentPrompt
1155+
member _.ShowPrompt
1156+
with get () = showPrompt
1157+
and set (value) = showPrompt <- value
11371158

1138-
member _.SkipNext() = dropPrompt <- dropPrompt + 1
1159+
member _.SkipNext() =
1160+
if showPrompt then
1161+
dropPrompt <- dropPrompt + 1
11391162

11401163
member _.FsiOptions = fsiOptions
11411164

@@ -2772,6 +2795,15 @@ type FsiInteractionProcessor
27722795
fsiConsolePrompt.SkipNext() (* "silent" directive *)
27732796
istate, Completed None
27742797

2798+
| ParsedHashDirective("interactiveprompt", ParsedHashDirectiveArguments ["show" | "hide" | "skip" as showPrompt], m) ->
2799+
match showPrompt with
2800+
| "show" -> fsiConsolePrompt.ShowPrompt <- true
2801+
| "hide" -> fsiConsolePrompt.ShowPrompt <- false
2802+
| "skip" -> fsiConsolePrompt.SkipNext()
2803+
| _ -> error(Error((FSComp.SR.fsiInvalidDirective("prompt", String.concat " " [showPrompt])), m))
2804+
2805+
istate, Completed None
2806+
27752807
| ParsedHashDirective("dbgbreak", [], _) ->
27762808
let istate = {istate with debugBreak = true}
27772809
istate, Completed None
@@ -3072,7 +3104,7 @@ type FsiInteractionProcessor
30723104

30733105
// After we've unblocked and got something to run we switch
30743106
// over to the run-thread (e.g. the GUI thread)
3075-
let res = istate |> runCodeOnMainThread (fun ctok istate -> ExecuteParsedInteractionOnMainThread (ctok, diagnosticsLogger, action, istate, cancellationToken))
3107+
let res = istate |> runCodeOnMainThread (fun ctok istate ->ExecuteParsedInteractionOnMainThread (ctok, diagnosticsLogger, action, istate, cancellationToken))
30763108

30773109
if progress then fprintfn fsiConsoleOutput.Out "Just called runCodeOnMainThread, res = %O..." res
30783110
res)

src/Compiler/Service/ServiceLexing.fs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1126,6 +1126,7 @@ type FSharpLineTokenizer(lexbuf: UnicodeLexing.Lexbuf, maxLength: int option, fi
11261126
| true, "savedll"
11271127
| true, "nosavedll"
11281128
#endif
1129+
| true, "interactiveprompt"
11291130
| true, "silentCd"
11301131
| true, "q"
11311132
| true, "quit"

vsintegration/src/FSharp.VS.FSI/fsiSessionToolWindow.fs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -534,17 +534,16 @@ type internal FsiToolWindow() as this =
534534
executeTextNoHistory null text
535535
with _ -> ()
536536

537-
let executeInteraction dbgBreak dir (filename: string) topLine text =
538-
// Preserving previous functionality, including the #directives...
539-
let interaction =
540-
"\n"
541-
+ (sprintf "# silentCd @\"%s\" ;; " dir) + "\n"
542-
+ (if dbgBreak then "# dbgbreak\n" else "")
543-
+ (sprintf "# %d @\"%s\" " topLine filename) + "\n"
544-
+ text + "\n"
545-
+ "# 1 \"stdin\"" + "\n" (* stdin line number reset code *)
546-
+ ";;" + "\n"
547-
537+
let executeInteraction dbgBreak dir filename topLine (text:string) =
538+
let interaction = $"""
539+
#interactiveprompt "hide"
540+
#silentCd @"{dir}";;
541+
{if dbgBreak then "#dbgbreak" else ""}
542+
#{topLine} @"{filename}"
543+
{text.ToString()};;
544+
#1 "stdin"
545+
#interactiveprompt "show";;
546+
"""
548547
executeTextNoHistory filename interaction
549548

550549
let sendSelectionToFSI action =
@@ -555,8 +554,8 @@ type internal FsiToolWindow() as this =
555554
| DebugSelection -> true, false
556555

557556
try
558-
let dte = provider.GetService(typeof<DTE>) :?> DTE
559-
let activeD = dte.ActiveDocument
557+
let dte = provider.GetService(typeof<DTE>) :?> DTE
558+
let activeD = dte.ActiveDocument
560559
match activeD.Selection with
561560
| :? TextSelection as selection when selectLine || selection.Text = "" ->
562561
selection.SelectLine()

0 commit comments

Comments
 (0)