Skip to content

fix(intellisense): clamp spell-check start line with Math.max - #407

Open
RobertoReale wants to merge 1 commit into
overleaf-workshop:masterfrom
RobertoReale:fix/spellcheck-negative-line
Open

fix(intellisense): clamp spell-check start line with Math.max#407
RobertoReale wants to merge 1 commit into
overleaf-workshop:masterfrom
RobertoReale:fix/spellcheck-negative-line

Conversation

@RobertoReale

Copy link
Copy Markdown

Fixes #402

Problem

MisspellingCheckProvider computes the first line to re-check as:

const startLine = Math.min(0, event.range.start.line-1);

Math.min(0, x) is always <= 0, so:

  • editing line 0 gives startLine = -1, and the vscode.Range constructor throws Illegal argument: line must be non-negative before validateRange gets a chance to clamp it;
  • editing any other line gives startLine = 0, so the whole document from line 0 up to the edited line is re-checked instead of the intended one line of context.

The handler is an unawaited async callback, so the exception also shows up as rejected promise not handled within 1 second (visible in the logs attached to #194).

Change

Math.minMath.max, which is what the surrounding code intends: one line of context, clamped at the start of the document.

`Math.min(0, line-1)` is always <= 0, so any edit on line 0 (and every edit
whose start line is 0) builds a Range starting at line -1 and VS Code throws
`Illegal argument: line must be non-negative`. The intent is clearly to look
one line back without going below 0, i.e. `Math.max`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Spell check throws "Illegal argument: line must be non-negative" when editing the first line (Math.min instead of Math.max)

1 participant