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

VS plugin Bugfix :: Defensive checks added to prevent TaskListService crashes #17411

Merged
merged 7 commits into from
Aug 15, 2024
42 changes: 27 additions & 15 deletions vsintegration/src/FSharp.Editor/TaskList/TaskListService.fs
Original file line number Diff line number Diff line change
Expand Up @@ -83,23 +83,35 @@ type internal FSharpTaskListService [<ImportingConstructor>] () 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()

Expand Down
Loading