Skip to content

Commit

Permalink
Update README
Browse files Browse the repository at this point in the history
  • Loading branch information
keynmol committed Jan 31, 2023
1 parent 8516587 commit cf8c7eb
Showing 1 changed file with 13 additions and 37 deletions.
50 changes: 13 additions & 37 deletions README.md
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.

1 comment on commit cf8c7eb

@amaanq
Copy link
Collaborator

@amaanq amaanq commented on cf8c7eb Feb 2, 2023

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

Please sign in to comment.