Skip to content

Conversation

@dcreager
Copy link
Contributor

This patch adds the tree-sitter-config crate, which manages tree-sitter's configuration file. This new setup allows different components to define their own serializable configuration types, instead of having to create a single monolithic configuration type. But the configuration itself is still stored in a single JSON file.

Before, the default location for the configuration file was ~/.tree-sitter/config.json. This patch updates the default location to follow the XDG Base Directory spec (or other relevant platform-specific spec). So on Linux, for instance, the new default location is ~/.config/tree-sitter/config.json. We will look in the new location first, and fall back on reading from the legacy location if we can't find anything.

@dcreager dcreager requested a review from maxbrunsfeld June 10, 2021 12:55
@dcreager
Copy link
Contributor Author

c.f. #628

@dcreager
Copy link
Contributor Author

Compiled parsers are now placed into the user's cache directory, typically ~/.cache/tree-sitter/lib. It's still configurable where we look for the grammar source repo, using the parser-directories entry in the config file. No changes to the default set of source repo directories. There were suggestions on #628 that those should live under ~/.local, and I'd be open to including that in the default value for the config parameter, but I think it should remain configurable since most folks will want their grammars to be in their typical "bag of git clones" workspace directory.

Comment on lines 42 to 45
Err(anyhow!(concat!(
"Cannot find a tree-sitter configuration file.\n",
"Please run `tree-sitter init-config` to create one!"
)))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this makes it a hard error to run tree-sitter without having a config file in place, which is different than before. I'm honestly not sure that I like this part of the change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ha! And in fact that makes the test cases fail! Okay that definitely tells me we don't want this to be a hard error. I'll push up a fix for that.

@ahlinc
Copy link
Contributor

ahlinc commented Jun 10, 2021

@dcreager @maxbrunsfeld I know that clap crate allows to extract sub commands to separate binaries: https://users.rust-lang.org/t/using-external-subcommands-with-clap/10753/4. What are you think about to move tree-sitter highlight and tree-sitter tags sub commands into separate binaries in the corresponding crates?

@dcreager
Copy link
Contributor Author

sub commands into separate binaries in the corresponding crates

I quite like that idea, though I think it should be done in a separate PR

dcreager added 2 commits June 10, 2021 10:21
This patch adds the `tree-sitter-config` crate, which manages
tree-sitter's configuration file.  This new setup allows different
components to define their own serializable configuration types, instead
of having to create a single monolithic configuration type.  But the
configuration itself is still stored in a single JSON file.

Before, the default location for the configuration file was
`~/.tree-sitter/config.json`.  This patch updates the default location
to follow the XDG Base Directory spec (or other relevant platform-
specific spec).  So on Linux, for instance, the new default location is
`~/.config/tree-sitter/config.json`.  We will look in the new location
_first_, and fall back on reading from the legacy location if we can't
find anything.
Just fall back on the default values for each configuration option.
Copy link
Contributor

@maxbrunsfeld maxbrunsfeld left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great.

Can you do a cursory read of the syntax highlighting docs path and see if anything should be updated or rephrased, due to the changes to the config file's location?

@dcreager
Copy link
Contributor Author

see if anything should be updated or rephrased

Done ✔️

@dcreager dcreager merged commit 6ed4274 into tree-sitter:master Jun 10, 2021
@dcreager dcreager deleted the xdg-config branch June 10, 2021 19:39
Julian added a commit to Julian/dotfiles that referenced this pull request Jul 1, 2021
Does so as of tree-sitter/tree-sitter#1157

And having this set seems to cause tree-sitter to fail,
see tree-sitter/tree-sitter#1222
Julian added a commit to Julian/dotfiles that referenced this pull request Jun 18, 2022
Does so as of tree-sitter/tree-sitter#1157

And having this set seems to cause tree-sitter to fail,
see tree-sitter/tree-sitter#1222
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

Successfully merging this pull request may close these issues.

3 participants