Skip to content

fix: don't crash when switching languages with an ESQuery selector - #608

Open
Pixel998 wants to merge 1 commit into
mainfrom
fix/esquery-language-switch-crash
Open

Pixel998 wants to merge 1 commit into
mainfrom
fix/esquery-language-switch-crash

Conversation

@Pixel998

@Pixel998 Pixel998 commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Prerequisites checklist

AI acknowledgment

  • I did not use AI to generate this PR.
  • (If the above is not checked) I have reviewed the AI-generated content before submitting.

What is the purpose of this pull request?

This PR fixes a crash in the editor's ESQuery highlighting when switching languages while an ESQuery selector is set.

Steps to reproduce

  1. Type Literal in the ESQuery Selector.
  2. Switch the language to JSON.
  3. Switch the language back to JavaScript.
  4. Notice CodeMirror plugin crashed: RangeError: Position 749 is out of range for changeset of length 603 in the browser console, and that the highlights are gone.

What changes did you make? (Give an overview)

Made highlightedRangesExtension take the code the ranges were computed for, and only create the decorations once the editor contains that code.

Related Issues

Is there anything you'd like reviewers to focus on?

Summary by CodeRabbit

  • Bug Fixes
    • Highlighting now stays in sync with the editor’s current content when switching languages. Highlights reappear when returning to code that matches the highlighted content, avoiding stale or misplaced highlights.

@eslintbot eslintbot added this to Triage Oct 29, 2026
@eslint-github-bot eslint-github-bot Bot added the bug Something isn't working label Oct 29, 2026
@github-project-automation github-project-automation Bot moved this to Needs Triage in Triage Oct 29, 2026
@netlify

netlify Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for eslint-code-explorer ready!

Name Link
🔨 Latest commit 2b9aa25
🔍 Latest deploy log https://app.netlify.com/projects/eslint-code-explorer/deploys/6ae2ac8c59262820451f48d0
😎 Deploy Preview https://deploy-preview-608--eslint-code-explorer.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@coderabbitai

coderabbitai Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Central YAML; Path: .coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: ae217097-949e-4b20-9820-db76da32a45b
Commits

Reviewing files that changed from the base of the PR and between 84c4797 and 2b9aa25.

Files selected for processing: 3
  • e2e-tests/code-editing-and-ast-interaction.test.ts
  • src/components/editor.tsx
  • src/utils/highlighted-ranges.ts

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

Walkthrough

The editor now pairs highlight ranges with source code. The decoration extension checks that the editor document matches that code before creating decorations. An end-to-end test checks highlighting when switching between JavaScript and JSON.

Changes: Editor highlighting

Layer / File(s) Summary
Code-matched highlight decorations
src/utils/highlighted-ranges.ts
highlightedRangesExtension now accepts source code and creates decorations only when the document matches it. It maps existing decorations through document changes, or creates them when the updated document matches the source code.
Editor integration and language-switch test
src/components/editor.tsx, e2e-tests/code-editing-and-ast-interaction.test.ts
EditorProperties.value is required. The editor passes its current value to the extension and recomputes extensions when the value changes. The end-to-end test checks highlighting after switching languages and asserts that no console errors were recorded.

Priority: Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Possibly related PRs

  • eslint/code-explorer#594: Changes how the editor receives highlight ranges and source code, which is the data paired by this change.

Suggested reviewers: patricktree

Merge Risk: Minimal · up to 2b9aa

Highlights are guarded against mismatched editor text. No material merge risk was identified.

Pre-merge checks: Passed 5
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the main change: a crash fix when switching languages while an ESQuery selector is set. The raw summary and PR objectives confirm that highlightedRangesExtension now receives the sourc…
Docstring Coverage Passed No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: a crash fix when switching languages while an ESQuery selector is set. The raw summary and PR objectives confirm that highlightedRangesExtension now receives the source code and creates decorations only when the editor contains that code. The title is specific and matches the changeset.

Full details: Docstring Coverage

Explanation

No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 0 functions across 3 files.

Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@Pixel998 Pixel998 moved this from Needs Triage to Implementing in Triage Oct 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

Status: Implementing

Development

Successfully merging this pull request may close these issues.

1 participant