dotnet / roslyn

The Roslyn .NET compiler provides C# and Visual Basic languages with rich code analysis APIs.
https://docs.microsoft.com/dotnet/csharp/roslyn-sdk/
MIT License
19.02k stars 4.03k forks source link

Improve error messages in REPL by printing and underlining failed line of code #7314

Open drognanar opened 8 years ago

drognanar commented 8 years ago

When parser fails it prints the error along with the location of failures. The REPL does not underline this location making it hard to locate the problem. For instance given the following submissions:

> public class MyClassA {}
> public class MyClassB : MyClass A { }

REPL will print the following error:

(1,33): error CS1003: Syntax error, ',' expected

The following error message would be more readable:

public class MyClassB : MyClass A { }
-------------------------------^-----
(1,33): error CS1003: Syntax error, ',' expected
tmat commented 8 years ago

This can get complicated with multi-line input. Perhaps we could use Console API to highlight the error locations (dark-red background color or light-red foreground color)?

tmat commented 8 years ago

Also note that VB compiler prints out ~~~ for errors. That could also work in REPL, although it makes the output longer since we need to echo the lines that contain the errors.