Skip to content

Conversation

@barrettruth
Copy link
Owner

@barrettruth barrettruth commented Feb 5, 2026

When a file has no recognizable extension, filetype detection now falls back to reading file content.

The problem: Files like build (no extension) got no syntax highlighting when expanded in fugitive status, because vim.filetype.match({ filename = "build" }) returns nil without content hints.

The fix: When filename-based detection fails, read the first 10 lines from disk and use vim.filetype.match({ filename, contents }) for content-based detection.

Detection order:

  1. Existing buffer's filetype (from fix(parser): detect filetype from existing buffer #69)
  2. Filename extension
  3. File content on disk (fallback for extensionless files)

This catches shebangs (#!/bin/bash), XML declarations, and other patterns Neovim detects from early file content.

Also:

  • Adds filetype on to test helpers (required for vim.g.ft_ignore_pat which shell detection depends on)

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 barrettruth force-pushed the fix/filetype-from-file-content branch from 0dc8a0e to 33c58c7 Compare February 5, 2026 06:08
@barrettruth barrettruth merged commit 294cbad into main Feb 5, 2026
7 checks passed
@barrettruth barrettruth deleted the fix/filetype-from-file-content branch February 5, 2026 06:13
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.

1 participant