Skip to content

Commit 4aba012

Browse files
committed
Console: enhanced warning reporting
Improved warning reporting to display line number and column in the format: `fileName.fs(lineNumber, column)`. This feature is particularly useful in environments like VSCode, which highlights these locations and makes them clickable. When clicked, VSCode will open the corresponding file at the exact line and position of the cursor. This functionality allows developers to quickly navigate to the source of the issue, significantly speeding up the debugging process.
1 parent c978b08 commit 4aba012

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

src/FSharpLint.Console/Output.fs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,24 @@ type IOutput =
1414

1515
type StandardOutput () =
1616

17-
let getErrorMessage (range:Range) =
17+
let getErrorMessage (range:Range) (filePath:string) =
1818
let error = Resources.GetString("LintSourceError")
19-
String.Format(error, range.StartLine, range.StartColumn)
20-
21-
let highlightErrorText (range:Range) (errorLine:string) =
19+
let startLine = range.StartLine
20+
let startColumn = range.StartColumn
21+
String.Format(
22+
error,
23+
startLine,
24+
startColumn,
25+
$"%s{filePath}(%i{startLine},%i{startColumn})"
26+
)
27+
let highlightErrorText (filePath: string) (range:Range) (errorLine:string) =
2228
let highlightColumnLine =
2329
if String.length errorLine = 0 then "^"
2430
else
2531
errorLine
2632
|> Seq.mapi (fun i _ -> if i = range.StartColumn then "^" else " ")
2733
|> Seq.reduce (+)
28-
$"{getErrorMessage range}{Environment.NewLine}{errorLine}{Environment.NewLine}{highlightColumnLine}"
34+
$"{getErrorMessage range filePath}{Environment.NewLine}{errorLine}{Environment.NewLine}{highlightColumnLine}"
2935

3036
let writeLine (str:string) (color:ConsoleColor) (writer:IO.TextWriter) =
3137
let originalColour = Console.ForegroundColor
@@ -37,7 +43,7 @@ type StandardOutput () =
3743

3844
member _.WriteInfo (info:string) = writeLine info ConsoleColor.White Console.Out
3945
member this.WriteWarning (warning:Suggestion.LintWarning) =
40-
let highlightedErrorText = highlightErrorText warning.Details.Range warning.ErrorText
46+
let highlightedErrorText = highlightErrorText warning.FilePath warning.Details.Range warning.ErrorText
4147
let ruleUrlHint = $"See https://fsprojects.github.io/FSharpLint/how-tos/rules/%s{warning.RuleIdentifier}.html"
4248
let str = $"{warning.Details.Message}{Environment.NewLine}{highlightedErrorText}{Environment.NewLine}{ruleUrlHint}"
4349
writeLine str ConsoleColor.Yellow Console.Out

src/FSharpLint.Core/Text.resx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@
238238
<value>A tuple of wildcards in a pattern can be replaced with a single wildcard. `{0}` can be replaced with `{1}`.</value>
239239
</data>
240240
<data name="LintSourceError" xml:space="preserve">
241-
<value>Error on line {0} starting at column {1}</value>
241+
<value>Error on line {0} starting at column {1}: {2}</value>
242242
</data>
243243
<data name="RulesCanBeReplacedWithComposition" xml:space="preserve">
244244
<value>Lambda may be able to be replaced with composition. e.g. `fun x -&gt; x |&gt; isValid |&gt; not` could be replaced with `isValid &gt;&gt; not`.</value>

0 commit comments

Comments
 (0)