shikijs / shiki

A beautiful yet powerful syntax highlighter

Home Page:http://shiki.style/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`shellsession` language not highlighting first command

sventec opened this issue · comments

Validations

Describe the bug

When using the syntax highlighter shellsession, the first bash command on the line is inconsistently formatted, compared to subsequent commands. This can be seen directly in the Playground by using a command such as:

user@test$ echo -n $EDITOR | grep -E "vim"

As seen in this screenshot, grep and -E are stylized, while cat and -n are not:
image

Here is another example with ; instead of |:
image

Reproduction

Type a compound command with e.g. | or ; using the shellsession language in the Playground

Contributes

  • I am willing to submit a PR to fix this issue
  • I am willing to submit a PR with failing tests

For more context, here is the Playground highlighting the examples from above using the shell grammar. This is what seems to be referenced in tm-grammars as the grammar to use for everything after the $ in shellsession.

image

As can be seen, the syntax highlighting doesn't match with the highlighting after $ in shellsession.

I have the same issue. Using console.log() to output token in tokenizeWithTheme() function, I found that the code was not tokenized correctly. I'm not familiar with this project, but it seems like a bug in the grammar file or its loading process or vscode-textmate.

{ content: 'user@test$', offset: 0, color: '#569CD6', fontStyle: 0 }
{ content: ' echo -n ', offset: 10, color: '#CCCCCC', fontStyle: 0 }
{ content: '$EDITOR', offset: 19, color: '#9CDCFE', fontStyle: 0 }
{ content: ' ', offset: 26, color: '#CCCCCC', fontStyle: 0 }
{ content: '|', offset: 27, color: '#D4D4D4', fontStyle: 0 }
{ content: ' ', offset: 28, color: '#CCCCCC', fontStyle: 0 }
{ content: 'grep', offset: 29, color: '#DCDCAA', fontStyle: 0 }
{ content: ' ', offset: 33, color: '#CCCCCC', fontStyle: 0 }
{ content: '-E', offset: 34, color: '#569CD6', fontStyle: 0 }
{ content: ' ', offset: 36, color: '#CCCCCC', fontStyle: 0 }
{ content: '"vim"', offset: 37, color: '#CE9178', fontStyle: 0 }

When I loaded the shellsession grammar file into VS Code, the same problem occurred. Therefore, it is even more likely that either the grammar file or vscode-textmate is the cause of this problem.

image

Upon further inspection, echo -n is correctly recognized as source.shell, so the shellsession grammar file seems to be correct. Perhaps this is a bug in vscode-textmate or shellscript grammer file? (Sorry if I'm thinking wrong)

image

Thanks for investigating @Robot-Inventor! In that case it's a grammar issue but not Shiki's, please report upstream. Once it get fixed upstream, Shiki will sync them back automatically.