I've recently been working on some tools to get a better integration in VSCode for Opus (JScript) scripting.
This revolves around:
- Updated dopus.d.ts file to get intellisense, type validation and Opus documentation insights in VSCode
- Ability to extend the typings to your local include files (so that their specific functions can also get intellissense)
- A few VSCode tasks to automate these actions,
- A few "opus oriented" code snippets that can be triggered from within VSCode (enumerations, simple dialogs, ...)
Everything is available from the following github link:
From there, you'll also find (as described on github) two usefull resources:
- A
.opusscriptinstall file (that you can install through the Script Management dialog)
- A
.dcf file which provides a small menu to get you started. That menu contains an "Install" entry. This will go fetch the latest version from github and have it installed in your local "Script Addins" folder.
Some remarks:
- This will create a
.vscode folder in your /dopusdata/Script Addins folder (required for VSCode) containing tasks, snippets, ...
- This will also create a
OpusDevTools folder in /dopusdata/Script Addins folder (containing the typings, some readmes, ...).
- The core dopus.d.ts file has been created through parsing of the html documentation of Opus, reworked by an AI (mostly) to search for optional parameters/arguments, and then reviewed by me to fix everything that has gone wrong either with the original parsing or the AI "contribution". Yet, Opus object model is quite extensive, and as a consequence:
- There might still be errors. Do not hesitate to report them here (or on github).
- There's still work to do on reformatting the JSDoc part of the file.
Hope this can be useful to some !!
8 Likes
Really cool idea. Having autocomplete is very useful.
It would be interesting if it were possible to turn it into a VSCode plugin and distribute it via their marketplace.
I didn't get the point of the OpusDevTools, and you have many commands defined for VSCode. What is the purpose of this?
These are new Opus commands to help glue this dopus.d.ts into VSCode:
OpusDT_FixTypes: This command can be used from VSCode (through a vscode task, which is also provided) to decorate the file you're currently editing:
- Transforms your include directives (if any) in the form that is not offending the type checker (
//@@include ...)
- Decorates with JSDoc all the event type Opus functions that you may have in your code (e.g.
OnActivateLister, OnAddColumns, OnAddCommands, OnAfterFolderChange, ...). Doing so, you'll get intellisense on the parameters of these commands.
- Decorates with JSDoc your own new commands or columns methods (the one you declare in
OnAddColumns and OnAddCommands): this allow intellisense on the scriptCmdData parameters of your custom commands entry points (and same with columns).
- Finally, it can also be used directly from Opus (on selected files) for batch processing (in that case, the files are transformed in a temporary folder so you can check no harm has been done). In both cases, files are first backed up to avoid data loss if transformation goes wrong.
OpusDT_GenerateIndex: This one will help glue all the .d.ts files in a single entry point (with references to all other required .d.ts files). The files taken into account:
dopus.d.ts: the core with Opus object model
global.d.ts: declares the (currently) two global objects DOpus and Script that are available from anywhere in scripts.
- The include files that are coming with
OpusDevTools.js, the ones you might have built for your own include files (that you have to put inside /dopusdata/Script Addins/OpusDevTools/typings/includes/)
user_custom.d.ts: If you have personal .d.ts files you want to be included too, add references in a file named user_custom.d.ts (in /dopusdata/Script Addins/OpusDevTools/typings), and it will be taken into account.
- In the end, the
index.d.ts file references all of the above for the maximum representation of typings. That's the index.d.ts file which is given to vscode as the entry point for typings check, intellisense, ... (in the jsconfig.json which is in the Script Addins folder)
OpusDT_Install: Fetches latest files from Github (typings, vscode settings/snippets/tasks) and installs them in your setup.
- For VSCode sensible files (tasks.json, settings.json): it should detect if you already have one and propose a
.template file in that case. When updating, it will detect if your current file is the one that was installed previously and overwrite in that case (using a manifest file).
- The reference index file discussed above is also generated by the install procedure.
OpusDT_GenerateMinifiedTypings:
- This one is a bit special. It has to do with creating your own
.d.ts files for your custom include files. If such files are big with many functions, objects, etc ..., it might be interesting to use an AI to generate at least a first draft. If you want that to use the actual Opus object model, you'll need to provide it to the AI.
- Then the problem comes with the full dopus.d.ts file which contains a ton of comments coming gtom the doc (which help with intellisense), which will overload the AI and use a ton of tokens. So this command is building a stripped/minified version of
dopus.d.ts that contains only the type definitions (no more comments).
1 Like