helix icon indicating copy to clipboard operation
helix copied to clipboard

Highlighting is done for file named exactly a language file name extension (rs, py, …)

Open antoyo opened this issue 2 years ago • 3 comments

Summary

Hi. Helix will enable the Rust syntax highlighting for a file named rs, the Python one for py, etc. The config should include a leading dot to avoid this. Thanks.

Reproduction Steps

I tried this:

  1. hx rs
  2. Type fn.

I expected this to happen:

No syntax highlighting.

Instead, this happened:

fn got highlighted because helix loads the Rust syntax highlighter.

Helix log

n/a

Platform

Linux

Terminal Emulator

alacritty 0.12.0 (5a728195)

Helix Version

helix 23.03

antoyo avatar May 12 '23 15:05 antoyo

This is caused by this check: https://github.com/helix-editor/helix/blame/06d7f5d100fdcc99f4cdfda879898b2d488d8d7c/helix-core/src/syntax.rs#L643.

For the most part file types are already treated as extensions. We have the { suffix = "..." } syntax for matching the rest of the filename. I wonder if we should remove this check and simply convert all files that check the entire file-name (like poetry.lock for toml) to use suffix matching.

What do you think @the-mikedavis? I saw in the blame that you introduced that syntax.

I think /<filename> should always exactly match the filename right?

pascalkuthe avatar May 12 '23 15:05 pascalkuthe

There is some more discussion of this in https://github.com/helix-editor/helix/issues/5869. Using suffix for full filenames could be a nice workaround to avoid introducing breaking changes or new file-type formats but it seems a little hacky to me: I would prefer having a { filename = "poetry.lock" } over using suffix

the-mikedavis avatar May 12 '23 22:05 the-mikedavis

Ah I wasnt aware of the discussion there. From the issue title I wouldn't have looked there.

Using the filename syntax looks quite nice and is my favorite variant but would require a breaking change to the current behavior. If we want to avoid the breaking change an alternative could be to just add {extension = "rs" } instead and keep the current syntax unchanged.

It's not a huge deal but can cause weird bugs when a language uses a common filename (like res). Especially if the TS grammar isn't super robust. So I would Kean towards trying to fix this somehow.

pascalkuthe avatar May 12 '23 23:05 pascalkuthe

This was fixed in https://github.com/helix-editor/helix/pull/8006

the-mikedavis avatar Mar 01 '24 15:03 the-mikedavis