Function this.registry.startIdForScope is not a function


#1

There is an issue with my atom-tasks package not loading in 1.24 in regards to custom grammars being set. However, just from the stack traces (and testing the package itself) I can’t really tell what’s going on.

There are two other packages with the same issue:


Any thoughts? Anybody know what’s going on? Thanks!


#2

According to the stack trace, tasks.coffee:125 is the last line of your package that executes before the error. Given that, I would first look to see if something about atom.grammars.addGrammar() has changed. However, I also noticed that the Grammar documentation specifically instructs, “This class should not be instantiated directly but instead obtained from a GrammarRegistry by calling GrammarRegistry::loadGrammar.” Based on a cursory examination of Atom’s grammar.coffee file, my conjecture is that Atom’s grammar registry logic calls functions outside of the Grammar class when building a new instance of the class. You could try to emulate this, or you could use atom.grammars.loadGrammar() to tell Atom to generate a new Grammar from your file. This will automatically add it to the registry, and I can confirm that it works as I use the following init.coffee code to rapidly prototype new grammars:

atom.commands.add 'atom-text-editor', 'custom:load-active-editor-as-grammar', ->
    editor = atom.workspace.getActiveTextEditor()
    atom.grammars.loadGrammarSync(editor.getPath())

#3

Indeed!

I’ve just replaced the line:
newG = new Grammar atom.grammars, g
with:
newG = atom.grammars.readGrammarSync(__dirname + ‘/tasks.cson’)

… and, apparently, based on your excelent overview, it works nicely.

@irrationalistic, can you commit this change (after testing, and seeing that this makes some sense), please?

P.S.: never worked with the Atom “guts” before, that’s a first =)
P.S. #2: never worked with coffescript, also a first =) =)

Thanks!


#4

Sorry, i forgot to mention the file that was changed: it was the file “tasks.coffee”.


#5

Thanks for giving this a shot! Unfortunately, the main reason I’m doing this creation of a new grammar is that the grammar itself is dynamic based on the settings the user has set, so I can’t just load and apply the grammar directly without processing :frowning:


#6

I’ll take a look at the grammar registry internals to see if there’s anything relevant. I can’t do loading grammars directly from file unless i’m also dynamically writing to a file based on the user settings, which feels fragile. It’s possible i’m just missing some custom values or additional information along the way :slight_smile: I’ll update as I dig in!


#7

No problem! I’m in that classic cornercase: “works for me” (at least,
I’m able to use my .TODO files as I always did) =)

Great package, by the way!

Cheers!

Att,
Wolff


#8

I haven’t looked much into your package, but how is that much different from how Atom stores all of its settings? The .atom/ folder is a great storage place for files like that.


#9

:open_mouth: that’s a really interesting idea! Is there an API for writing files to that directory? Whenever you change settings I could re-write a grammar to that location and then just simply load it back up…


#10

There’s an API for writing files to anywhere, and an environment variable ATOM_HOME which contains the location of the .atom/ folder.


#11

I’m also in favor of writing to a permanent-but-expendable file because it can be a huge help when debugging by allowing a user to take a look at the last state of the package without interacting with it.


#12

Definitely! I’m writing to a TaskGrammar.cson file in the home directory, which i’ll initialize from settings on activation and then update whenever the settings change.


#13

Just posted an updated version of the plugin that reads from and writes to a custom grammar file. Thanks for the great suggestions @DamnedScholar! Super helpful :smiley:


#14

No problem. I’m happy that my oddly specific knowledge of Atom’s grammar system can make someone else’s life easier. :slight_smile: