# Language data not being recognized on custom Language

**URL:** https://discuss.codemirror.net/t/language-data-not-being-recognized-on-custom-language/6310
**Category:** v6
**Created:** [April 17, 2023, 9:35pm UTC](https://discuss.codemirror.net/t/language-data-not-being-recognized-on-custom-language/6310 "2023-04-17T21:35:18Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![thetrevorharmon](https://discuss.codemirror.net/user_avatar/discuss.codemirror.net/thetrevorharmon/32/2221_2.png) [@thetrevorharmon](https://discuss.codemirror.net/u/thetrevorharmon)
#### Post date: [April 17, 2023, 9:35pm UTC](https://discuss.codemirror.net/t/language-data-not-being-recognized-on-custom-language/6310/1 "2023-04-17T21:35:18Z")

</div>

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:

```ts
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](https://github.com/thetrevorharmon/zephyr-demo/blob/main/src/extensions/zephyr/zephyr.ts))

---

<div class="post-metadata">

### Author: ![marijn](https://discuss.codemirror.net/user_avatar/discuss.codemirror.net/marijn/32/136_2.png) [@marijn](https://discuss.codemirror.net/u/marijn)
#### Post date: [April 18, 2023, 6:49am UTC](https://discuss.codemirror.net/t/language-data-not-being-recognized-on-custom-language/6310/2 "2023-04-18T06:49:36Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![thetrevorharmon](https://discuss.codemirror.net/user_avatar/discuss.codemirror.net/thetrevorharmon/32/2221_2.png) [@thetrevorharmon](https://discuss.codemirror.net/u/thetrevorharmon)
#### Post date: [April 18, 2023, 12:06pm UTC](https://discuss.codemirror.net/t/language-data-not-being-recognized-on-custom-language/6310/3 "2023-04-18T12:06:42Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![marijn](https://discuss.codemirror.net/user_avatar/discuss.codemirror.net/marijn/32/136_2.png) [@marijn](https://discuss.codemirror.net/u/marijn)
#### Post date: [April 18, 2023, 1:05pm UTC](https://discuss.codemirror.net/t/language-data-not-being-recognized-on-custom-language/6310/4 "2023-04-18T13:05:49Z")

</div>

> [@thetrevorharmon](#):
>
> 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.

---

<div class="post-metadata">

### Author: ![thetrevorharmon](https://discuss.codemirror.net/user_avatar/discuss.codemirror.net/thetrevorharmon/32/2221_2.png) [@thetrevorharmon](https://discuss.codemirror.net/u/thetrevorharmon)
#### Post date: [April 18, 2023, 1:19pm UTC](https://discuss.codemirror.net/t/language-data-not-being-recognized-on-custom-language/6310/5 "2023-04-18T13:19:22Z")

</div>

> 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)`.

---

<div class="post-metadata">

### Author: ![marijn](https://discuss.codemirror.net/user_avatar/discuss.codemirror.net/marijn/32/136_2.png) [@marijn](https://discuss.codemirror.net/u/marijn)
#### Post date: [April 18, 2023, 1:41pm UTC](https://discuss.codemirror.net/t/language-data-not-being-recognized-on-custom-language/6310/6 "2023-04-18T13:41:07Z")

</div>

On closer look, it looks you’re not using [`languageDataProp`](https://codemirror.net/docs/ref/#language.languageDataProp) to associate the language facet with your top node type, since that code never feeds that back to the parser.

---

<div class="post-metadata">

### Author: ![thetrevorharmon](https://discuss.codemirror.net/user_avatar/discuss.codemirror.net/thetrevorharmon/32/2221_2.png) [@thetrevorharmon](https://discuss.codemirror.net/u/thetrevorharmon)
#### Post date: [April 18, 2023, 2:00pm UTC](https://discuss.codemirror.net/t/language-data-not-being-recognized-on-custom-language/6310/7 "2023-04-18T14:00:19Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![marijn](https://discuss.codemirror.net/user_avatar/discuss.codemirror.net/marijn/32/136_2.png) [@marijn](https://discuss.codemirror.net/u/marijn)
#### Post date: [April 18, 2023, 2:21pm UTC](https://discuss.codemirror.net/t/language-data-not-being-recognized-on-custom-language/6310/8 "2023-04-18T14:21:12Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![thetrevorharmon](https://discuss.codemirror.net/user_avatar/discuss.codemirror.net/thetrevorharmon/32/2221_2.png) [@thetrevorharmon](https://discuss.codemirror.net/u/thetrevorharmon)
#### Post date: [April 18, 2023, 3:04pm UTC](https://discuss.codemirror.net/t/language-data-not-being-recognized-on-custom-language/6310/9 "2023-04-18T15:04:36Z")

</div>

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

```ts
const topNode = NodeType.define({
  id: 0,
  name: "topNode",
  top: true,
  props: [
    [
      languageDataProp,
      defineLanguageFacet({
        commentTokens: { block: { open: "/*", close: "*/" }, line: "//" },
      }),
    ],
  ],
});

```

Thank you for your help!

---

<div class="post-metadata">

### Author: ![prettykingking](https://discuss.codemirror.net/user_avatar/discuss.codemirror.net/prettykingking/32/5329_2.png) [@prettykingking](https://discuss.codemirror.net/u/prettykingking)
#### Post date: [October 28, 2025, 11:19am UTC](https://discuss.codemirror.net/t/language-data-not-being-recognized-on-custom-language/6310/10 "2025-10-28T11:19:54Z")

</div>

Language parses. But it does not get parsed in editor. This troubles me for a while until I found your answer. Clear package lock file and package cache, after that re-init project and everything works fine.
