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

cli: Extract CLI configuration into separate crate #1157

Merged
merged 3 commits into from
Jun 10, 2021

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
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

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 ✔️

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.

None yet

3 participants