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

Dotnet fsi broken on inputs that take more than 1 line #14946

Closed
ieviev opened this issue Mar 21, 2023 · 10 comments · Fixed by #16251
Closed

Dotnet fsi broken on inputs that take more than 1 line #14946

ieviev opened this issue Mar 21, 2023 · 10 comments · Fixed by #16251
Assignees
Labels
Area-FSI Bug Impact-High (Internal MS Team use only) Describes an issue with extreme impact on existing code. Regression
Milestone

Comments

@ieviev
Copy link

ieviev commented Mar 21, 2023

Please provide a succinct description of the issue.

dotnet fsi breaks because it cannot read multiline expressions

Provide the steps required to reproduce the problem:

1 run dotnet fsi
2 insert any expr taking more than 1 line in console
3 reach the bottom of console
4 the interpreter goes crazy

7.0.2xx sdk:
dotnet-fsi

issue does not exist in 7.0.1** sdk:
dotnet-fsi-old

workaround is to revert back to 7.0.1

sudo apt-get install dotnet-sdk-7.0=7.0.104-1
@github-actions github-actions bot added this to the Backlog milestone Mar 21, 2023
@KevinRansom
Copy link
Member

This repros on linux, not windows.

@NatElkins
Copy link
Contributor

I also experienced this on macOS.

@bonjune
Copy link

bonjune commented May 2, 2023

Repros on MacOS

Screen.Recording.2023-05-02.at.5.12.09.PM.mov
$ dotnet fsi

Microsoft (R) F# Interactive version 12.5.0.0 for F# 7.0
Copyright (c) Microsoft Corporation. All Rights Reserved.

For help type #help;;

> adjksbfaksdlbfjaklsdfjbasdklfjbdskljfbadjkslbfasdjklfbksadjfbk
lsadjfbadklsjbfskladjbfajklsbfadjksbfadjksbfsjkldbfjklasbfjklasb
fjklsafkadlsfhajklsfhaklsjfhskljfahsdklfjhasdklfjhsadjkfhadjksfh
ajklsfhadsjkfhajklsfhklajsfhklajsfhajkslfhajklsfhjklshfjksafklds

System.PlatformNotSupportedException: Operation is not supported on this platform.
   at System.ConsolePal.set_BufferHeight(Int32 value)
   at <StartupCode$fsi>.$Console.moveCursorToNextLine@345(ReadLineConsole x, Char c) in D:\a\_work\1\s\src\fsi\console.fs:line 350
   at <StartupCode$fsi>.$Console.writeChar@358(ReadLineConsole x, FSharpRef`1 rendered, Char c) in D:\a\_work\1\s\src\fsi\console.fs:line 367
   at <StartupCode$fsi>.$Console.insertChar@402(ReadLineConsole x, StringBuilder input, FSharpRef`1 anchor, FSharpRef`1 rendered, FSharpRef`1 current, Char c) in D:\a\_work\1\s\src\fsi\console.fs:line 410
   at <StartupCode$fsi>.$Console.read@544(ReadLineConsole x, StringBuilder input, FSharpRef`1 anchor, FSharpRef`1 rendered, FSharpRef`1 changed, FSharpRef`1 optionsCache, FSharpRef`1 current, Unit unitVar0) in D:\a\_work\1\s\src\fsi\console.fs:line 634
   at FSharp.Compiler.Interactive.ReadLineConsole.ReadLine() in D:\a\_work\1\s\src\fsi\console.fs:line 643
   at FSharp.Compiler.Interactive.Shell.-ctor@1182-163.Invoke() in D:\a\_work\1\s\src\Compiler\Interactive\fsi.fs:line 1186
   at System.Threading.Thread.StartCallback()
Stopped due to error
Unhandled exception. System.PlatformNotSupportedException: Operation is not supported on this platform.
   at System.ConsolePal.set_BufferHeight(Int32 value)
   at <StartupCode$fsi>.$Console.moveCursorToNextLine@345(ReadLineConsole x, Char c) in D:\a\_work\1\s\src\fsi\console.fs:line 350
   at <StartupCode$fsi>.$Console.writeChar@358(ReadLineConsole x, FSharpRef`1 rendered, Char c) in D:\a\_work\1\s\src\fsi\console.fs:line 367
   at <StartupCode$fsi>.$Console.insertChar@402(ReadLineConsole x, StringBuilder input, FSharpRef`1 anchor, FSharpRef`1 rendered, FSharpRef`1 current, Char c) in D:\a\_work\1\s\src\fsi\console.fs:line 410
   at <StartupCode$fsi>.$Console.read@544(ReadLineConsole x, StringBuilder input, FSharpRef`1 anchor, FSharpRef`1 rendered, FSharpRef`1 changed, FSharpRef`1 optionsCache, FSharpRef`1 current, Unit unitVar0) in D:\a\_work\1\s\src\fsi\console.fs:line 634
   at FSharp.Compiler.Interactive.ReadLineConsole.ReadLine() in D:\a\_work\1\s\src\fsi\console.fs:line 643
   at FSharp.Compiler.Interactive.Shell.-ctor@1182-163.Invoke() in D:\a\_work\1\s\src\Compiler\Interactive\fsi.fs:line 1186
   at System.Threading.Thread.StartCallback()

