未验证 提交 186d3f6c 编写于 作者: K Kevin Ransom (msft) 提交者: GitHub

Fix 14340 - Prompt issues between VS and fsi. (#14383)

Co-authored-by: NPetr Pokorny <petr@innit.cz>
Co-authored-by: NVlad Zarytovskii <vzaritovsky@hotmail.com>
上级 8e3b97b1
......@@ -193,7 +193,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "FCSBenchmarks", "FCSBenchma
EndProject
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "Fsharp.ProfilingStartpointProject", "tests\benchmarks\Fsharp.ProfilingStartpointProject\Fsharp.ProfilingStartpointProject.fsproj", "{FE23BB65-276A-4E41-8CC7-F7752241DEBA}"
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "FSharp.Editor.Tests", "vsintegration\tests\FSharp.Editor.Tests\FSharp.Editor.Tests.fsproj", "{CBC96CC7-65AB-46EA-A82E-F6A788DABF80}"
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "FSharp.Editor.Tests", "vsintegration\tests\FSharp.Editor.Tests\FSharp.Editor.Tests.fsproj", "{CBC96CC7-65AB-46EA-A82E-F6A788DABF80}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
......
......@@ -1127,15 +1127,38 @@ type internal FsiConsolePrompt(fsiOptions: FsiCommandLineOptions, fsiConsoleOutp
// A prompt gets "printed ahead" at start up. Tells users to start type while initialisation completes.
// A prompt can be skipped by "silent directives", e.g. ones sent to FSI by VS.
let mutable dropPrompt = 0
let mutable showPrompt = true
// NOTE: SERVER-PROMPT is not user displayed, rather it's a prefix that code elsewhere
// uses to identify the prompt, see service\FsPkgs\FSharp.VS.FSI\fsiSessionToolWindow.fs
let prompt = if fsiOptions.UseServerPrompt then "SERVER-PROMPT>\n" else "> "
member _.Print() = if dropPrompt = 0 then fsiConsoleOutput.uprintf "%s" prompt else dropPrompt <- dropPrompt - 1
let prompt =
if fsiOptions.UseServerPrompt then
"SERVER-PROMPT>" + Environment.NewLine
else
"> "
member _.Print() =
if showPrompt then
if dropPrompt = 0 then
fsiConsoleOutput.uprintf "%s" prompt
else
dropPrompt <- dropPrompt - 1
member _.PrintAhead() =
if showPrompt then
dropPrompt <- dropPrompt + 1
fsiConsoleOutput.uprintf "%s" prompt
member _.PrintAhead() = dropPrompt <- dropPrompt + 1; fsiConsoleOutput.uprintf "%s" prompt
// Can be turned off when executing blocks of code using:
// # silentPrompt
member _.ShowPrompt
with get () = showPrompt
and set (value) = showPrompt <- value
member _.SkipNext() = dropPrompt <- dropPrompt + 1
member _.SkipNext() =
if showPrompt then
dropPrompt <- dropPrompt + 1
member _.FsiOptions = fsiOptions
......@@ -2772,6 +2795,15 @@ type FsiInteractionProcessor
fsiConsolePrompt.SkipNext() (* "silent" directive *)
istate, Completed None
| ParsedHashDirective("interactiveprompt", ParsedHashDirectiveArguments ["show" | "hide" | "skip" as showPrompt], m) ->
match showPrompt with
| "show" -> fsiConsolePrompt.ShowPrompt <- true
| "hide" -> fsiConsolePrompt.ShowPrompt <- false
| "skip" -> fsiConsolePrompt.SkipNext()
| _ -> error(Error((FSComp.SR.fsiInvalidDirective("prompt", String.concat " " [showPrompt])), m))
istate, Completed None
| ParsedHashDirective("dbgbreak", [], _) ->
let istate = {istate with debugBreak = true}
istate, Completed None
......@@ -3072,7 +3104,7 @@ type FsiInteractionProcessor
// After we've unblocked and got something to run we switch
// over to the run-thread (e.g. the GUI thread)
let res = istate |> runCodeOnMainThread (fun ctok istate -> ExecuteParsedInteractionOnMainThread (ctok, diagnosticsLogger, action, istate, cancellationToken))
let res = istate |> runCodeOnMainThread (fun ctok istate -> ExecuteParsedInteractionOnMainThread (ctok, diagnosticsLogger, action, istate, cancellationToken))
if progress then fprintfn fsiConsoleOutput.Out "Just called runCodeOnMainThread, res = %O..." res
res)
......
......@@ -1126,6 +1126,7 @@ type FSharpLineTokenizer(lexbuf: UnicodeLexing.Lexbuf, maxLength: int option, fi
| true, "savedll"
| true, "nosavedll"
#endif
| true, "interactiveprompt"
| true, "silentCd"
| true, "q"
| true, "quit"
......
......@@ -534,17 +534,16 @@ type internal FsiToolWindow() as this =
executeTextNoHistory null text
with _ -> ()
let executeInteraction dbgBreak dir (filename: string) topLine text =
// Preserving previous functionality, including the #directives...
let interaction =
"\n"
+ (sprintf "# silentCd @\"%s\" ;; " dir) + "\n"
+ (if dbgBreak then "# dbgbreak\n" else "")
+ (sprintf "# %d @\"%s\" " topLine filename) + "\n"
+ text + "\n"
+ "# 1 \"stdin\"" + "\n" (* stdin line number reset code *)
+ ";;" + "\n"
let executeInteraction dbgBreak dir filename topLine (text:string) =
let interaction = $"""
#interactiveprompt "hide"
#silentCd @"{dir}";;
{if dbgBreak then "#dbgbreak" else ""}
#{topLine} @"{filename}"
{text.ToString()}
#1 "stdin"
#interactiveprompt "show";;
"""
executeTextNoHistory filename interaction
let sendSelectionToFSI action =
......@@ -555,8 +554,8 @@ type internal FsiToolWindow() as this =
| DebugSelection -> true, false
try
let dte = provider.GetService(typeof<DTE>) :?> DTE
let activeD = dte.ActiveDocument
let dte = provider.GetService(typeof<DTE>) :?> DTE
let activeD = dte.ActiveDocument
match activeD.Selection with
| :? TextSelection as selection when selectLine || selection.Text = "" ->
selection.SelectLine()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册