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

Set Language ID on extensionless files with a deno hashbang #475

Open
martin-braun opened this issue Jul 23, 2021 · 5 comments
Open

Set Language ID on extensionless files with a deno hashbang #475

martin-braun opened this issue Jul 23, 2021 · 5 comments
Labels
dx enhancement New feature or request

Comments

@martin-braun
Copy link

martin-braun commented Jul 23, 2021

I like Deno for its capability to replace NodeJS in the long run. But what I like even more on it is the fact that it can do so much more. I'm very interested in the fact of writing cross-platform scripts that replace shell / batch scripts, like one can do with Python, for instance. One of the things that should be possible is not providing a filename extension and instead use a shebang. Also there should be a way to define if this is JS or TS by a comment.

Shebangs already work and I guess a way to define the language, too₍₁₎. What I miss is this extension picking up. Whenever I open a deno script file without filename extension I end up with no highlighting:

Screen Shot 2021-07-24 at 01 42 08

Can this be fixed, so it parses the first two lines and knows to use JS or TS syntax highlighting, automatically?

I know that I can change the language, manually, but this will be forgotten once I close the file, again.

⁽¹⁾ This was false information and I edited the linked answer, because it is not implemented yet. References: denoland/deno#1197 (comment) and denoland/deno#5088

@kitsonk
Copy link
Contributor

kitsonk commented Jul 24, 2021

This is not something vscode_deno can control. This is a vscode thing, as editors choose the underlying language. Try selecting the language in vscode and see what happens.

@martin-braun
Copy link
Author

martin-braun commented Jul 24, 2021

Try selecting the language in vscode and see what happens.

@kitsonk

I know that I can change the language, manually, but this will be forgotten once I close the file, again.

So in conclusion, I can set it, but as soon as I close the file and re-open it, it will be opened as text, again. So you want to say that this is an issue of vscode, not vscode_deno?

@kitsonk kitsonk added the enhancement New feature or request label Jul 24, 2021
@kitsonk
Copy link
Contributor

kitsonk commented Jul 24, 2021

So you want to say that this is an issue of vscode, not vscode_deno?

The determination of how a document is displayed for editing, including what syntax highlighting occurs, is the responsibility of an editor, not something an extension can control.

It does appear though that vscode has an API for changing the language ID of a file: setTextDocumentLanguage which should allow the extension to detect things in an extensionless file and change the langauge ID. One small problem is then activating the extension on extension-less files, but it looks like it is possible.

@martin-braun
Copy link
Author

martin-braun commented Jul 25, 2021

The determination of how a document is displayed for editing, including what syntax highlighting occurs, is the responsibility of an editor, not something an extension can control.

@kitsonk In the very basic scenario I agree (reading the extension and shebang, i.e. shell and python files). I suspect this is done by the editor, exclusively. It starts to get questionable for the second line that defines the language is JS or TS.

It does appear though that vscode has an API for changing the language ID of a file: setTextDocumentLanguage which should allow the extension to detect things in an extensionless file and change the langauge ID. One small problem is then activating the extension on extension-less files, but it looks like it is possible.

@kitsonk So what would be your suggestion? Should I make an issue over at vscode, referencing this issue? No matter I open another issue or not, I think the vscode team would take longer to implement this feature, so it sounds very good that it is possible in the extension, too.

Thank you for consideration. :)

@kitsonk
Copy link
Contributor

kitsonk commented Jul 25, 2021

No I've marked it as an enhancement for this extension. It is a low priority enhancement and there are still some open questions about implementation.

@kitsonk kitsonk changed the title Smart Language Detection Set Language ID on extensionless files with a deno hashbang Jul 25, 2021
@bartlomieju bartlomieju added the dx label Jul 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dx enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants