Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Thought on XDG convention #628

Closed
azzamsa opened this issue May 28, 2020 · 10 comments
Closed

Thought on XDG convention #628

azzamsa opened this issue May 28, 2020 · 10 comments

Comments

@azzamsa
Copy link

azzamsa commented May 28, 2020

tree-sitter puts the config in ~/.tree-sitter/config.json. Would it be better if fit in better with the XDG conventions?

@dcreager
Copy link
Contributor

dcreager commented May 28, 2020

I like this idea, and we can leave ~/.tree-sitter/config.json as a legacy fallback location.

@maxbrunsfeld Is the config file ever needed by the C library, or is it only used by the Rust CLI tool? If we need this from C, there is some code we could lift from libcork that both defines the XDG locations and implements a "look for a file in this list of paths" search. [docs] [code]

@dcreager
Copy link
Contributor

(and if it's only needed from Rust there's the xdg crate)

@patrickt
Copy link
Contributor

I’m +1 on this too, viz. how Emacs looks in .emacs.d and .config/emacs.

@maxbrunsfeld
Copy link
Contributor

Yeah, I'd be open to this. The config file is specific to the CLI, so there's not much cost to changing it.

@alemuller
Copy link
Contributor

$XDG_DATA_HOME/tree-sitter could be suggest as one of the defaults directories in "parser-directories"on config file.

@gwerbin
Copy link

gwerbin commented Dec 10, 2020

+1 to these! To recap, the "XDG way" would be something like this (in Bash-like syntax):

Config file: ${XDG_CONFIG_HOME:-$HOME/.config}/tree-sitter/config.json, using ~/.tree-sitter/config.json if that doesn't exist.

Parsers: ${XDG_DATA_HOME:-$HOME/.local/share}/tree-sitter/parsers/* as the first default in the config file, above the other ones that are already listed.

@Julian
Copy link
Contributor

Julian commented Feb 24, 2021

+1, but it's also nice to have an explicit environment variable (e.g. TREE_SITTER_HOME) to decide where the directory goes (if such an envvar existed someone who wanted this behavior could have had it already without waiting for specific XDG support)

@gwerbin
Copy link

gwerbin commented Feb 24, 2021

+1, but it's also nice to have an explicit environment variable (e.g. TREE_SITTER_HOME) to decide where the directory goes (if such an envvar existed someone who wanted this behavior could have had it already without waiting for specific XDG support)

Note that the idea of a single "HOME" directory is somewhat incompatible with the XDG base directory setup, because in the XDG system you have two directories: one in XDG_CONFIG_HOME and the other in XDG_DATA_HOME.

A long time ago I implemented a patch for the Ruby Bundler tool that had some complicated fallback logic for this kind of thing: rubygems/bundler#6024

I propose the following for Tree Sitter:

  • If TREE_SITTER_HOME is set, look in $TREE_SITTER_HOME/config.json and $TREE_SITTER_HOME/parsers/*.
  • If TREE_SITTER_HOME is not set, look for Tree Sitter config files in $XDG_CONFIG_HOME/tree-sitter/config.json and parsers in $XDG_DATA_HOME/tree-sitter/parsers/*.

So this will still be a breaking change, but you can choose to set TREE_SITTER_HOME if you don't want to move your stuff into the XDG locations.

Also, note that there is some debate on Mac and Windows as to whether the default XDG locations should be the same as on Linux or should use something more platform-specific. See https://stackoverflow.com/q/3373948/2954547 (Mac) and https://stackoverflow.com/q/43853548/2954547 (Windows).

@p13nty
Copy link

p13nty commented Apr 25, 2021

For anyone trying to move out .tree-sitter directory from $HOME:

It turns out tree-sitter cli supports $TREE_SITTER_DIR.

Here is my config:

export TREE_SITTER_DIR="${XDG_CONFIG_HOME}/tree-sitter"

@ahlinc
Copy link
Contributor

ahlinc commented Jun 30, 2021

@maxbrunsfeld this issue was successfully resolved by awesome @dcreager rework of CLI with extraction of config loading logic to a separate crate. So this issue can be closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants