<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>book/src/guides/adding_languages.md - fork/helix @ 25.01.1</title>
<meta name="description" content="book/src/guides/adding_languages.md in fork/helix at 25.01.1.">
<meta property="og:title" content="book/src/guides/adding_languages.md - fork/helix @ 25.01.1">
<meta property="og:description" content="book/src/guides/adding_languages.md in fork/helix at 25.01.1.">
<meta property="og:type" content="website">
<meta property="og:site_name" content="git.julia.blue">
<link rel="stylesheet" href="/css/style.css?v=62">
<script type="module" src="/js/main.js?v=62"></script>
</head>
<body>
<main data-ref="25.01.1" data-tip="e7ac2fcdecfdbf43a4f772e7f7c163b43b3d0b9b">
<noscript>
  <div class="callout">
    <p>
      hey! this is a static git repo viewer. commit diffs, file history,
      older commits and other revisions won't load without javascript.
    </p>
    <p>
      you are still able to view source files on branch/tag tips,
      but the experience is degraded.
    </p>
  </div>
</noscript>
<header class="repo"><div>
<h1>fork/helix</h1>
</div>
<pre class="clone">git clone https://git.julia.blue/fork/helix</pre>
</header>
<p class="snapshot-commit"><span class="commit-author">Michael Davis</span><span class="commit-message" data-commit="127567df8e88cfa71feb66619a6016988d984256">docs: Fix dead links to tree-sitter docs</span><span class="snapshot-sha sha" data-commit="127567df8e88cfa71feb66619a6016988d984256">127567df</span><time datetime="2024-12-28T09:05:46-05:00" title="2024-12-28 09:05:46 -0500">2024-12-28</time></p>
<header class="topbar"><details class="switcher"><summary>25.01.1</summary><div class="menu"><strong>branches</strong><a href="/fork/helix/ref/master/">master</a><strong>tags</strong><a href="/fork/helix/ref/23.05/">23.05</a><a href="/fork/helix/ref/23.10/">23.10</a><a href="/fork/helix/ref/24.03/">24.03</a><a href="/fork/helix/ref/24.07/">24.07</a><a href="/fork/helix/ref/25.01/">25.01</a><a class="current" href="/fork/helix/ref/25.01.1/">25.01.1</a><a href="/fork/helix/ref/25.07/">25.07</a><a href="/fork/helix/ref/25.07.1/">25.07.1</a><a class="all" href="/fork/helix/refs">all refs →</a></div></details><nav class="crumbs"><a href="/fork/helix/">helix</a> / <a href="/fork/helix/ref/25.01.1/tree/book/">book</a> / <a href="/fork/helix/ref/25.01.1/tree/book/src/">src</a> / <a href="/fork/helix/ref/25.01.1/tree/book/src/guides/">guides</a> / <span class="cur">adding_languages.md</span></nav>
<span class="view-stats"><span>2.7 KiB</span><span>55 lines</span></span><span class="actions"><a class="raw" href="/fork/helix/raw/cb7e0eb63c783e8b26294d59604fb2be3db73453/book/src/guides/adding_languages.md">raw</a></span></header>
<div class="markdown-view"><input type="radio" name="markdown-view" id="markdown-rendered" checked><label for="markdown-rendered">rendered</label><input type="radio" name="markdown-view" id="markdown-code"><label for="markdown-code">code</label><section class="readme rendered"><h2>Adding new languages to Helix</h2>
<p>In order to add a new language to Helix, you will need to follow the steps
below.</p>
<h2>Language configuration</h2>
<ol>
<li>Add a new <code>[[language]]</code> entry in the <code>languages.toml</code> file and provide the
necessary configuration for the new language. For more information on
language configuration, refer to the
<a href="/fork/helix/ref/25.01.1/blob/book/src/languages.md">language configuration section</a> of the documentation.
A new language server can be added by extending the <code>[language-server]</code> table in the same file.</li>
<li>If you are adding a new language or updating an existing language server
configuration, run the command <code>cargo xtask docgen</code> to update the
<a href="/fork/helix/ref/25.01.1/blob/book/src/lang-support.md">Language Support</a> documentation.</li>
</ol>
<blockquote>
<p>💡 If you are adding a new Language Server configuration, make sure to update
the
<a href="https://github.com/helix-editor/helix/wiki/Language-Server-Configurations">Language Server Wiki</a>
with the installation instructions.</p>
</blockquote>
<h2>Grammar configuration</h2>
<ol>
<li>If a tree-sitter grammar is available for the new language, add a new
<code>[[grammar]]</code> entry to the <code>languages.toml</code> file.</li>
<li>If you are testing the grammar locally, you can use the <code>source.path</code> key
with an absolute path to the grammar. However, before submitting a pull
request, make sure to switch to using <code>source.git</code>.</li>
</ol>
<h2>Queries</h2>
<ol>
<li>In order to provide syntax highlighting and indentation for the new language,
you will need to add queries.</li>
<li>Create a new directory for the language with the path
<code>runtime/queries/&lt;name&gt;/</code>.</li>
<li>Refer to the
<a href="https://tree-sitter.github.io/tree-sitter/3-syntax-highlighting.html#highlights">tree-sitter website</a>
for more information on writing queries.</li>
<li>A list of highlight captures can be found <a href="https://docs.helix-editor.com/themes.html#scopes">on the themes page</a>.</li>
</ol>
<blockquote>
<p>💡 In Helix, the first matching query takes precedence when evaluating
queries, which is different from other editors such as Neovim where the last
matching query supersedes the ones before it. See
<a href="https://github.com/helix-editor/helix/pull/1170#issuecomment-997294090">this issue</a>
for an example.</p>
</blockquote>
<h2>Common issues</h2>
<ul>
<li>If you encounter errors when running Helix after switching branches, you may
need to update the tree-sitter grammars. Run the command <code>hx --grammar fetch</code>
to fetch the grammars and <code>hx --grammar build</code> to build any out-of-date
grammars.</li>
<li>If a parser is causing a segfault, or you want to remove it, make sure to
remove the compiled parser located at <code>runtime/grammars/&lt;name&gt;.so</code>.</li>
<li>If you are attempting to add queries and Helix is unable to locate them, ensure that the environment variable <code>HELIX_RUNTIME</code> is set to the location of the <code>runtime</code> folder you're developing in.</li>
</ul>
</section><div class="code-panel"><pre class="code src language-markdown"><span class="code-line"><a class="ln" id="L1" href="#L1">1</a><span class="code-text"><a-p>##</a-p> <a-tt>Adding new languages to Helix</a-tt></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L2" href="#L2">2</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L3" href="#L3">3</a><span class="code-text">In order to add a new language to Helix, you will need to follow the steps</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L4" href="#L4">4</a><span class="code-text">below.</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L5" href="#L5">5</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L6" href="#L6">6</a><span class="code-text"><a-p>##</a-p> <a-tt>Language configuration</a-tt></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L7" href="#L7">7</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L8" href="#L8">8</a><span class="code-text"><a-p>1. </a-p>Add a new `[[language]]` entry in the `languages.toml` file and provide the</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L9" href="#L9">9</a><span class="code-text"><a-p>   </a-p>necessary configuration for the new language. For more information on</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L10" href="#L10">10</a><span class="code-text"><a-p>   </a-p>language configuration, refer to the</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L11" href="#L11">11</a><span class="code-text"><a-p>   </a-p>[language configuration section](../languages.md) of the documentation.</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L12" href="#L12">12</a><span class="code-text"><a-p>   </a-p>A new language server can be added by extending the `[language-server]` table in the same file.</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L13" href="#L13">13</a><span class="code-text"><a-p>2. </a-p>If you are adding a new language or updating an existing language server</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L14" href="#L14">14</a><span class="code-text"><a-p>   </a-p>configuration, run the command `cargo xtask docgen` to update the</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L15" href="#L15">15</a><span class="code-text"><a-p>   </a-p>[Language Support](../lang-support.md) documentation.</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L16" href="#L16">16</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L17" href="#L17">17</a><span class="code-text"><a-p>&gt; 💡 If you are adding a new Language Server configuration, make sure to update</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L18" href="#L18">18</a><span class="code-text"><a-p>&gt; the</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L19" href="#L19">19</a><span class="code-text"><a-p>&gt; [Language Server Wiki](https://github.com/helix-editor/helix/wiki/Language-Server-Configurations)</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L20" href="#L20">20</a><span class="code-text"><a-p>&gt; with the installation instructions.</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L21" href="#L21">21</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L22" href="#L22">22</a><span class="code-text"><a-p>## </a-p><a-tt>Grammar configuration</a-tt></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L23" href="#L23">23</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L24" href="#L24">24</a><span class="code-text"><a-p>1. If a tree-sitter grammar is available for the new language, add a new</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L25" href="#L25">25</a><span class="code-text"><a-p>   `[[grammar]]` entry to the `languages.toml` file.</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L26" href="#L26">26</a><span class="code-text"><a-p>2. If you are testing the grammar locally, you can use the `source.path` key</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L27" href="#L27">27</a><span class="code-text"><a-p>   with an absolute path to the grammar. However, before submitting a pull</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L28" href="#L28">28</a><span class="code-text"><a-p>   request, make sure to switch to using `source.git`.</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L29" href="#L29">29</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L30" href="#L30">30</a><span class="code-text"><a-p>## </a-p><a-tt>Queries</a-tt></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L31" href="#L31">31</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L32" href="#L32">32</a><span class="code-text"><a-p>1. In order to provide syntax highlighting and indentation for the new language,</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L33" href="#L33">33</a><span class="code-text"><a-p>   you will need to add queries.</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L34" href="#L34">34</a><span class="code-text"><a-p>2. Create a new directory for the language with the path</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L35" href="#L35">35</a><span class="code-text"><a-p>   `runtime/queries/&lt;name&gt;/`.</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L36" href="#L36">36</a><span class="code-text"><a-p>3. Refer to the</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L37" href="#L37">37</a><span class="code-text"><a-p>   [tree-sitter website](https://tree-sitter.github.io/tree-sitter/3-syntax-highlighting.html#highlights)</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L38" href="#L38">38</a><span class="code-text"><a-p>   for more information on writing queries.</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L39" href="#L39">39</a><span class="code-text"><a-p>4. A list of highlight captures can be found [on the themes page](https://docs.helix-editor.com/themes.html#scopes).</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L40" href="#L40">40</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L41" href="#L41">41</a><span class="code-text"><a-p>&gt; 💡 In Helix, the first matching query takes precedence when evaluating</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L42" href="#L42">42</a><span class="code-text"><a-p>&gt; queries, which is different from other editors such as Neovim where the last</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L43" href="#L43">43</a><span class="code-text"><a-p>&gt; matching query supersedes the ones before it. See</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L44" href="#L44">44</a><span class="code-text"><a-p>&gt; [this issue](https://github.com/helix-editor/helix/pull/1170#issuecomment-997294090)</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L45" href="#L45">45</a><span class="code-text"><a-p>&gt; for an example.</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L46" href="#L46">46</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L47" href="#L47">47</a><span class="code-text"><a-p>## </a-p><a-tt>Common issues</a-tt></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L48" href="#L48">48</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L49" href="#L49">49</a><span class="code-text"><a-p>- If you encounter errors when running Helix after switching branches, you may</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L50" href="#L50">50</a><span class="code-text"><a-p>  need to update the tree-sitter grammars. Run the command `hx --grammar fetch`</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L51" href="#L51">51</a><span class="code-text"><a-p>  to fetch the grammars and `hx --grammar build` to build any out-of-date</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L52" href="#L52">52</a><span class="code-text"><a-p>  grammars.</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L53" href="#L53">53</a><span class="code-text"><a-p>- If a parser is causing a segfault, or you want to remove it, make sure to</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L54" href="#L54">54</a><span class="code-text"><a-p>  remove the compiled parser located at `runtime/grammars/&lt;name&gt;.so`.</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L55" href="#L55">55</a><span class="code-text"><a-p>- </a-p>If you are attempting to add queries and Helix is unable to locate them, ensure that the environment variable `HELIX_RUNTIME` is set to the location of the `runtime` folder you&#39;re developing in.</span></span></pre></div></div>
</main>
</body>
</html>
