getGrammars() ignores tree-sitter grammars


Tree-sitter grammars will not be returned by the getGrammars() function of a GrammarRegistry. Instead, only TextMate grammars are returned.

  // Extended: Get all the grammars in this registry.
  // Returns a non-empty {Array} of {Grammar} instances.
  getGrammars () {
    return this.textmateRegistry.getGrammars()

This causes issues with the grammar-selector package, which uses that function to build the list of available grammars. All tree-sitter grammars will be hidden from it.

Interestingly, if a regex grammar has the same name value as a tree-sitter one, then the regex grammar will appear in the list, but selecting it will apply the tree-sitter grammar

This can be seen by selecting Python, and noticing the green tick mark is not applied to it when you reopen the menu (in contrast to a solely regex grammar, with no tree-sitter alternative).

Steps to Reproduce

  1. Open the grammar menu and select Python
  2. Open the grammar menu and look at the Python entry; there is no tick mark
  3. Select Python Console (or any other regex-only grammar)
  4. Open the grammar menu and see the tick mark next to Python Console

Alternatively, a grammar that is solely tree-sitter based will not appear at all in the selection menu, but will be automatically applied when the right file type is opened.

Expected behavior: [What you expect to happen]

Tick next to Python because it was selected

Actual behavior: [What actually happens]

No tick, because we were actually selecting the regex gramar and the tree-sitter one “intercepted” it as it was being applied. So the result is that the regex grammar was not applied, and so no tick mark.

Reproduces how often:


apm  1.19.0
npm  3.10.10
node 6.9.5 x64
atom 1.26.0-beta0
python 2.7.10
git 2.14.3

Atom    : 1.26.0-beta0
Electron: 1.7.11
Chrome  : 58.0.3029.110
Node    : 7.9.0

macOS 10.13.3

1 possible answer(s) on “getGrammars() ignores tree-sitter grammars

  1. @ashthespy @jakofranko While my PR is being finished, adding the following to your init.js file should allow you to see TS grammars (or you can translate to CoffeeScript for

    atom.grammars.getGrammars = () => {
      return [...atom.grammars.textmateRegistry.getGrammars(), ...Object.values(atom.grammars.treeSitterGrammarsById)]

    It will show apparent duplicates for lots of languages, so you might want to filter out TextMate grammars with the same name.