fix(parser): detect filetype from existing buffer#69
Merged
barrettruth merged 1 commit intomainfrom Feb 5, 2026
Merged
Conversation
Files detected via shebang or modeline (e.g., `build` with `#!/bin/bash`) weren't getting syntax highlighting because `vim.filetype.match()` only does filename-based detection. Now `get_ft_from_filename()` first checks if a buffer already exists for the file and uses its detected filetype. This requires knowing the repo root to construct the full path, so: - `parse_buffer()` reads `b:diffs_repo_root` or `b:git_dir` (fugitive) - `commands.lua` sets `b:diffs_repo_root` on diff buffers it creates Co-authored-by: phanen <phanen@qq.com>
barrettruth
added a commit
that referenced
this pull request
Feb 5, 2026
When a file has no extension but contains a shebang (e.g., `#!/bin/bash`),
filetype detection now reads the first 10 lines from disk and uses
`vim.filetype.match({ filename, contents })` for content-based detection.
This enables syntax highlighting for files like `build` scripts that rely
on shebang detection, even when the file isn't open in a buffer.
Detection order:
1. Existing buffer's filetype (already implemented in #69)
2. File content (shebang/modeline) - NEW
3. Filename extension only
Also adds `filetype on` to test helpers to ensure `vim.g.ft_ignore_pat`
is set, which is required for shell detection.
barrettruth
added a commit
that referenced
this pull request
Feb 5, 2026
When a file has no extension but contains a shebang (e.g., `#!/bin/bash`),
filetype detection now reads the first 10 lines from disk and uses
`vim.filetype.match({ filename, contents })` for content-based detection.
This enables syntax highlighting for files like `build` scripts that rely
on shebang detection, even when the file isn't open in a buffer.
Detection order:
1. Existing buffer's filetype (already implemented in #69)
2. File content (shebang/modeline) - NEW
3. Filename extension only
Also adds `filetype on` to test helpers to ensure `vim.g.ft_ignore_pat`
is set, which is required for shell detection.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Files detected via shebang or modeline (e.g.,
buildwith#!/bin/bash) weren't getting syntax highlighting in diffs becausevim.filetype.match({ filename = ... })only does filename-based detection.Repro:
sh/bash):G, expand the diffCloses #63
Thanks to @phanen for identifying this issue.