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

Incorrect highlighting with .fish files #205

Closed
orf opened this issue Sep 3, 2018 · 10 comments
Closed

Incorrect highlighting with .fish files #205

orf opened this issue Sep 3, 2018 · 10 comments

Comments

@orf
Copy link

orf commented Sep 3, 2018

Given the following small snippet of fish code:

test -n "$_CONDA_EXE"; or set _CONDA_EXE "$PWD/shell/bin/conda"

test -n "$CONDA_SHLVL"; or set -gx CONDA_SHLVL "0"

function __conda_add_prompt
  if set -q CONDA_DEFAULT_ENV
      set_color normal
      echo -n '('
      set_color -o green
      echo -n $CONDA_DEFAULT_ENV
      set_color normal
      echo -n ') '
  end
end

Syntect seems to render the following, at least through bat:

image

Not sure if this should be reported here or in bat, so sorry if this is the wrong place 👍

@keith-hall
Copy link
Collaborator

for reference, it seems like bat is using the ShellScript/bash syntax from https://github.com/sublimehq/Packages to highlight .fish files. I'm not at a computer right now to see how it looks in Sublime Text, to help determine if it is a problem with the syntax definition or syntect, but if nobody beats me to it, I will hopefully be able to check in about 12 hours time. Thanks for reporting btw.

@sharkdp
Copy link
Contributor

sharkdp commented Sep 3, 2018

This is how it looks like in Sublime Text:
image

It looks slightly different (I'm not quite sure if my Sublime Text uses the same version of sublimehq/Packages as bat) but the main issue is definitely that the Fish syntax is quite different from Bash syntax. So it really looks like a sublimehq/Packages issue.

Syntect users could potentially solve the problem by adding a dedicated Fish syntax (and possibly also Zsh), but I'm not sure how file_extension conflicts are handled (which .sublime-syntax takes precedence?)

@keith-hall
Copy link
Collaborator

I believe precedence works in Sublime Text by lexicographical order https://github.com/guillermooo/sublime-undocs/blob/a571f5ba987176607f12bb141965bf4596775eeb/source/extensibility/packages.rst#id62, so a package named ShellScriptFish would take precedence over ShellScriptBash (for example) were they to have conflicting file extension mappings. Users of Sublime Text can also set a preference to open particular extensions with a particular syntax, which always takes priority over what is in the syntax definition.

@keith-hall
Copy link
Collaborator

in syntect, it seems the syntax definitions are searched in the order they are added to the syntax set, and the first one with a matching file extension is used. Currently, I believe the syntax set builder which loads from a folder doesn't load the definitions in a deterministic order. We could perhaps change it to behave similar to how syntest orders/sorts the syntax test files. Then, perform the search in reverse to get the same behavior as Sublime Text of lexicographical order overrides.

@robinst
Copy link
Collaborator

robinst commented Sep 4, 2018

Sounds good. I'm not sure if that's the loading code that you're talking about, but there is sorting here:

https://github.com/trishume/syntect/blob/master/src/parsing/syntax_set.rs#L336

So maybe it's just about doing the search in reverse.

@keith-hall
Copy link
Collaborator

You're right, somehow I didn't notice that earlier. 👍 It looks like the first_line_match caching will be a bit more complicated, due to the way syntaxes can be added after some first line match entries are cached, so just caching in reverse isn't quite going to be suitable I think?

@robinst
Copy link
Collaborator

robinst commented Sep 4, 2018

Ah, we can actually change how that code works now that SyntaxSet is immutable and we have SyntaxSetBuilder. The length check is no longer necessary, we just have to initialize it lazily.

If you're not comfortable changing it, I can look at raising a PR to change it tomorrow.

@keith-hall
Copy link
Collaborator

oops, just realized I forgot to comment - if you could spare a few mins to raise a PR for this, that'd be grand @robinst, thanks - save me botching it and thus taking more of our time to review and fix it ;)

@robinst
Copy link
Collaborator

robinst commented Oct 13, 2018

@keith-hall done :) #216

I'll leave the actual logic change to you, so that I don't botch it and take your time to review and fix it ;)

@Enselic
Copy link
Collaborator

Enselic commented Nov 10, 2021

I haven't double checked, but sounds as if the merged PR #217 fixed this problem, so I'm closing this issue now.

Feel free to reopen if I am mistaken of course.

@Enselic Enselic closed this as completed Nov 10, 2021
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

No branches or pull requests

5 participants