IDL on Visual Studio Code - ITA-Solar/solo-spice-ql GitHub Wiki

This page describes the settings we want to use for the auto-formatting feature in Visual Studio Code.

Table of contents generated with markdown-toc

Code formatting

In short

Setup

If we want to use autoformatting of the code, it makes sense to allow the plugin to format on save. See here for how to do it:

https://interactive-data-language.github.io/vscode-idl/code-comments/formatting/setup.html

It is possible to disable the 'format-on-save' feature. At the developers' request, a button does the formatting. However, then the code won't always be formatted.

An IDL-unspecific option for format-on-save exists as well here: editor.formatOnSave. Although this doesn't have to enabled when the IDL-specific one is enabled.

Formatting configuration

The description and default values of the formatting configuration can be found here:

https://interactive-data-language.github.io/vscode-idl/code-comments/formatting/configuration.html

We decided to use these values:

{
  "autoDoc": false,
  "autoFix": false,    -- NON-DEFAULT --
  "eol": "lf",
  "styleAndFormat": true,
  "tabWidth": 2,
  "style": {
    "quotes": "none",    -- NON-DEFAULT --
    "methods": "dot",
    "keywords": "lower",
    "properties": "camel",
    "control": "upper",    -- NON-DEFAULT --
    "numbers": "lower",
    "hex": "lower",
    "octal": "lower",
    "binary": "lower",
    "routines": "camel",    -- NON-DEFAULT --
    "routineMethods": "camel",
    "systemVariables": "lower",
    "structureNames": "pascal",
    "localVariables": "match"
  }
}

We don't want default values because:

  • "autofix": It mainly adds COMPILE_OPT to each function and procedure if not present. If present, it doesn't change anything, i.e. it does NOT add option IDL2. If not present it adds it with the option IDL2. It also corrects all brackets to square-brackets if it thinks they come after a variable. But this 'variable' may well be a function, but a real variable with the same name exists in the vicinity. So manual checking is necessary.
  • "quotes": We don't like strings like 'I don''t like it', instead of "I don't like it", so we leave the quotes as is. But we prefer single quotes.
  • "control": It makes the code more readable if these control commands (IF, FOR, BEGIN, END) are in capital letters. Everything else is already in lower letters.
  • "routines": some routine's definition is written in all capital letters, some not. With this option they will be reformatted to lower letter when used in other code.

Add IDL paths

This option allows to add paths to the IDL path. It is important to include solarsoft to be able to run our software. That also means that these added paths will be parsed, whenever one starts Visual Studio Code. The more files, the longer it takes. So add here only the subdirectories of the solarsoft directory that you need.

These are the paths to the synced solarsoft repository, in which Stein Vidar added a line to disable reporting of problems. Spice quicklook software is explicitly not included in this list, since when I use and edit it, I have it open in the workspace. The workspace is always parsed and problems are reported.

"idl.IDL.path": [
  "+/mn/alruba2/astro/local/opt/solarsoft_vscode/gen/idl",
  "+/mn/alruba2/astro/local/opt/solarsoft_vscode/iris/idl",
  "+/mn/alruba2/astro/local/opt/solarsoft_vscode/hinode/eis/idl",
  "+/mn/alruba2/astro/local/opt/solarsoft_vscode/so/gen/idl/sunspice",
  "+/mn/alruba2/astro/local/opt/solarsoft_vscode/so/spice/idl/pipeline",
  "+/mn/alruba2/astro/local/opt/solarsoft_vscode/so/spice/idl/planning",
  "+/mn/alruba2/astro/local/opt/solarsoft_vscode/so/stix/idl"
]

You can also add paths to the IDL_PATH environment variable, for which by default problems are NOT reported. This behaviour can be controlled with this setting: idl.problems.includeProblemsFromIDLPath.

Add environment variables here: idl.IDL.environment

Ignore Problems

Ignore specific problems via settings

There is an option in the idl plugin extension settings (idl.problems.ignoreProblems) where it is possible to add some problems, which should never be reported. There we can add

  • no-comp-opt

to get a lot less 'problems'.

There is a bug in the IDL extension (bug report). That means some problems are still reported even though we set the line ; idl-disable, which should suppress all problem reporting. This bug may be resolved in the future.

Meanwhile you can turn those warnings off by adding:

  • duplicate-func
  • duplicate-pro
  • duplicate-func-method
  • duplicate-pro-method
  • duplicate-struct
  • no-idl2

but then you may miss some real duplicates.

Ignore all problems of a file

One can add a line to a file

; idl-disable

this would disable reporting of any problems within this file.

Stein Vidar adds this line to all files in the synced solarsoft directory. We can turn this script off once this feature request is resolved.

Outcome

See how the Autoformat would change the code:

Autoformat-commit

Autofix-commit

Known issues

  • spice_xcfit_block.pro and spice_fitshead2struct.pro create error message: 'Unable to format code due to syntax error or problem in file'

I am quite sure this is due to the fact that brackets are used instead of square brackets in many places, mostly in conjunction with size(). This would need to be fixed manually, but no hurry, since we might want to replace the original files eventually.

Old notes

IDL on Visual Studio Code ‐ Old notes

⚠️ **GitHub.com Fallback** ⚠️