Get Language from file


#1

I am trying to get the language of a file using

atom.workspace.getActiveEditor().getGrammar().scopeName

this works properly giving source.js for javascript.

But for php it gives text.html.php

So is this a bug in the php language?
Also what is the right way to get the language of a file?


#2

That is the correct way to get the currently configured grammar scope of a file. And that is the correct scope for PHP, at least according to the grammar definition.


#3

@leedohm Should it not be something like source.php?


#4

That depends on whether you consider PHP to be a real programming language or a glorified templating language :wink:

All kidding aside, since a file with a .php extension may or may not have HTML in it, it is best to assume that it does have HTML in it and treat it as such. From a grammar perspective anyway.