Packages: File named "build" always opens as "NAnt Build FIle" type

Created on 2 Feb 2019  路  4Comments  路  Source: sublimehq/Packages

How to reproduce:
Create file named "build", put anything into it, eg. #!/bin/bash, and then save it.
Closing and opening the file switches to "NAnt Build File", also on Sidebar file is wrongly detected.

Most helpful comment

All 4 comments

  1. The _NAnt Build File_ is defined in C#/Build.sublime-syntax.
  2. This syntax is associated with the _build_ file extension.
  3. ST uses file extensions to choose the syntax first. If none matches, the first_line_match rule is used. That's why the shebang is ignored.
  4. ST uses the last part of a file path as "extension", which means it matches both _foo.build_ and _build_. We could argue about a file named _build_ is to be a file extension, but changing the behavior would break syntax assignment for files like _.gitignore_.

With that said this issue is not related with the _Default Packages_ and can not be fixed in the syntax defintions without changing ST core behavior.

A backward compatible solution would probably be to introduce a new file_pattern context which was used instead of file_extensions if exists. It would then need to support simple file patterns.

file_patterns:
  - *.build     // file extension
  - build       // file name

FWIW, I use ApplySyntax for more fine-grained control until things like @deathaxe's wish are implemented. Here's the main problem I use it for:

  • ~/.ssh/config
  • ~/projects/foo/.git/config

Both files have the same filename. Neither one has a shebang or other guaranteed first line stuff. How do you distinguish them? Even with @deathaxe's system, can the patterns test the full path?

Even ApplySyntax comes with a caveat: I have to disable its default rules by setting default_syntaxes: [] to avoid interfering with the PackageDev-defined languages for special XML files (.tmPreferences, etc.).

As a side note, I'm not sure build is a specific enough extension to justify having it opened with the C++ build system thingy by default. Meson, for example, also uses the .build extension, though that is always written as meson.build.
Can you think of other examples?

Was this page helpful?
0 / 5 - 0 ratings