Skip to content

Fix language injections sticking after language comment removed#46134

Merged
JosephTLyons merged 8 commits intozed-industries:mainfrom
jeffbrennan:fix/sync-language-injection-comment
Jan 27, 2026
Merged

Fix language injections sticking after language comment removed#46134
JosephTLyons merged 8 commits intozed-industries:mainfrom
jeffbrennan:fix/sync-language-injection-comment

Conversation

@jeffbrennan
Copy link
Contributor

@jeffbrennan jeffbrennan commented Jan 6, 2026

Closes #46104

Release Notes:

  • Fixed language injections sticking after language comment removed

This is working well for the Python SQL comments
comment_sync_demo

from pyspark.sql import SparkSession
spark = SparkSession.builder.getOrCreate()

# sql
cmd = "SELECT col1, col2 FROM tbl"

df = spark.sql(  # sql
    """
    WITH cte AS (
        SELECT col1, col2, COUNT(*) AS n
        FROM tbl
        GROUP BY ALL
    )
    SELECT * FROM cte
    """
)

And go comments
comment_sync_demo_go_updated

package main

func test() {
    var _ = /* sql */ `SELECT id, name FROM products`
    var _ = /* sql */ "SELECT id, name FROM products"

    var _ = /* sql */ `SELECT id, name FROM products`

    var _ = /* sql*/ "SELECT id, name FROM products"
}

Note: f04b252dd9 was a simpler implementation that worked for non-inline comments in Python, but produced the following Go behavior
comment_sync_demo_go

@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Jan 6, 2026
@jeffbrennan jeffbrennan marked this pull request as ready for review January 6, 2026 03:51
@jeffbrennan
Copy link
Contributor Author

@JosephTLyons - got this working! Thanks for the issue

@zed-industries-bot
Copy link
Contributor

zed-industries-bot commented Jan 6, 2026

Warnings
⚠️

This PR is missing release notes.

Please add a "Release Notes" section that describes the change:

Release Notes:

- Added/Fixed/Improved ...

If your change is not user-facing, you can use "N/A" for the entry:

Release Notes:

- N/A

Generated by 🚫 dangerJS against b03cb48

@jeffbrennan
Copy link
Contributor Author

Apologies for the test failures, all tests are now passing locally.
image

Tests that SQL injection is properly activated when completing a #sql
comment and deactivated when removing the 'l' to make it #sq again.

This verifies the fix for zed-industries#46104 where SQL highlighting persisted after
removing the #sql comment.
@JosephTLyons
Copy link
Collaborator

JosephTLyons commented Jan 27, 2026

Hey @jeffbrennan, sorry for the slowness here.

I added a test to pin down the behavior by simulating:

  1. Starting with #sq comment above a SQL string
  2. Ensuring we don't have any unknown injections (since #sq doesn't match the injection pattern)
  3. Adding l to complete #sql
  4. Ensuring we now have an unknown injection (SQL is triggered but not registered)
  5. Removing l to go back to #sq
  6. Ensuring we no longer have any unknown injections

It's a little awkward since SQL isn't shipped with Zed, so I'm just asking "do we now have unknown injections" whenever we have a full #sql comment. The test also registers a mock "comment" language since Python's injection queries request a language named "comment" for all comments - otherwise every comment would trigger unknown injections.

@JosephTLyons JosephTLyons enabled auto-merge (squash) January 27, 2026 17:23
@JosephTLyons JosephTLyons merged commit 797ad8c into zed-industries:main Jan 27, 2026
26 checks passed
@JosephTLyons
Copy link
Collaborator

/cherry-pick preview

github-actions bot pushed a commit that referenced this pull request Jan 27, 2026
Closes #46104

Release Notes: 

- Fixed language injections sticking after language comment removed

---

This is working well for the Python SQL comments

