1
0
Fork 0
mirror of https://github.com/helix-editor/helix synced 2024-05-19 15:36:05 +02:00

rename '--fetch/build-grammars' flags into '--grammar fetch/build'

The old flags were a bit long. --grammar is also aliased to -g to make
it even easier.
This commit is contained in:
Michael Davis 2022-03-08 00:13:15 -06:00 committed by Blaž Hrastnik
parent 37520f46ae
commit 7044d7d804
8 changed files with 25 additions and 23 deletions

2
Cargo.lock generated
View File

@ -435,7 +435,6 @@ name = "helix-term"
version = "0.6.0"
dependencies = [
"anyhow",
"cc",
"chrono",
"content_inspector",
"crossterm",
@ -460,7 +459,6 @@ dependencies = [
"serde_json",
"signal-hook",
"signal-hook-tokio",
"threadpool",
"tokio",
"tokio-stream",
"toml",

View File

@ -39,8 +39,8 @@ # Installation
git clone https://github.com/helix-editor/helix
cd helix
cargo install --path helix-term
hx --fetch-grammars
hx --build-grammars
hx --grammar fetch
hx --grammar build
```
This will install the `hx` binary to `$HOME/.cargo/bin` and build tree-sitter grammars.

View File

@ -60,7 +60,7 @@ ## Grammar configuration
| --- | ----------- |
| `git` | A git remote URL from which the grammar should be cloned |
| `rev` | The revision (commit hash or tag) which should be fetched |
| `subpath` | A path within the grammar directory which should be built. Some grammar repositories host multiple grammars (for example `tree-sitter-typescript` and `tree-sitter-ocaml`) in subdirectories. This key is used to point `hx --build-grammars` to the correct path for compilation. When omitted, the root of repository is used |
| `subpath` | A path within the grammar directory which should be built. Some grammar repositories host multiple grammars (for example `tree-sitter-typescript` and `tree-sitter-ocaml`) in subdirectories. This key is used to point `hx --grammar build` to the correct path for compilation. When omitted, the root of repository is used |
Or a `path` key with an absolute path to a locally available grammar directory.
@ -79,7 +79,7 @@ ## Queries
## Common Issues
- If you get errors when running after switching branches, you may have to update the tree-sitter grammars. Run `hx --fetch-grammars` to fetch the grammars and `hx --build-grammars` to build any out-of-date grammars.
- If you get errors when running after switching branches, you may have to update the tree-sitter grammars. Run `hx --grammar fetch` to fetch the grammars and `hx --grammar build` to build any out-of-date grammars.
- If a parser is segfaulting or you want to remove the parser, make sure to remove the compiled parser in `runtime/grammar/<name>.so`

View File

@ -58,5 +58,5 @@ ## Build from source
## Building tree-sitter grammars
Tree-sitter grammars must be fetched and compiled if not pre-packaged.
Fetch grammars with `hx --fetch-grammars` (requires `git`) and compile them
with `hx --build-grammars` (requires a C compiler).
Fetch grammars with `hx --grammar fetch` (requires `git`) and compile them
with `hx --grammar build` (requires a C compiler).

View File

@ -388,7 +388,7 @@ fn initialize_highlight(&self, scopes: &[String]) -> Option<Arc<HighlightConfigu
&injections_query,
&locals_query,
)
.unwrap_or_else(|query_error| panic!("Could not parse queries for language {:?}. Are your grammars out of sync? Try running 'hx --fetch-grammars' and 'hx --build-grammars'. This query could not be parsed: {:?}", self.language_id, query_error));
.unwrap_or_else(|query_error| panic!("Could not parse queries for language {:?}. Are your grammars out of sync? Try running 'hx --grammar build' and 'hx --grammar build'. This query could not be parsed: {:?}", self.language_id, query_error));
config.configure(scopes);
Some(Arc::new(config))

View File

@ -239,12 +239,12 @@ fn build_grammar(grammar: GrammarConfiguration) -> Result<()> {
};
let grammar_dir_entries = grammar_dir.read_dir().with_context(|| {
format!("Failed to read directory {grammar_dir:?}. Did you use 'hx --fetch-grammars'?")
format!("Failed to read directory {grammar_dir:?}. Did you use 'hx --grammar fetch'?")
})?;
if grammar_dir_entries.count() == 0 {
return Err(anyhow!(
"Directory {grammar_dir:?} is empty. Did you use 'hx --fetch-grammars'?"
"Directory {grammar_dir:?} is empty. Did you use 'hx --grammar fetch'?"
));
};

View File

@ -34,8 +34,13 @@ pub fn parse_args() -> Result<Args> {
args.health = true;
args.health_arg = argv.next_if(|opt| !opt.starts_with('-'));
}
"--fetch-grammars" => args.fetch_grammars = true,
"--build-grammars" => args.build_grammars = true,
"-g" | "--grammar" => match argv.next().as_deref() {
Some("fetch") => args.fetch_grammars = true,
Some("build") => args.build_grammars = true,
_ => {
anyhow::bail!("--grammar must be followed by either 'fetch' or 'build'")
}
},
arg if arg.starts_with("--") => {
anyhow::bail!("unexpected double dash argument: {}", arg)
}

View File

@ -59,16 +59,15 @@ async fn main_impl() -> Result<i32> {
<files>... Sets the input file to use, position can also be specified via file[:row[:col]]
FLAGS:
-h, --help Prints help information
--edit-config Opens the helix config file
--tutor Loads the tutorial
--health [LANG] Checks for potential errors in editor setup
If given, checks for config errors in language LANG
--fetch-grammars Fetches tree-sitter grammars listed in languages.toml
--build-grammars Builds tree-sitter grammars fetched with --fetch-grammars
-v Increases logging verbosity each use for up to 3 times
(default file: {})
-V, --version Prints version information
-h, --help Prints help information
--edit-config Opens the helix config file
--tutor Loads the tutorial
--health [LANG] Checks for potential errors in editor setup
If given, checks for config errors in language LANG
-g, --grammars {{fetch|build}} Fetches or builds tree-sitter grammars listed in languages.toml
-v Increases logging verbosity each use for up to 3 times
(default file: {})
-V, --version Prints version information
",
env!("CARGO_PKG_NAME"),
env!("VERSION_AND_GIT_HASH"),