Pranomvignesh / extend-monaco-language-tokenizer

This project is about to explain a method to extend the present language configuration in monaco editor

Home Page:https://monaco-editor-extend-lang-conf.vercel.app

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to extend JSON language ?

vikyd opened this issue · comments

JSON language has no loader function.

@vikyd I think you can use semantic tokens provider API from monaco editor
This API is available from version 0.21.0 of monaco editor.
You can tweak this example from playground to make it work for JSON

Only highlight by tokens provider is not enough.

I also want to make it format correctly.

Example, this my input JSON string:

{
  "a": {{myName}}
}

I want to highlight {{myName}}.

And I also want to format the JSON string.

Expected:

{
  "a": {{myName}}
}

But actually, it become:

{
      "a": {
            {myName
            }
      }
}

@vikyd This package is indented to extend the tokenizer to add custom syntax highlighting only.
And this package will work only if there is a loader method present for the particular language.

For adding custom formatting there are APIs like registerOnTypeFormattingEditProvider, DocumentRangeFormattingEditProvider

A little exploration in monaco editor documentation will help you achieve your case