Language data not being recognized on custom Language

I have a custom language that I’m adding CodeMirror support for. I’ve subclassed Parser and am providing my own Parser (called ParserAdapter); I’m trying to add support for comments to my language:

const parserAdapter = new ParserAdapter();
const facet = defineLanguageFacet({
  commentTokens: { block: { open: "/*", close: "*/" } },

const language = new Language(facet, parserAdapter, []);

export const myLang = new LanguageSupport(language, [syntaxHighlight]);

I have been trying a variety of approaches but no matter what I seem to do, I can’t seem to get comment toggling via the default keymap working. Is my approach for defining language data incorrect?

(you can see the whole source here)

Does state.languageDataAt("commentTokens", 0) return anything in an editor with this language? Also, have you verified that your dependency tree is deduplicated and isn’t loading any library package twice?

When I log out state.languageDataAt("commentTokens", 0), it shows that it’s an empty array.

As far as the dependency duplcation–I had 6.6.0 and 6.0.0 referenced in various parts of my yarn.lock file. I downgraded the 6.6.0 to 6.0.0 (so now I only see 6.0.0 for the language package), but I still see the same output. From what I can tell, I only have a single version of the language package installed (there is only a single entry in my yarn.lock file and in my node_modules folder).

Should I be managing dependencies in a particular way with codemirror packges? Do I need to provide custom resolutions or anything like that?

When you clear your package lock and fully recreate it, npm is pretty good about deduplicating the whole tree and installing up-to-date packages. Any other operation that upgrades packages seems to risk creating weird duplications.

When you clear your package lock and fully recreate it, npm is pretty good about deduplicating the whole tree and installing up-to-date packages

Got it–I took the step of removing my lock file and recreating it, still seeing any empty array for state.languageDataAt("commentTokens", 0).

On closer look, it looks you’re not using languageDataProp to associate the language facet with your top node type, since that code never feeds that back to the parser.

Interesting–I saw that in the docs when trying to solve this but I wasn’t sure how to use that. Is this something I should be doing as an extension of creating my NodeSet (via NodeProp.add)? I had originally assumed that passing the facet in to Language() would attach the facet to the top node for me, but it appears that I need to do that myself?

Yes, you do need to do that (since a Language doesn’t know how to change a Parser). Passing in the prop, either with add or as a two-element array holding the node prop and the facet, when creating the node type should help.

Got it–I was able to get this working with the following code:

const topNode = NodeType.define({
  id: 0,
  name: "topNode",
  top: true,
  props: [
        commentTokens: { block: { open: "/*", close: "*/" }, line: "//" },

Thank you for your help!