pgourlain / vscode_erlang

Erlang support for Visual Studio Code
MIT License
129 stars 46 forks source link

Support escript shebangs #131

Open Zalastax opened 5 years ago

Zalastax commented 5 years ago

When writing an escript, the file will start with a shebang, e.g. #!/usr/bin/env escript. It would we very nice if the shebang didn't cause the plugin to fail completely.

pgourlain commented 5 years ago

Hi,

Sorry for the delay.

I am not used to using escript, can you give me detail about it ? so i take a sample from erlang documention... but plugin didn't failed...

here is my sample :

!/usr/bin/env escript

%% -- erlang -- %%! -smp enable -sname factorial -mnesia debug verbose main([String]) -> try N = list_tointeger(String), F = fac(N), io:format("factorial ~w = ~w\n", [N,F]) catch : -> usage() end; main() -> usage().

usage() -> io:format("usage: factorial integer\n"), halt(1).

fac(0) -> 1; fac(N) -> N * fac(N-1).

Zalastax commented 5 years ago

The issue is quite weird it seems.

I took your sample and wrote it to a file test.erl. Setting the language to Erlang, everything works. However, if I restart the editor:

Switching the language to something else and then back to Erlang, the error disappears.

KornelH commented 3 years ago

Hi,

In the mentioned example the first line is not part of the language at any means and ignored by escript (used by Linux shell). Since I've got no error on the first line I guess it's solved in the meantime. The second line is exclusively for Emacs as it was the de-facto editor in the good old days, other editors treat is as a simple comment without no meaning. The third line is used by escript if present but it's a simple comment even for Emacs.

Extension .escript is now associated to erlang extension. If other extensions are preferred then a VSC extension like Shebang Language Associator could be handy.