Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

tree-sitter ssh client config #2443

Closed
midnightexigent opened this issue May 9, 2022 · 3 comments
Closed

tree-sitter ssh client config #2443

midnightexigent opened this issue May 9, 2022 · 3 comments

Comments

@midnightexigent
Copy link
Contributor

I am looking into adding the tree-sitter-ssh-client-config but am having trouble, specifically making helix detect the file (it's the .ssh/config file), I have no idea what to put in file-types and root

[[language]]
name = "ssh-client-config"
scope = "source.ssh-client-config"
file-types = [] # I tried .ssh/config with no success
roots = []
[[grammar]]
name = "ssh-client-config"
source = { git = "https://github.com/metio/tree-sitter-ssh-client-config.git", rev = "769d7a01a2e5493b4bb5a51096c6bf4be130b024" }
@the-mikedavis
Copy link
Member

This may need a bit of work in the function that chooses a language configuration for a given file type, here:

pub fn language_config_for_file_name(&self, path: &Path) -> Option<Arc<LanguageConfiguration>> {
// Find all the language configurations that match this file name
// or a suffix of the file name.
let configuration_id = path
.file_name()
.and_then(|n| n.to_str())
.and_then(|file_name| self.language_config_ids_by_file_type.get(file_name))
.or_else(|| {
path.extension()
.and_then(|extension| extension.to_str())
.and_then(|extension| self.language_config_ids_by_file_type.get(extension))
});
configuration_id.and_then(|&id| self.language_configs.get(id).cloned())
// TODO: content_regex handling conflict resolution
}

This would be useful as well for git config where you can highlight .git/config as git-config.

You could set file-types = [ "config" ] as a temporary workaround but that would highlight all files called config or with an extension name of .config as ssh-config.

@midnightexigent
Copy link
Contributor Author

hmm, are you aware of any previous discussions on how this part of the config is resolved ? I can't think of a clean way to do this..

A "meh" solution would be to shellexpand the strings passed to file-types so that a user can provide something like

name = "ssh-client-config"
file-types = ["~/.ssh/config"] 

name = "git-config"
file-types = ["~/.gitconfig", "${workspace}/.git/config"]

With that, we can add an or_else in the function language_config_for_file_name that matches files by exact path

@the-mikedavis
Copy link
Member

There was a bit of discussion here #1426

I think the shell expand might be a good increment. What do others think?

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants