How to recognise file name for syntax highlighting


I am trying to write a grammar file and am struggling to get Atom to recognise a file name structure where the “extension” is actually before the full-stop.
For my language, file names follow a convention or Foo.program i.e all filenames are prefixed with Foo. How do I specify this? I have tried the following and it doesn’t work:

'scopeName': 'source.singularity'
'name': 'Singularity'
'fileTypes': ['Singularity']


While using naming conventions to determine the file-type has always been a dumb idea, it has historical reasons. I wonder why anyone would think it to be a good idea to break with that concept. But let’s stay on topic.

From what I can tell, you cannot use RegEx for fileType matches. However, it lets you specify full file-names, even though this has limitations (e.g. some.file.type also matches the type file.type). So, if your prefix never changes, you could simply provide, Foo.program...

But I guess it’s not that simple.

I haven’t tested this, but you could try omitting the fileType altogether and programmatically set the grammar using in the onDidOpen event. Match whether the file-name fits the structure, then set the grammar:

const editor = atom.workspace.getActiveTextEditor();
const grammar = atom.grammars.grammarForScopeName('source.singularity');


Note: the Atom blog mentions that “the existing APIs that deal with configuring a grammar on an editor are being altered.”


Thanks for your help.
Excuse my ignorance but I have zero experience with Atom packages.
Where would I put that code snippet you added?
If that is too long a story would you be able to point me to somewhere I can figure this out?


Your package should have a main file cited in your package.json, like in this one. In that main file, you will export a number of functions. Inside the activate() function, you can put code to be run or define commands that point at other functions in your package. In this case, you want activate() to contain an atom.workspace.onDidOpen() instruction that either contains the grammar-setting logic or calls a function to do the same thing.