From e5a6d72cf67ac7f64f414863e85b5d6722ef420c Mon Sep 17 00:00:00 2001 From: Tomas Grosup Date: Fri, 12 Jul 2024 20:18:39 +0200 Subject: [PATCH 1/2] defensive checks added --- .../FSharp.Editor/TaskList/TaskListService.fs | 39 +++++++++++-------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/vsintegration/src/FSharp.Editor/TaskList/TaskListService.fs b/vsintegration/src/FSharp.Editor/TaskList/TaskListService.fs index 1c52afd7364..05589ff76ec 100644 --- a/vsintegration/src/FSharp.Editor/TaskList/TaskListService.fs +++ b/vsintegration/src/FSharp.Editor/TaskList/TaskListService.fs @@ -83,23 +83,30 @@ type internal FSharpTaskListService [] () as this = ) |> extractContractedComments - for ct in contractedTokens do + if contractedTokens |> List.isEmpty then + () + else let lineTxt = line.ToString() - let tokenSize = 1 + (ct.Right - ct.Left) - - for (dText, d) in descriptors do - let idx = - lineTxt.IndexOf(dText, ct.Left, tokenSize, StringComparison.OrdinalIgnoreCase) - - if idx > -1 then - let taskLength = 1 + ct.Right - idx - let idxAfterDesc = idx + dText.Length - // A descriptor followed by another letter is not a todocomment, like todoabc. But TODO, TODO2 or TODO: should be. - if idxAfterDesc >= lineTxt.Length || not (Char.IsLetter(lineTxt.[idxAfterDesc])) then - let taskText = lineTxt.Substring(idx, taskLength).TrimEnd([| '*'; ')' |]) - let taskSpan = new TextSpan(line.Span.Start + idx, taskText.Length) - - foundTaskItems.Add(new FSharpTaskListItem(d, taskText, doc, taskSpan)) + for ct in contractedTokens do + + let tokenSize = 1 + (ct.Right - ct.Left) + + for (dText, d) in descriptors do + if tokenSize < 0 || ct.Left >= lineTxt.Length || tokenSize > (lineTxt.Length - ct.Left) then + () + else + let idx = + lineTxt.IndexOf(dText, ct.Left, tokenSize, StringComparison.OrdinalIgnoreCase) + + if idx > -1 then + let taskLength = 1 + ct.Right - idx + let idxAfterDesc = idx + dText.Length + // A descriptor followed by another letter is not a todocomment, like todoabc. But TODO, TODO2 or TODO: should be. + if idxAfterDesc >= lineTxt.Length || not (Char.IsLetter(lineTxt.[idxAfterDesc])) then + let taskText = lineTxt.Substring(idx, taskLength).TrimEnd([| '*'; ')' |]) + let taskSpan = new TextSpan(line.Span.Start + idx, taskText.Length) + + foundTaskItems.Add(new FSharpTaskListItem(d, taskText, doc, taskSpan)) foundTaskItems.ToImmutable() From 27dbeedc2cabd43e51acec7ed093dc6c6d1190bf Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Fri, 12 Jul 2024 18:38:12 +0000 Subject: [PATCH 2/2] Automated command ran: fantomas Co-authored-by: T-Gro <46543583+T-Gro@users.noreply.github.com> --- .../src/FSharp.Editor/TaskList/TaskListService.fs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/vsintegration/src/FSharp.Editor/TaskList/TaskListService.fs b/vsintegration/src/FSharp.Editor/TaskList/TaskListService.fs index 05589ff76ec..a82e414e754 100644 --- a/vsintegration/src/FSharp.Editor/TaskList/TaskListService.fs +++ b/vsintegration/src/FSharp.Editor/TaskList/TaskListService.fs @@ -87,12 +87,17 @@ type internal FSharpTaskListService [] () as this = () else let lineTxt = line.ToString() + for ct in contractedTokens do - + let tokenSize = 1 + (ct.Right - ct.Left) for (dText, d) in descriptors do - if tokenSize < 0 || ct.Left >= lineTxt.Length || tokenSize > (lineTxt.Length - ct.Left) then + if + tokenSize < 0 + || ct.Left >= lineTxt.Length + || tokenSize > (lineTxt.Length - ct.Left) + then () else let idx =