Skip to content

Commit

Permalink
Update language docs
Browse files Browse the repository at this point in the history
  • Loading branch information
mattmassicotte committed Jul 10, 2024
1 parent 1beb1d2 commit 8308f68
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions Edit/Chime.docc/AddLanguage.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,25 @@ Chime relies heavily internally on [UTIs](https://developer.apple.com/documentat
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.
These UTIs should first be incorporated 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
- Add the SPM package to the `TreeSitterParsers` target of the `Dependencies` local package
- Modify `Dependencies/Sources/TreeSitterParsers/TreeSitterParsers` to re-export the parser symbols
- 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
- Add new static property to `LanguageProfile` for the language
- Match the language UTI and return it in `LanguageProfile.profile(for:)`

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.
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 Quick Look Preview extension. This duplication is not ideal, but I have not yet been able to find a workaround.

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

Expand Down

0 comments on commit 8308f68

Please sign in to comment.