shikijs / textmate-grammars-themes

Collection of TextMate grammars and themes in JSON
https://textmate-grammars-themes.netlify.app/
MIT License
116 stars 57 forks source link

Change ``shellsession`` grammar or ``shellscript`` grammar source for more accurate parsing #43

Closed Robot-Inventor closed 8 months ago

Robot-Inventor commented 8 months ago

This issue is related to a problem with the first command in shellsession not being highlighted correctly (https://github.com/shikijs/shiki/issues/616)

I reported the above issue upstream (https://github.com/jeff-hykin/better-shell-syntax/issues/79) and found that fixing this issue requires action in this repository, so here I am.

First, from a maintenance standpoint, I was told that it would be difficult to update the shellscript grammar to fix the issue. Also, the original shellsession grammar assumes that the grammar file in linguist is used to parse shellscript, not better-shell-syntax used in VS Code. If linguist is used to parse shellscript, shellsession will work correctly.

Therefore, there are two ways to fix this issue.

  1. use linguist instead of better-shell-syntax as the shellscript grammar
  2. fork the better-shell-syntax and shellscript grammars and modify each

I have confirmed that both options will fix the issue. The easiest to work with is option 1, but the possibility of breaking compatibility with other grammars cannot be ruled out. I would like to hear your opinion on this matter.

PS: It seems that only a very few commands are highlighted when linguist is used. Therefore, option 2 may be better if you do not consider the hassle.

antfu commented 8 months ago

Thanks for your effort in investigating and reporting. Unfortunately, neither of the options seems considerable to me. I think it's easier for Shiki to align with VS Code as much as possible (so we could count on the VS Code team to make sure the grammars are up to date and well maintained).

It would be hard to take immediate action about grammar on our side, as Shiki is about the highlighter, and we can't take care of all grammar for different languages.

I suggest you forget about the grammars Shiki has builtin for a moment. Instead you could provide your own grammars as documented https://shiki.style/guide/load-lang, to use another grammar one or fork your own - until VS Code fixes it and get synced down to Shiki.

Thank you.

Robot-Inventor commented 8 months ago

Thank you for your kind response. I will use custom grammar.

For others who are interested in this issue: I created a project that automatically patches the VS Code grammar to generate a custom grammar for shellsession. If you need it, you can use it from here: https://github.com/Robot-Inventor/shell-session-syntax/