zed icon indicating copy to clipboard operation
zed copied to clipboard

Typescript file with NodeJS shebang gets detected as Javascript

Open gwennlbh opened this issue 1 year ago • 9 comments

Check for existing issues

  • [X] Completed

Describe the bug / provide steps to reproduce it

I'm building a CLI with Typescript, but the resulting transpiled JS files will have to be executed by Node.

Shebang language detection is a feature (as per https://github.com/zed-industries/zed/issues/6089), but in that case it leaves me with plenty of linter errors and no autocompletion '^^

I'd argue that special-casing .ts file that have a javascript-matching shebang as typescript files would be the solution

Environment

Zed: v0.142.6 (Zed) OS: Linux Wayland endeavouros unknown Memory: 15.6 GiB Architecture: x86_64

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

No response

If applicable, attach your Zed.log file to this issue.

No response

gwennlbh avatar Jul 09 '24 10:07 gwennlbh

Hey, thanks for filling out this issue. For what it's worth, we always treat files with node shebang as JS files; see: https://github.com/zed-industries/zed/blob/main/crates/languages/src/javascript/config.toml#L4 I wonder if it's as easy as adding the same detection in TS config.toml (that currently doesn't specify any shebang: https://github.com/zed-industries/zed/blob/main/crates/languages/src/typescript/config.toml).

osiewicz avatar Jul 09 '24 11:07 osiewicz

I came here to report this same issue. Is there anything I can do to help move this forward?

Tobbe avatar Aug 29 '24 11:08 Tobbe

Ran into this again. The workaround is to manually switch to TypeScript (by clicking the language selector down in the bottom right corner) and then restarting the language server.

Tobbe avatar Sep 15 '24 13:09 Tobbe

This is still an issue

Image

Tobbe avatar Mar 11 '25 18:03 Tobbe

Yep, still an issue in 0.181.6. Run into this commonly with AWS CDK projects which use this pattern by default.

christiangaetano avatar Apr 11 '25 23:04 christiangaetano

Here to report that this is still an issue with preview 0.188.2. Inconvenient problem that I didn't know the cause of. After about 30 mins of combing my settings.json, trying different things, comparing neovim... led me here.

nicholasq avatar May 23 '25 22:05 nicholasq

While we wait for a permanent resolution what is a temporary solution we can apply to avoid this problem at the moment?

rubencallewaert avatar May 26 '25 13:05 rubencallewaert

While we wait for a permanent resolution what is a temporary solution we can apply to avoid this problem at the moment?

you can see what I did in the commit that got referenced in this PR (scroll up), i basically added a (ugly) sed call in my package.json build script that adds the shebang to the compiled JS file

gwennlbh avatar May 26 '25 13:05 gwennlbh