To add a language to Code Explorer, follow these steps.
Add an SVG logo into the public/languages/ directory.
- Update the
Languagetype to contain an entry for the new language. - Create a new mode variable that defines the primary parsing mode (such as
jsonModeorcssMode). - Update the
Codetype to include an entry for the new language. - Create a new options variable that defines the options for the new language (such as
JsonOptionsorCssOptions). - Update the
ExplorerStatetype to include getters and setters for the new language's language options. - Update the
useExplorervariable to include the default options for the new language.
- Import the type for the new language options from
src/hooks/use-explorer.ts. - Add an entry in the
languagesvariable for the new language. - Export a new variable describing the available modes for the new language (such as
jsonModesorcssModes). - Default the default code for the new language (such as
defaultJsonCodeordefaultCssCode). - Add an entry in the
defaultCodevariable for the new language's default code. - Export a variable containing the default options for the new language (such as
defaultJsonOptionsordefaultCssOptions). - Add an entry to the
esquerySelectorPlaceholderconstant for the new language(must match Language enum), using an appropriate example selector.
Now import the default options for the new language from src/lib/const.ts.
- Import the new language mode type from
src/hooks/use-explorer(such asJsonModeorCssMode). - Import the available modes for the new language from
src/hooks/const(such asjsonModesorcssModes). - Create an options panel for the new language (such as
JsonPanelorCssPanel). - Update the
Panelvariable to use the new options panel.
- Install the appropriate CodeMirror plugin for the new language.
- Update the
languageExtensionsvariable to include the new language CodeMirror plugin.
In the src/components/ast directory, create two files:
{new language}-ast.tsx{new language}-ast-tree-item.tsx
Replace {new language} with the name of the language. You can copy existing files for other languages to get started.
In {new language}-ast-tree-item.tsx, update the name of the options type and the exported component to match the new language.
Next, install the ESLint language plugin for the new language.
In {new language}-ast.tsx:
- Update language references to point to the new language.
- Import the ESLint language plugin to parse the code.
- Set the
defaultValuein the accordion to the name of the root node for the new language AST.
Last, update src/components/index.tsx to import {new language}-ast.tsx and update Ast to include the new language.