Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reintroduce header patterns for filetype detection #3208

Merged
merged 12 commits into from
Mar 25, 2024

Commits on Mar 24, 2024

  1. UpdateRules: fix foundDef logic

    The original meaning of foundDef was: "we already found the final syntax
    definition in a user's custom syntax file". After introducing signatures
    its meaning became: "we found some potential syntax definition in a
    user's custom syntax file, but we don't know yet if it's the final one".
    This makes the code confusing and actually buggy.
    
    At least one bug is that if we found some potential filename matches in
    the user's custom syntax files, we don't search for more matches in the
    built-in syntax files. Which is wrong: we should keep searching for as
    many potential matches as possible, in both user's and built-in syntax
    files, to select the best one among them.
    
    Fix that by restoring the original meaning of foundDef and updating the
    logic accordingly.
    dmaluka committed Mar 24, 2024
    Configuration menu
    Copy the full SHA
    1348360 View commit details
    Browse the repository at this point in the history
  2. UpdateRules: don't call highlight.ParseFile() needlessly

    No need to parse a syntax YAML file if we are not going to use it,
    it's a waste of CPU cycles.
    dmaluka committed Mar 24, 2024
    Configuration menu
    Copy the full SHA
    0c923aa View commit details
    Browse the repository at this point in the history
  3. UpdateRules: rename syntaxFiles to fnameMatches

    As a preparation for reintroducing header matches.
    dmaluka committed Mar 24, 2024
    Configuration menu
    Copy the full SHA
    2b8d925 View commit details
    Browse the repository at this point in the history
  4. syntax parser: reintroduce header regex in .hdr files

    Replacing header patterns with signature patterns was a mistake, since
    both have their own uses. So restore support for header regex, while
    keeping support for signature regex as well.
    dmaluka committed Mar 24, 2024
    Configuration menu
    Copy the full SHA
    3f4942c View commit details
    Browse the repository at this point in the history
  5. UpdateRules: reintroduce using header regex for filetype detection

    Replacing header patterns with signature patterns was a mistake, since
    both are quite different from each other, and both have their uses. In
    fact, this caused a serious regression: for such files as shell scripts
    without *.sh extension but with #!/bin/sh inside, filetype detection
    does not work at all anymore.
    
    Since both header and signature patterns are useful, reintroduce support
    for header patterns while keeping support for signature patterns as well
    and make both work nicely together.
    
    Also, unlike in the old implementation (before signatures were
    introduced), ensure that filename matches take precedence over header
    matches, i.e. if there is at least one filename match found, all header
    matches are ignored. This makes the behavior more deterministic and
    prevents previously observed issues like zyedidia#2894 and zyedidia#3054: wrongly
    detected filetypes caused by some overly general header patterns.
    
    Precisely, the new behavior is:
    
    1. if there is at least one filename match, use filename matches only
    2. if there are no filename matches, use header matches
    3. in both cases, try to use signatures to find the best match among
    multiple filename or header matches
    dmaluka committed Mar 24, 2024
    Configuration menu
    Copy the full SHA
    39e410a View commit details
    Browse the repository at this point in the history
  6. Configuration menu
    Copy the full SHA
    6c3b5ad View commit details
    Browse the repository at this point in the history
  7. Configuration menu
    Copy the full SHA
    5492d30 View commit details
    Browse the repository at this point in the history
  8. Restore header instead of signature in most syntax files

    Turning `header` patterns into `signature` patterns in all syntax files
    was a mistake. The two are different things. In almost all syntax files
    those patterns are things like shebangs or <?xml ... ?> or
    <!DOCTYPE html5> i.e. things that:
    
    1. can be (and should be) used for detecting the filetype when there is
       no `filename` match (and that is actually the purpose of those
       patterns, so it's a regression that it doesn't work anymore).
    
    2. should only occur in the first line of the file, not in the first
       100 lines or so.
    
    In other words, the old `header` semantics was exactly what was needed
    for those filetypes, while the new `signature` semantics makes little
    sense for them.
    
    So replace `signature` back with `header` in most syntax files. Keep
    `signature` only in C++ and Objective-C syntax files, for which it was
    actually introduced.
    dmaluka committed Mar 24, 2024
    Configuration menu
    Copy the full SHA
    b2a428f View commit details
    Browse the repository at this point in the history
  9. Configuration menu
    Copy the full SHA
    66a3839 View commit details
    Browse the repository at this point in the history
  10. UpdateRules: rename syntaxFileBuffer to syntaxFileInfo

    To make it more clear. Why Buffer?
    dmaluka committed Mar 24, 2024
    Configuration menu
    Copy the full SHA
    9ee82a6 View commit details
    Browse the repository at this point in the history
  11. UpdateRules: de-densify code arouns signatureMatch

    Purely cosmetic change: make the code a bit more readable by reducing
    its visual "density".
    dmaluka committed Mar 24, 2024
    Configuration menu
    Copy the full SHA
    053949e View commit details
    Browse the repository at this point in the history
  12. Configuration menu
    Copy the full SHA
    1021f61 View commit details
    Browse the repository at this point in the history