You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
id(web): detectLanguage lets a special-name stem override a known extension — justfile.rs highlights as Just, makefile.md as Makefile #721
detectLanguage in pkgs/id/web/src/highlight.ts checks the file's stem against the special-filename table before it ever looks at the extension, so any file whose stem happens to be a special name is highlighted with the wrong language even when its extension unambiguously names another one.
Evidence (verified on main df38365, temporary vitest probe since removed)
highlight.ts:133-143 computes nameWithoutExt (basename minus its final extension) and returns FILENAME_TO_LANG[nameWithoutExt] before the extension lookup at highlight.ts:158-162.
Probe results against the real function:
filename
returned
correct
justfile.rs
just
rust
makefile.md
makefile
markdown
dockerfile.py
dockerfile
python
gemfile.json
ruby
json
vagrantfile.toml
ruby
toml
cmakelists.rs
cmake
rust
rakefile.ts
ruby
typescript
Controls that must keep working:
filename
returned
correct
Dockerfile.dev
dockerfile
dockerfile (extension unknown)
CMakeLists.txt
cmake
cmake (.txt has no language)
src/Dockerfile
dockerfile
dockerfile (no extension)
Why it matters
The editor picks the Shiki grammar solely from this function (filename-detected language, highlight.tscreateSyntaxHighlightPlugin). A mis-detected file is highlighted with a completely unrelated grammar — e.g. documentation about a Makefile (makefile.md) or a Rust source file named after the tool it drives (justfile.rs). The special-name rule was only ever meant for files that are the special file (Dockerfile, Makefile, CMakeLists.txt, Dockerfile.dev); it should not override a known extension.
Acceptance criteria
When the basename's extension is present in EXT_TO_LANG, the extension wins over the stem special-name match (justfile.rs → rust, makefile.md → markdown, gemfile.json → json).
Special filenames still win when there is no extension (Dockerfile, Gemfile, src/Makefile) or the extension is unknown (Dockerfile.dev, CMakeLists.txt).
Dotfile handling (.env, .gitignore, .env.local, …) is unchanged.
New regression tests in highlight.test.ts cover at least the stem-vs-known-extension cases and the unknown-extension controls above; the existing detectLanguage suite passes unchanged.
Activity
Merge pull request #722 from developing-today/creator/721-detect-lang…