-
Notifications
You must be signed in to change notification settings - Fork 30
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
update keyword and operator definitions in highlights.scm #156
base: main
Are you sure you want to change the base?
Conversation
I think it's not possible without changing the grammar. And even if we manage to make builtin internals correct, there're still user defined composite commands... I'm afraid there's no perfect solution for this in tree-sitter. |
I got the CI to pass at least. I guess I need to point my nvim config at this branch to get it to work/use it? |
Actually you can just edit your highlights.scm file in the ftplugin to test the color, but I think nothing will change, since the parsed tree is the same. |
no clue what ftplugin is. this is my config https://github.com/fdncred/nvim-dotfiles/blob/de092ea37c325545ffca85d702c8e323e28ad979/lua/kickstart/plugins/treesitter.lua#L33 |
ya, right. it's pointing to my local where the file is edited. darn. so, the grammar has to be changed to make the highlighting work right? i guess that means that the grammar doesn't recognize commands with spaces. I guess i don't understand this part of the highlights.scm if it does nothing. why is it even in the file? |
@fdncred it does the job of correct highlighting the "head" if it is in the collected strings, however the |
Sorry, you're right, |
would be nice if the grammar for nushell would be able to highlight commands in nushell. LOL Seems like the parser would need to check if the text after a command was part of the command or not and if not it's an argument, otherwise it's all the command. Maybe that's easier to say than to do? |
@fdncred The only way that I can imagine is hardcoded choices in function _command_rule(parenthesized) {
return (/** @type {any} */ $) => {
const sep = parenthesized ? $._separator : $._space;
return prec.right(
seq(
choice(
field("head", seq(optional(PUNC().caret), $.cmd_identifier)),
field("head", seq(PUNC().caret, $._stringish)),
field("head", choice(...INTERNALS())), // <-- collection of all composite commands
),
repeat(seq(sep, optional($._cmd_arg))),
),
);
};
} But still, it can't deal with user-defined ones (probably no solution). |
I'm not as concerned about custom commands, but internal commands and plugins should at least be identified as such. |
I see two options:
Edit: I have a slight aversion against manually maintaining all these commands in this repo |
I understand that but I'd also "keep it simple". Having the commands and plugin command hard coded somehow seems easy to maintain because that section could just be replaced as needed. This is what the vscode extension does here in the |
We could also use the regex, then we only sync regexes and don't have to maintain different representations of the same information. What do you think? |
I'm up for trying it. If we don't like it, we can always revert it. |
@fdncred naive implementation FYI. Update: extra regex suffix for situations like weatherdark.nu where |
With vscode, we can make regexes with ^/$ and \b word boundaries. Would be nice to be able to combine INTERNAL with word boundaries so it knows where words end. Also, can you put up a PR with your implementation. I think I could test it easier by checking out your PR. |
Sad story,
|
For test purpose #156 --------- Co-authored-by: Darren Schroeder <[email protected]>
This PR is an attempt to update the keywords, operators and commands. I'm hoping that things like
str replace
are highlighted as a command instead of being highlighted as a command and an argument.I'm not sure how to test this. Any guidance would be helpful.
Maybe commands with spaces aren't allowed?