Skip to content

Commit

Permalink
Docs for adding a language
Browse files Browse the repository at this point in the history
  • Loading branch information
mattmassicotte committed Apr 25, 2024
1 parent 8af188f commit 57c07ea
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
41 changes: 41 additions & 0 deletions Edit/Chime.docc/AddLanguage.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Adding a Language

Learn how to add a new language to Chime.

## Overview

There are multiple steps involved in adding new language support to Chime. Today, extensions cannot supply all of the needed functionality to support languages. In particular, all of the syntactic features require in-app changes.

### Determine UTIs

Chime relies heavily internally on [UTIs](https://developer.apple.com/documentation/uniformtypeidentifiers) for identifying file types. It is critical that the UTI is correctly set for all content. If you are unsure, you can verify it with the `kMDItemContentType` key from the `mdls` tool.

```
mdls path/to/your/file
```

These UTIs should first be encorporated into [ChimeKit](https://github.com/ChimeHQ/ChimeKit). From there, they can be added as "Imported Type Identifiers" in Chime's Info.plist. To do this, you'll need to know the file extensions used. ChimeKit also supports well-known file names, like `Makefile`, which the Uniform Type Identifier APIs do not currently support.

## Tree-Sitter

### Parser

The easiest path to supporting the language syntax is to use Chime's tree-sitter support. Once the parser supports SPM, to incorporate it you must:

- Add the SPM package to the main project
- Add the library as a dependency to `EditKit` and link it there
- Include the library module name in `NonSwiftWorkaround.xcconfig` to address an Xcode bug
- Import the module into `LanguageProfile+Profiles.swift`
- Add new static property to `LanguageProfile` for the language, and match its UTI

Chime also needs to locate the correct tree-sitter query definitions to perform highlighting and embedded language detection. This will be done automatically if the parser SPM package includes queries.

### Embedding Queries

Even if a parser package includes queries, they should be copied into a dedicated directory within `Resources/LanguageData`. This will make it possible for them to be loaded by the Spotlight Preview extension.

You might also be tempted to adjust these queries. Try to resist this temptation and instead fix the queries within their own projects.

## Language Server

After syntactic support is working, you can refer to ChimeKit's documentation on how to set up an extension for language server support.
2 changes: 2 additions & 0 deletions Edit/Chime.docc/Chime.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ Chime is an editor for macOS. The project is complex, and is undergoing major ch

- ``<doc:Building>``
- ``<doc:Structure>``
- ``<doc:AddLanguage>``

### Core Functionality

- ``<doc:Mutation>``

0 comments on commit 57c07ea

Please sign in to comment.