Merge pull request #17 from xixiaofinland/main

Readme info for nvim-treesitter usage
pull/579/head
Heber 2023-10-02 08:18:32 +07:00 committed by GitHub
commit a768c956b6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 52 additions and 0 deletions

@ -4,6 +4,9 @@ Salesforce grammars for [tree-sitter](https://github.com/tree-sitter/tree-sitter
Try it out using our [playground](https://aheber.github.io/tree-sitter-sfapex/playground/)
If you are a Neo-vim user, the parsers and syntax highlights are part of nvim-treesitter
plugin already, [guidance](nvim-treesitter-setup.md).
## Status
Most of the parsers are built and tested on large corpus of Apex, I still intend to write automated tests that parse large Apex libraries as part of evaluating the grammar.

@ -0,0 +1,49 @@
# Use parsers and queries in nvim-treesitter plugin
The Apex, SOQL, and SOSL parsers in this repo are alredy part of [nvim-treesitter
repository](https://github.com/nvim-treesitter/nvim-treesitter).
Any parser new version in this repo is automatically syned in nvim-treesitter.
Note. Nvim-treesitter maintains its own version of `scm` [query files](https://github.com/nvim-treesitter/nvim-treesitter/tree/master/queries).
It means that the query files stored in this repo is not used by nvim-treesitter.
# How to install and use
Installing the nvim-treesitter plugin with whatever package manager you use.
I use `Lazy`, and you can find my Nvim dotfiles
[here](https://github.com/xixiaofinland/dotfiles/tree/main/.config/nvim).
Once the plugin is installed, the parsers and query files are part of the plugin in your
local installed version.
In your Nvim init configuraiton, you need to setup the filetypes so
nvim-treesitter automatically kicks-in when corresponding filetypes are opened.
```lua
vim.filetype = on
vim.filetype.add({
extension = {
cls = 'apex',
apex = 'apex',
trigger = 'apex',
soql = 'soql',
sosl = 'sosl',
}
})
```
Now when you open a `.cls` file, Nvim should use the `Apex` parser to parse the Apex language and
`highlights.scm` to highlight syntax.
# Troubleshoot
1. Are the parsers successfully installed?
Run `:TSInstallInfo` to see the parser installation information
2. No syntax highlight in Apex?
Sometimes the syntax higlight module is disabled, open an Apex file and run `:TSEnable highlight` to enable it.