-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
13 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,25 @@ | ||
# [Tree Sitter](https://tree-sitter.github.io/tree-sitter/) grammar for [Smithy](https://awslabs.github.io/smithy/index.html) | ||
|
||
|
||
[![Build Status](https://github.com/indoorvivants/tree-sitter-smithy/workflows/CI/badge.svg)](https://github.com/indoorvivants/tree-sitter-smithy/workflows/CI/badge.svg) | ||
[![Discord](https://img.shields.io/discord/1063097320771698699?logo=discord)](https://discord.gg/w7nTvsVJhm) | ||
|
||
If you find yourself editing Smithy files in Neovim, you might be interested in this project. | ||
|
||
It provides a "good enough" grammar for Smithy, and a set of highlighting queries that | ||
should give you decent syntax highlighting. | ||
|
||
## Installation | ||
<!--toc:start--> | ||
- [Installation in Neovim](#installation-in-neovim) | ||
- [Additional links](#additional-links) | ||
<!--toc:end--> | ||
|
||
Make sure you have [Neovim Treesitter](https://github.com/nvim-treesitter/nvim-treesitter) plugin installed and configured. | ||
|
||
Adding syntax highlighting requires 3 steps: | ||
|
||
1. Drop this snippet into your `init.lua`: | ||
|
||
```lua | ||
local parser_config = require "nvim-treesitter.parsers".get_parser_configs() | ||
parser_config.smithy = { | ||
install_info = { | ||
url = "https://github.com/indoorvivants/tree-sitter-smithy", -- local path or git repo | ||
files = {"src/parser.c"}, | ||
-- optional entries: | ||
branch = "main", -- default branch in case of git repo if different from master | ||
generate_requires_npm = true, -- if stand-alone parser without npm dependencies | ||
requires_generate_from_grammar = true, -- if folder contains pre-generated src/parser.c | ||
}, | ||
filetype = "smithy" -- if filetype does not agrees with parser name | ||
} | ||
``` | ||
If you find yourself editing Smithy files in Neovim, you might be interested in this project. | ||
|
||
and run `:TSInstall smithy`, this should succeed | ||
<img width="542" alt="image" src="https://user-images.githubusercontent.com/1052965/215846807-17218c3c-4ba3-4a85-86fa-f97f48952bd1.png"> | ||
|
||
2. By default, Neovim doesn't recognise `smithy` extension and doesn't have a filetype for it. | ||
## Installation in Neovim | ||
|
||
If you are not familiar with filetypes, the simplest way to enable them is to add this line | ||
to your `init.lua` script: | ||
Smithy has been added to [nvim-treesitter](https://github.com/nvim-treesitter/nvim-treesitter) so you can follow normal configuration instructions. | ||
|
||
```lua | ||
vim.cmd([[au BufRead,BufNewFile *.smithy setfiletype smithy]]) | ||
``` | ||
3. For some reason, nvim-treesitter doesn't copy the highlighting queries from the repo, so you'll need | ||
to take the [`highlights.scm`](./highlights.scm) file and copy it into `.local/share/nvim/site/pack/packer/start/nvim-treesitter/queries/smithy/highlights.scm` | ||
## Additional links | ||
|
||
If there's a better way of doing it, please let me know. | ||
- [Smithy in Neovim: parsing, syntax highlighting, LSP](https://blog.indoorvivants.com/2022-05-12-smithy-neovim) - my blog post documenting the development | ||
of the first version of the grammar and integrating it into my Neovim setup | ||
|
||
After that, once you restart neovim, you should have highlighting powered by Tree-sitter in your `*.smithy` files | ||
Since then contributors took it from rough sketch to nearly perfect parser, for which I'm extremely grateful. |
cf8c7eb
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice! was planning to do this..eventually