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

Add support for a workspace runtime directory #12823

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion book/src/guides/textobject.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ documentation][tree-sitter-queries].
Query files should be placed in `runtime/queries/{language}/textobjects.scm`
when contributing to Helix. Note that to test the query files locally you should put
them under your local runtime directory (`~/.config/helix/runtime` on Linux
for example).
for example) or the workspace runtime directory (`$PWD/.helix/runtime`).

The following [captures][tree-sitter-captures] are recognized:

Expand Down
11 changes: 8 additions & 3 deletions helix-loader/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ pub fn initialize_log_file(specified_file: Option<PathBuf>) {
/// 3. `HELIX_RUNTIME` (if environment variable is set)
/// 4. `HELIX_DEFAULT_RUNTIME` (if environment variable is set *at build time*)
/// 5. subdirectory of path to helix executable (always included)
/// 6. workspace directory, e.g. `$PWD/.helix/runtime` (see [runtime_dirs])
///
/// Postcondition: returns at least two paths (they might not exist).
fn prioritize_runtime_dirs() -> Vec<PathBuf> {
Expand Down Expand Up @@ -81,8 +82,12 @@ fn prioritize_runtime_dirs() -> Vec<PathBuf> {
/// All directories should be checked when looking for files.
///
/// Postcondition: returns at least one path (it might not exist).
pub fn runtime_dirs() -> &'static [PathBuf] {
&RUNTIME_DIRS
pub fn runtime_dirs() -> Vec<PathBuf> {
let mut rt_dirs = Vec::with_capacity(RUNTIME_DIRS.len() + 1);
rt_dirs.clone_from(&RUNTIME_DIRS);
// workspace runtime directory
rt_dirs.push(find_workspace().0.join(".helix").join("runtime"));
rt_dirs
}

/// Find file with path relative to runtime directory
Expand All @@ -91,7 +96,7 @@ pub fn runtime_dirs() -> &'static [PathBuf] {
/// The valid runtime directories are searched in priority order and the first
/// file found to exist is returned, otherwise None.
fn find_runtime_file(rel_path: &Path) -> Option<PathBuf> {
RUNTIME_DIRS.iter().find_map(|rt_dir| {
runtime_dirs().iter().find_map(|rt_dir| {
let path = rt_dir.join(rel_path);
if path.exists() {
Some(path)
Expand Down