Inform 6 extension for VS Code

So I just finished writing VS Code extensions for Inform 6 and 7. They only add syntax highlighting for the moment. Here are some features.

Inform 6

https://marketplace.visualstudio.com/items?itemName=natrium729.inform-6

  • Highlights .inf and .h files (comments, numbers, routines, keywords and directives, object declarations, strings).
  • Highlight characters, dictionary words and strings in different colours to help the author not mixing them up. Special characters in strings (^, ~, @:e and so on) are highlighted, too.
  • Highlights Inform 6 template files (.i6t, used by I7) correctly, with the paragraph headings and all.
  • Highlights Javascript in strings used as arguments in Vorple’s VorpleExecuteJavaScriptCommand and BuildCommand.

There are no snippets yet, but I plan to add them eventually. A language server for linting, auto-completion and so on would be very cool (I’m quite interested to tackle the challenge), but it won’t be anytime soon.

Inform 7

(I’ve made a specific topic for the extension. Updates for the I7 extension will be announced there!)

https://marketplace.visualstudio.com/items?itemName=natrium729.inform-7

I’m aware another extension already exists, but it made choices I didn’t like (for example, highlighting words such as “is” in sentences), and mine has more features. (And it seems the repo of the other extension isn’t public?)

  • Highlights .ni and .i7x files (story title, headings, comments, text and text substitutions, table names, documentation).
  • Highlight Vorple JavaScript commands, similarly to the I6 extension.
  • Highlights Inform 6 inclusions if the above extension is installed.
  • Highlights Preform files and inclusions.

A language server seems difficult to write because of the natural language. I may add snippets for the Standard Rules phrases.


I hope they will help people other than myself! And of course, comments, bug reports and other contributions are welcome!

11 Likes

Inform 6:
The “Dictionary” directive is no longer deprecated and is very useful.
It also lacks the property “before_implicit”.
Read David Kinder’s “ReleaseNotes.html” and David Griffith’s “ChangeLog” to get the latest modifications and additions to the Inform 6 language:
https://github.com/DavidKinder/Inform6
https://gitlab.com/DavidGriffith/inform6lib

I found this too:
lm_o
lm_s
lm_p (?)
#Ifnot
AskTo
additive (for the grammar of verbs)
compass_look
buffer (Array)
table (Array)
reverse (for grammar verbs)
JumpIn
JumpOn

Do you still think that version 6.12 of the Inform 6 library does not exist (especially the adaptation I made in French) or do you want to integrate these latest new features?

Just pushed a small update to the Inform 6 extension to take account of the features of newer I6 compiler and library.

It includes directives and functions that I forgot to add, and Glulx floating-point numbers. There are still a few minor things that are missing, but they’ll wait for the moment (except if it’s really important).

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