nvim-treesitter / nvim-treesitter

Nvim Treesitter configurations and abstraction layer
Apache License 2.0
10.84k stars 901 forks source link

Allow changes in the working directory when compiling the tree-sitter language #2665

Open Dekker1 opened 2 years ago

Dekker1 commented 2 years ago

Is your feature request related to a problem? Please describe.

I'm working on a language that includes a tree-sitter parser. Although it is great that this project can immediately provide language support in NVIM, it is a bit frustrating to install the tree-sitter language. Because the tree-sitter grammar is located in a subdirectory of the repository, using a configuration that I would expect to work gives a compilation error:

Configuration:

parser_config.mylang = {
    install_info = {
        url = "https://github.com/[repo_url]",
        branch = "develop",
        files = {"[subdir]/src/parser.c"}
    },
    filetype = "mylang",
    used_by = {"mylang"}
}

Error:

nvim-treesitter[mylang]: Error during compilation                                                                                                  
[subdir]/src/parser.c:1:10: error: 'tree_sitter/parser.h' file not found with <angled> include; use "quotes" instead                
#include <tree_sitter/parser.h>                                                                                                                      
         ^~~~~~~~~~~~~~~~~~~~~~                                                                                                                      
         "tree_sitter/parser.h"

It would be great if there was some way to provide either the include path or the subdirectory in which the tree-sitter structure is located.

Describe the solution you'd like

An additional field in install_info that allows the user to specify a subdirectory of the repository in which the tree-sitter structure is located. The compilation should then be executed from this directory.

Describe alternatives you've considered

Additional context

I understand that this is maybe not the most common scenario and that most tree-sitter grammars are seperate from a language. However, for a developing language that uses the tree-sitter grammar internally, using only one repository that includes the grammar to keep it in sync seems logical to me.

theHamsta commented 2 years ago

For local development, you can just set it to the subfolder where your tree-sitter directory with standard tree-sitter layout is located. We have a work-around for this for tsx/typescript and ocaml parsers. See https://github.com/nvim-treesitter/nvim-treesitter/pull/2563#discussion_r812208864 as the vlang PR faced the same problem. We're open for PR that make this setting more expected/discoverable.

Dekker1 commented 2 years ago

I was indeed using the local development directory as workaround.

location was indeed the actual functionality that I was looking for. I was looking through the code trying to find something like it, but since I'm not an experienced LUA programmer I must have missed it.

It probably would be good to make this feature more visible. I'll see if I have some time to open a PR to add a sentence or two to the documentation.