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

Closed
wants to merge 1 commit into from

Conversation

senekor
Copy link
Contributor

@senekor senekor commented Feb 9, 2025

closes #12821

In the documentation, there isn't much reference to these directories, other than that hx --health displays them. The new workspace directory is correctly included there.

@senekor senekor force-pushed the senekor/sztxwllqnovr branch from d11bc16 to fbe9f9a Compare February 15, 2025 12:40
@senekor
Copy link
Contributor Author

senekor commented Feb 27, 2025

I actually ran into a problem by not having this, it's not just an aesthetic thing anymore. The building from source instructions for helix recommend symlinking ~/.config/helix/runtime to the repository. In that case, ec2hx generates stuff into one's helix repository, which is very annoying.

Would be great if someone could take a look at it, it doesn't seem like an invasive change.

@nik-rev
Copy link
Contributor

nik-rev commented Mar 7, 2025

This is a REALLY powerful feature and I will show you why with a personal usecase.

I use a python project which has a rust function. This function accepts Rust source code:

rust("""macro_rules! my_macro {
    ($wow : tt) => {
        dbg!($wow);
    };
}""")

I use this function quite a lot. I would really like to have syntax highlighting for it.

To do this, I made the following file:

~/.config/helix/runtime/queries/python/injections.scm. This file contains:

((call
  function: (identifier) @_fn_name
  arguments: (argument_list 
               (string 
                 (string_content) @injection.content)))
 (#eq? @_fn_name "rust")
 (#set! injection.language "rust")
 (#set! injection.include-children))

The above code will inject the rust language into the arguments of the rust function in Python. We could make it more fine grained by only targetting the first argument etc, but that's not the point here

Now, I actually have Rust syntax highlighting for that

image

What's problematic, is that I must add this to my global configuration. I want my project-related stuff in the actual project.

I want other Helix users to be able to use this feature as well. So that's why I think this feature is actually extremely powerful because you can do arbitrary injections with it per-project and improve the experience.

Would love to get this merged!

@senekor
Copy link
Contributor Author

senekor commented Mar 7, 2025

Interestesting! I can think of more use cases in that direction too. I sometimes work on frontend apps with leptos, which has an html-like macro. It could be cool to inject html syntax highlighting into Rust on those projects.

@the-mikedavis
Copy link
Member

the-mikedavis commented Mar 8, 2025

This won't work in the long run for queries as we will eventually move them out of the runtime directory and into ~/.local/state (using some things from the tree-house repo). Generally we shouldn't allow having queries and parsers in separate places as we do now because whether a query compiles or not is based on the version of the parser. tree-sitter-python could update in the future to rename or remove any of the named nodes in that query (for example (string_content)) and that query and all python highlighting would break even if runtime/queries/python/highlights.scm were fixed. In practice this has historically lead to many headaches when a runtime directory isn't symlinked and this line shows up in the logs. With skidder from the tree-house repo we will bundle parsers and queries together. We should think of how to support custom queries as I think neovim does something similar but I don't want to introduce it like this since it will be brittle and eventually removed/changed.

For query files that are just ; inherits: <lang> the "parsers and queries are bundled" problem isn't really a problem. This setup is a bit cursed as you said in a comment on the other PR though and I'd only like to consider workspace runtime directories if they have a reasonable use-case that isn't queries. For ec2hx I'd like to sidestep this by just adding EditorConfig to core. I believe the context at the time for #1777 was that we didn't want to pull in a lot of code or dependencies for the feature and ec4rs (and the change in that PR) is quite heavy relative to how complex the EditorConfig spec is. The spec is very straightforward though and we should be able to support it in a small number of SLoC with no deps and in a single module. I'll post a patch for that (edit: #13056).

@senekor
Copy link
Contributor Author

senekor commented Mar 8, 2025

Thanks for the great explanation, that all makes sense.

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.

Add support for a workspace runtime directory
4 participants