Inform 6 extension for VS Code

If you’re interested in adding a debug engine, the one in zilf.zil-language should be fairly easy to adapt, although it only supports Z-machine games (using ZLR as the interpreter).

1 Like

Version 0.2.0 of Inform 6 for VS Code has been released!

It includes some improvements in the syntax highlighting, but the main new feature is the ability to compile a story file from within VS Code by using the “Compile with Inform 6” in the command in the palette (ctr/cmd + shift + P), by clicking on the play button at the top right or by right-clicking on an Inform 6 file in the explorer.

Compiler errors and warnings will then be displayed in the Problems panel and in the source.

vscode-inform6-error

By default, the extension assumes the compiler is in your PATH, but you can specify a custom path to the compiler in the settings.

The settings also allow to add additional arguments when compiling (by default the command compiles with no args), but it is better to add ICL commands in your Inform file, with !% comments.

Compiling from VS Code is mainly for testing the story. When releasing it, it’s better to use Inform directly from the command line, and using the right arguments (e.g. -~D).

(I’ve only tested on Windows, so let me know if you have any problem.)

The full changelog is available in the repo.

As usual, any comment and bug reports are welcome!

1 Like

This is great. I have been using it with my current WIP over the last week.
I was using using JIF & WIDE and IMAGINATE before those, but other than not being able to run the interpreter directly, I have found no problems.

Suggestions for future (depending on degree of difficulty to implement)

  • Setting a path to the interpreter (eg. winfrotz or gargoyle) to allow testing of the Z5 file.
  • A way to allow the user to change the colours of the different highlights.

A very pleasing and usable extension to VS Code. Much appreciated.

Thanks! :blush:

About your suggestions:

I have the plan to write an extension that will make it possible to open a Z-machine or Glulx file directly in VS Code next to your source. (A bit like when you preview a Markdown file in VS Code). I have other things to do right now though, so it’ll have to wait.

If you really think it’s necessary, it should be quite easy for me to make the extension open the file automatically at the end of the compilation.

In the meantime, if you have a command line interpreter (i.e. dumbfrotz), you can play your story in VS Code’s integrated terminal.

The colours are normally handled by your current theme. The main thing I can do is i.e. make a word be coloured as a keyword instead of a class. But ultimately it’s the active theme that chooses how a keyword or a class should be coloured.

If you have some specific things that trouble you in the colours, please tell me and I’ll see what I can do!

Thanks for the response. They were only suggestions - no urgent need for any of them. I open File Explorer and double click the .Z5 file and test what I need. It doesn’t take much longer.
I didn’t realize the colours were tied to the themes. I’ll have a play around to see if there is any other arrangement I might prefer. However, I can live with the way it is as it gives me all I need for now.

Thanks again for your work on this. I’ll watch for further updates if and when they occur.

Version 0.3.0 of Inform 6 for VS Code has been released!

The main new feature is that we can now automatically open story files just after compilation. When the new openStoryAfterCompilation setting is set to external, VS Code will attempt to open newly created story files with the default application associated with its extension (e.g. winfrotz for .z5, or Lectrote for .ulx).

(This is for you, @R2T1!)

Apart of that, there were quite a lot of internal changes (see the changelog), so if you encounter a bug, please report. :slight_smile:

1 Like

WOW. I wasn’t expecting this so soon. Many thanks for this. Being able to see/test my code as I write is great.
Excellent job.

1 Like

Version 0.4.0 of Inform 6 for VS Code has been released!

The main change is that the button at the top right now compiles the story in debug mode (with -SD) by default. To release a story, you can press alt before clicking: it will be compiled with -~S~D.

(Both commands are still available in the palette and by right-clicking a file, of course.)

Also, stories in formats other than Z5 are now properly opened after compilation. (Previously, only Z5 files would be opened.) Thanks @JasonLautzenheiser for spotting this bug!

2 Likes

I decided to make a new topic for the Inform 7 extension, since it’s quite different from the Inform 6 one, and they are releases independently.

The new topic is here, with a new release of the Inform 7 extension!

Thanks so much for this! I’ve been debating whether to use ZIL or I6 for my next project and am leaning toward I6 primarily because of the C-like syntax. I’ve never touched lisp so it’s a bit more intimidating.

3 Likes

Version 0.5.0 of Inform 6 for VS Code has been released!

Some snippets are now available when editing Inform 6 source, for routines and most statements. See the README for the full list. And tell if you want other snippets to be included.

(For those who don’t know what snippets are: you start typing a snippet’s name, say for, select it in the suggestion list, and a prefilled for loop is inserted. You can then navigate between each “fields” of the loop with tab to complete it with your variable name and so on.)