@KevinRansom KevinRansom modified the milestones: Backlog, June-2023 Jun 10, 2023
@sgoguen
Copy link
Contributor

sgoguen commented Jun 11, 2023

It appears #14365 rewrote how line advances on FSharp.Compiler.Interactive.ReadLineConsole() to accommodate East Asian Width characters per https://www.unicode.org/reports/tr11/

Unfortunately, this fix advances the next line by setting Console.BufferHeight by incrementing it (which is not supported in UNIX).

        let moveCursorToNextLine c =
            let charSize = x.GetCharacterSize(c)

            if Console.CursorLeft + charSize > Utils.bufferWidth () then
                if Console.CursorTop + 1 = Console.BufferHeight then
                    Console.BufferHeight <- Console.BufferHeight + 1

                Cursor.Move(0)

I was able to fix it from catastrophically failing on my Mac by wrapping the code that sets the BufferHeight it in a try block and writing a new line, but that breaks any editing functionality.

@sgoguen
Copy link
Contributor

sgoguen commented Jun 11, 2023

The following update to console.fs to the function seems to resolve the issue on my Mac.

        let moveCursorToNextLine c =
            let charSize = x.GetCharacterSize(c)

            if Console.CursorLeft + charSize > Utils.bufferWidth () then
                if Console.CursorTop + 1 = Console.BufferHeight then
                    try
                        Console.BufferHeight <- Console.BufferHeight + 1
                    with _ ->
                        // If we can't increase the buffer height, just write a newline.
                        Console.WriteLine()
                        // When we add a newline, we need to reflect the change in the anchor.
                        anchor <- { anchor with top = (anchor).top - 1 }
                    
                Cursor.Move(0)

@MrLuje
Copy link

MrLuje commented Nov 4, 2023

Got bitten by this today once again (#14160 (comment)) 😞

@sgoguen are you going to make a PR for it ?
I confirm this fix this issue. I guess we could even get rid of the try block and only go with the with part, since only windows will go to the happy path

        let moveCursorToNextLine c =
            let charSize = x.GetCharacterSize(c)

            if Console.CursorLeft + charSize > Utils.bufferWidth () then
                if Console.CursorTop + 1 = Console.BufferHeight then
                    Console.WriteLine()
                    // When we add a newline, we need to reflect the change in the anchor.
                    anchor <- { anchor with top = (anchor).top - 1 }
                    
                Cursor.Move(0)

@vzarytovskii vzarytovskii removed this from the June-2023 milestone Nov 4, 2023
@vzarytovskii vzarytovskii added the Impact-High (Internal MS Team use only) Describes an issue with extreme impact on existing code. label Nov 4, 2023
@T-Gro T-Gro self-assigned this Nov 4, 2023
@vzarytovskii
Copy link
Member

It seems I'm not able to see it on macOS on 8.0rc2 not sure how to reproduce it.

@MrLuje
Copy link

MrLuje commented Nov 6, 2023

@vzarytovskii Assign a long string to a variable (string longer than terminal's width) and do it enough times to hit the bottom of the terminal (to trigger the scrolling)

I was having it with RC1 this weekend, I'll try again with RC2
EDIT: still have it on RC2 (devcontainers from WSL2)

@athrun
Copy link

athrun commented Dec 17, 2023

I can reproduce this bug in Homebrew's currently shipping dotnet 8 build: #16251 (comment)

@vzarytovskii
Copy link
Member

It didn't get to release for 8.0.100 for sure, I'd expect it in 8.0.200

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-FSI Bug Impact-High (Internal MS Team use only) Describes an issue with extreme impact on existing code. Regression
Projects
Archived in project
9 participants