vscode_deno icon indicating copy to clipboard operation
vscode_deno copied to clipboard

Set Language ID on extensionless files with a deno hashbang

Open martin-braun opened this issue 2 years ago • 5 comments

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: https://github.com/denoland/deno/pull/1197#issuecomment-991470523 and https://github.com/denoland/deno/issues/5088

martin-braun avatar Jul 23 '21 23:07 martin-braun

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.

kitsonk avatar Jul 24 '21 00:07 kitsonk

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?

martin-braun avatar Jul 24 '21 14:07 martin-braun

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.

kitsonk avatar Jul 24 '21 21:07 kitsonk

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. :)

martin-braun avatar Jul 25 '21 00:07 martin-braun

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 avatar Jul 25 '21 01:07 kitsonk