zed icon indicating copy to clipboard operation
zed copied to clipboard

Request to add feature setting match file type by using regex.

Open hoangnx30 opened this issue 2 months ago • 7 comments

Check for existing issues

  • [X] Completed

Describe the feature

Currently, I saw file_types only matches word by word. Can team support to match by regex?

"file_types": {
    "Dockerfile": [
      "Dockerfile",
      "Dockerfile.dev",
      "Dockerfile.prod",
      "Dockerfile.uat"
    ]
  }

------> It worked.

"file_types": {
    "Dockerfile": [
      "Dockerfile",
      "Dockerfile.*",
    ]
  }

-----> it didn't work

If applicable, add mockups / screenshots to help present your vision of the feature

No response

hoangnx30 avatar Apr 19 '24 08:04 hoangnx30

I think a better alternative would be to support matching via globs, not regexes; https://docs.rs/glob/latest/glob/ It's less powerful than a regex, but it should suffice for your use case.

osiewicz avatar Apr 19 '24 08:04 osiewicz

Nice, anyone can help me, will be my first issue, I can try fix it.

guibes avatar Apr 20 '24 12:04 guibes

Sure! For starters, this function does path filtering: https://github.com/zed-industries/zed/blob/74241d9f935158dc113040c3d2c8b3785fdf0f09/crates/language/src/language_registry.rs#L472 user_file_types is a deserialized content of file_types, e.g. for the example provided in original post:

"file_types": {
    "Dockerfile": [
      "Dockerfile",
      "Dockerfile.dev",
      "Dockerfile.prod",
      "Dockerfile.uat"
    ]
  }

user_file_types is gonna be Some({"Dockerfile": [ "Dockerfile", "Dockerfile.dev", "Dockerfile.prod", "Dockerfile.uat" ]}).

It then follows that all you have to do is change the code within the call to any to use globs instead: https://github.com/zed-industries/zed/blob/74241d9f935158dc113040c3d2c8b3785fdf0f09/crates/language/src/language_registry.rs#L488

osiewicz avatar Apr 22 '24 11:04 osiewicz

I opened this PR #10960. I'm a newcomer, so please if someone can review and give me a feedback.

guibes avatar Apr 25 '24 00:04 guibes

I believe the issue I am running into with my angular LSP is similar to this one. From what I gather, the Angular LSP should only be applied to HTML files that have a component prefix to the suffix IE app.component.html I made a branch that fixed this issue, but reading here it looks like it's not the desired solution. However, pulling down PR #10960 I am not seeing how I can get the LSP to recognize angular files.

Edit: After looking into this some more, I see that this only effects language overrides in the config, so it's not exactly what I am looking for in regard to my language server issues.

nathansbradshaw avatar May 02 '24 19:05 nathansbradshaw

I made PR #12043 to work on this. I picked up the work from where @guibes stopped, taking note of the reviews from @osiewicz.

farayolaj avatar May 20 '24 01:05 farayolaj

This is gonna land in next Preview on Wednesday, 22.05. Thanks for getting this across the line @farayolaj :)

osiewicz avatar May 20 '24 08:05 osiewicz