![comment_sync_demo](https://github.com/user-attachments/assets/ba5160ce-4867-4b49-9f44-141ddc2730a1)

```python
from pyspark.sql import SparkSession
spark = SparkSession.builder.getOrCreate()

# sql
cmd = "SELECT col1, col2 FROM tbl"

df = spark.sql(  # sql
    """
    WITH cte AS (
        SELECT col1, col2, COUNT(*) AS n
        FROM tbl
        GROUP BY ALL
    )
    SELECT * FROM cte
    """
)
```


And go comments

![comment_sync_demo_go_updated](https://github.com/user-attachments/assets/73e81a94-e8fc-4dc3-82f8-09e966d35bc9)


```go
package main

func test() {
    var _ = /* sql */ `SELECT id, name FROM products`
    var _ = /* sql */ "SELECT id, name FROM products"

    var _ = /* sql */ `SELECT id, name FROM products`

    var _ = /* sql*/ "SELECT id, name FROM products"
}
```

Note: `f04b252dd9` was a simpler implementation that worked for
non-inline comments in Python, but produced the following Go behavior

![comment_sync_demo_go](https://github.com/user-attachments/assets/40336705-9799-4b0a-b457-4974d172e1c8)

---------

Co-authored-by: Joseph T. Lyons <JosephTLyons@gmail.com>
@JosephTLyons JosephTLyons self-requested a review January 27, 2026 17:42
JosephTLyons added a commit that referenced this pull request Jan 27, 2026
…) (cherry-pick to preview) (#47790)

Cherry-pick of #46134 to preview

----
Closes #46104

Release Notes: 

- Fixed language injections sticking after language comment removed

---

This is working well for the Python SQL comments


![comment_sync_demo](https://github.com/user-attachments/assets/ba5160ce-4867-4b49-9f44-141ddc2730a1)

```python
from pyspark.sql import SparkSession
spark = SparkSession.builder.getOrCreate()

# sql
cmd = "SELECT col1, col2 FROM tbl"

df = spark.sql(  # sql
    """
    WITH cte AS (
        SELECT col1, col2, COUNT(*) AS n
        FROM tbl
        GROUP BY ALL
    )
    SELECT * FROM cte
    """
)
```


And go comments


![comment_sync_demo_go_updated](https://github.com/user-attachments/assets/73e81a94-e8fc-4dc3-82f8-09e966d35bc9)


```go
package main

func test() {
    var _ = /* sql */ `SELECT id, name FROM products`
    var _ = /* sql */ "SELECT id, name FROM products"

    var _ = /* sql */ `SELECT id, name FROM products`

    var _ = /* sql*/ "SELECT id, name FROM products"
}
```

Note: `f04b252dd9` was a simpler implementation that worked for
non-inline comments in Python, but produced the following Go behavior


![comment_sync_demo_go](https://github.com/user-attachments/assets/40336705-9799-4b0a-b457-4974d172e1c8)

---------

Co-authored-by: Joseph T. Lyons <JosephTLyons@gmail.com>

Co-authored-by: Jeff Brennan <42007840+jeffbrennan@users.noreply.github.com>
Co-authored-by: Joseph T. Lyons <JosephTLyons@gmail.com>
naaiyy added a commit to Glass-HQ/Glass that referenced this pull request Feb 16, 2026
Key changes:
- Version bump v0.223
- Bold folder labels setting (zed-industries#47631) for project panel
- min_size/max_size style methods in GPUI (zed-industries#47775)
- Emoji typing fix (zed-industries#47835)
- Heap allocation reductions in GPUI (zed-industries#47858)
- Git graph: feature graph support (zed-industries#47861)
- Editor: select to start/end of larger syntax node (zed-industries#47571)
- Scroll position persistence moved to background with debounce (zed-industries#47834)
- Markdown: improved double-click word selection (zed-industries#47844)
- Language injections fix (zed-industries#46134)
- SharedString::new_static for string literals (zed-industries#47865)
- ACP registry improvements and agent deprecation banners

Conflict resolutions:
- Kept our version (0.0.1), not upstream's 0.223.0
- Removed vim settings from default.json, settings_content, settings_ui
- Took upstream's bold_folder_labels in project panel
- Removed deleted crate files (gpui, vim, util)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed The user has signed the Contributor License Agreement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Highlighting for SQL injections in Python are not removed when comments are removed

4 participants