Also, correct indentation is automatically added when inserting a new line while the cursor is inside the head of a routine. Say, if you have

[ Main;_]

(with the underscore denoting the cursor’s position) then press enter, you’ll get

[ Main;
    _
]

Finally, new settings have been added so that a compiled story can be automatically opened with VS code. (The IF Player extension is recommended in that case).

2 Likes

Thank you, this is really nice !

One feature suggestion I have would be to have the “outline” show classes and objects and such to quickly be able to skip to one. Unfortunately I think this is not too easy for Inform, as objects aren’t defined with fixed keywords but with any custom class name.

I have no intention of stealing focus in this thread from the inform 6 extension which I’m really happy to see progressing but the outline feature you ask for can be provided via the inf6langtools extension already. It provides an outliner with goto-definition capability and also goto-definitions on object names within the code itself so you can jump from one source file to another via a ctrl/cmd-click. Hope it will be of use.

1 Like

You’re not stealing anything! In fact, I was going to point to your extension before I saw you were replying.

I admit I totally forgot to try it out. The next time I update my extension, I’ll mention yours in the README.

1 Like

Would it be possible to extend this for PunyInform? I could fork your amazing extension, which I use on a daily basis, but maybe there is a way to incorporate the changes and additions from Puny. It’s not much but some of the library features I’d love to have more highlighted so that they differentiate from the game-specific code. Anything that is related to Punys built-in extensions, like cheap_scenery for example, the reactive attribute, and essential library routines like scope_modified and update_moved. And thank you so much for the work you’ve put into this. I love this extension.

1 Like

The thing is, the highlighting is done by a static JSON file, so it’s impossible to detect if the author if using the standard library or PunyInform and highlight accordingly. So if we add the PunyInform-specific functions, they’ll be highlighted for the standard library users too, which is not ideal.

Actually, I even hesitated to highlight the standard library functions since authors can write Inform 6 programs without a library! (And when the standard library is updated, I have to update the extension, too, which is a bit of a pain.) So I’m a bit wary of adding support to a specific library. After all, why not support other ones too, like Platypus or Triform, while we are at it? (Admitedly, they might not be as widely used.)

I can see 2 solutions for what you’re asking:

  • Create a separate extension that injects some grammar in the Inform 6 syntax file (see in the VS Code documentation). The drawback is that you have to enable or disable this extension in your workspace depending on your project (if it’s using Puny or not). Or maybe it should be possible to be able to select if you want to use Puny highlighting on a per-file basis, in which case it could be included in the same extension.
  • Programmatically detect what functions exists and highlight them accordingly. That what a language server like Language Server for Inform 6 (+clients for eclipse and vscode) can do. (But that’s not what you are asking, since you only want to hightlight the functions from the library.)

I’ll have to think about it. (And maybe others can give their insights too!) In the meantime, you could write a bug report in the extension repository, listing the PunyInform-specific functions/attributes/etc. so that I can try things when I have time.

And thanks for the nice words, it really appreciated! :blush:

1 Like

I was wondering about this, as well. I actually use Textpad, but the same principle applies with @Natrium729’s VSCode extension. Would it be feasible to use a different file name extension (such as pun) for PunyInform games and leave the inf extension for Inform 6 and Glulx games?

well, I think that this remnant of the mess of gate$, the 3-letter extension ought to disappear OFA, so if one really want an extension for puny, ought to use a .4 extension, like .pinf

(I actually differentiate by directory, here being a …/wrk/inf6/puny directory, I consider this a good usage)

Best regards from Italy,
dott. Piergiorgio.

The Inform 6 system really is a language and library, and PunyInform only replaces the library. Just like for all just about all other programming languages, the language decides the file extension, not the library. And then there are library files and extensions which end with “.h”, which makes most text editors go into C mode.

Also note that the compiler isn’t neutral in this, as it will append “.inf” automatically if you don’t provide a file extension (".h" for regular includes).

Could the extension have different modes that you could switch between with a keypress and/or menu option? If you’re using the standard library mode while editing a PunyInform file, it won’t really be a disaster - almost all of it is the same. When you notice it’s the wrong mode you can press a key a change it. And you could choose the default mode to use, so for those who almost exclusively use one or the other, it will almost always be correct from the start.

2 Likes

It should be possible in VS Code, yes. As you mentioned, .h is also used for C, so VS Code gives you the choice between C and Inform and you can set the default to use. It should be possible to make it so there is a “Inform 6 - PunyInform” and even a “Inform 6 - no library” in the following menu:

image

But I’m still pondering if it’s a good idea, as I explained above. It makes more work for me to keep the extension up to date, but not much either. And people can still make merge request when a new version of Puny or other library is released.

And since there’s demand for that, I guess I’ll try, at least.

2 Likes