Skip to content

feat(syntax): detect languages from shebangs - #360

Merged
fcoury merged 2 commits into
mainfrom
fcoury/shebang-detection
Sep 5, 2026
Merged

feat(syntax): detect languages from shebangs#360
fcoury merged 2 commits into
mainfrom
fcoury/shebang-detection

Conversation

@fcoury-oai

Copy link
Copy Markdown
Collaborator

Extensionless scripts currently have no automatic syntax selection even when their first line names an interpreter. This change detects languages from shebangs after existing filename and extension associations, so a file named script beginning with #!/usr/bin/env -S bash -eu gets Bash highlighting and syntax-aware editing.

Adds configurable languages.<id>.shebangs, bounded first-line detection, common env forms and numeric interpreter versions. Editor buffers, eligible previews, and diff sides use the same detector; edits and language reloads refresh the selected syntax. Manual syntax selection retains precedence. Zsh continues to use the bundled Bash grammar. LSP routing remains filename-based; quoted commands and arbitrary wrappers are outside this parser's scope.

Python pack interpreter metadata is a separate follow-up in codersauce/red-language-packs; this PR provides the detector and configuration support it needs.

How to Test

  1. Create an extensionless file containing #!/usr/bin/env -S bash -eu followed by if true; then echo hello; fi. Open it with this build: Bash syntax should be highlighted without setting executable permissions. Scroll below the first line and confirm highlighting persists.
  2. Change the shebang to an unknown interpreter: automatic highlighting should disappear. Use :syntax fish and then :syntax off to verify manual selection and disabling. A recognized .rs filename must still select Rust even with a Bash shebang.
  3. Run cargo test --lib shebang: all five tests should pass, covering detection, registered interpreters, live reload, offscreen edits, manual selection, and preview cache invalidation.

Validated locally: the five shebang tests, 70 highlighter tests (cargo test --lib highlighter::tests), two preview tests (cargo test --lib preview_syntax_highlighting), formatting, and cargo clippy --all-targets --all-features -- -D warnings. The interactive steps above are reviewer instructions, not a claimed manual smoke test.

@fcoury

fcoury commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 5, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-05T02:53:58.958171Z 6f1a133 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6f1a1337c6

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/highlighter.rs Outdated
@fcoury
fcoury merged commit b17d014 into main Sep 5, 2026
16 checks passed
@fcoury
fcoury deleted the fcoury/shebang-detection branch September 5, 2026 03:09
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.

2 participants