Article
· Apr 3 2m read

Comfortable VSCode Auto Save and ObjectScript CompileOnSave settings

Hi - Recently I have been investigating an annoying situation whilst editing ObjectScript classes or routines in VSCode.

What was happening to me was, as I was typing in lines of code into my class (for example, adding a new Method, or changing the Class signature, or a block of code),  this would quickly get syntax checked, re-formatted, and compiled - inevitably, (since I would be mid-way through my typing), this would generate compilation errors.

Knowing that I was mid-way through adding code, I could simply dismiss this message, however, this soon got very annoying, and conditioned me to ignore the error (which is not a good thing).

Even worse, however, is that the compilation process also reformatted the document and sometimes broke what was previously well formatted lines of code (appearing below the line I was writing) - which required me to go into that area of the document and fix them back up.

What's going on ?

There are two settings at play here:

  1. VSCode's auto-save (files.autosave) settings which dictates wether to automatically save a document that has been changed, and if so, how long to wait before saving (files.autoSaveDelay)
  2. ObjectScript extension's compileOnSave (objectscript.compileOnSave), which determines wether after saving the document, this also imports into and compiles on the connected IRIS namespace.

Since I had autosave turned on, and on a short wait delay together with compileOnSave meant that partially edited code kept compiling, generating the above erros, and as mentioned, sometimes re-formatting good, pre-existing blocks of code.

In my case, I have settled on the following:

  1. AutoSave (files.autosave) off (autosaveDelay is ignored),  and
  2. CompileOnSave (objectscript.compileOnSave) on.

Now, when I'm happy with my edits (in my own time !), I press Ctrl-S, to save, import and compile my class, and look out for that pop-up message which has real meaning and purpose now.

You may choose a different combination, (for example, go ahead and Autosave after 5 minutes or so, accepting the code may not fully compile), however, I've found the above combination works for me, and hope that - if you are experiencing the same annoyance, then, this article may help you find your optimum configuration.

Thankyou to @Patrick Sulin, and @Raj Singh for pointing me in the direction of these settings !

Steve Pisani

Discussion (11)7
Log in or sign up to continue

This is helpful, but I feel like it's still just a workaround for the real problem, which is that the compiler is reformatting code.  Even if I allow that the compiler knows more about how code should be formatted than I do (it doesn't, if only because correct formatting is defined by personal opinion), it shouldn't be doing that until it's fully parsed and validated the code.  If it hasn't successfully parsed the code it can't possibly make good decisions about how it should be formatted.

Thanks for this post.  I have been using VS Code and have "files.autoSave": "afterDelay" set which seemed to have been working fine, however at some point while writing code it stopped auto saving which lead me down a path of trying to understand why functionality I had added was not appearing and why syntax errors were NOT going away after multiple edits in a local workspace.    Finally an explicit save prompted for a server overwrite and changed the server version of the cls file.  Using I4H 2024.2.   Wondering if anyone else has seen this?