0

I've been trying to automate a lot of the manual processes in Codesys and found out they have an API that lets you use ironpython scripts to interact with the IDE. I cannot make heads or tails of their API documentation, and would like an interactive editor that would let me browse the libraries they provide.

I came across this post/script which (I think?) exports all the classes and functions available into a json file.

#dumps an API in json format for python
import clr

from System.IO import Path

path = Path.Combine(Path.GetDirectoryName(__file__), "api.json")

print("Dumping to " + path)

system.dump_scripting_api(path)
system.exit(0)

I've created the vs-code template using yeoman as a new language type, but got a little lost after that.

I've put the generated api.json file in the syntaxes folder and changed the package.json to point to the api file, but I get errors. Not sure what to fill out for the fields of grammar scope.

What format does the JSON need to be in for intellisense to work?

What is grammar.scope?

The api.json is about 272000 lines, with the main headings (and an example of a type) being:

Metadata
Entrypoints
Types
    {
          "Id": "Member Void write_message(_3S.CoDeSys.Core.Messages.Severity, System.String, _3S.CoDeSys.ScriptEngine.BasicFunctionality.IScriptTreeObject, Int64, Int16) of Type _3S.CoDeSys.ScriptDriverSystem.SystemImpl, ScriptDriverSystem.plugin, Version=3.5.16.30, Culture=neutral, PublicKeyToken=null",
          "Attributes": "PrivateScope, Public, Final, Virtual, HideBySig, VtableLayoutMask",
          "Parameters": [
            {
              "Id": "Parameter _3S.CoDeSys.Core.Messages.Severity severity of Member Void write_message(_3S.CoDeSys.Core.Messages.Severity, System.String, _3S.CoDeSys.ScriptEngine.BasicFunctionality.IScriptTreeObject, Int64, Int16) of Type _3S.CoDeSys.ScriptDriverSystem.SystemImpl, ScriptDriverSystem.plugin, Version=3.5.16.30, Culture=neutral, PublicKeyToken=null",
              "Name": "severity",
              "Type": "_3S.CoDeSys.Core.Messages.Severity, MessageStorage, Version=3.5.16.0, Culture=neutral, PublicKeyToken=null"
            },
            {
              "Id": "Parameter System.String stMessage of Member Void write_message(_3S.CoDeSys.Core.Messages.Severity, System.String, _3S.CoDeSys.ScriptEngine.BasicFunctionality.IScriptTreeObject, Int64, Int16) of Type _3S.CoDeSys.ScriptDriverSystem.SystemImpl, ScriptDriverSystem.plugin, Version=3.5.16.30, Culture=neutral, PublicKeyToken=null",
              "Name": "stMessage",
              "Type": "System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
            },
            {
              "Id": "Parameter _3S.CoDeSys.ScriptEngine.BasicFunctionality.IScriptTreeObject obj of Member Void write_message(_3S.CoDeSys.Core.Messages.Severity, System.String, _3S.CoDeSys.ScriptEngine.BasicFunctionality.IScriptTreeObject, Int64, Int16) of Type _3S.CoDeSys.ScriptDriverSystem.SystemImpl, ScriptDriverSystem.plugin, Version=3.5.16.30, Culture=neutral, PublicKeyToken=null",
              "Name": "obj",
              "Type": "_3S.CoDeSys.ScriptEngine.BasicFunctionality.IScriptTreeObject, ScriptEngine2, Version=3.5.16.1, Culture=neutral, PublicKeyToken=null"
            },
            {
              "Id": "Parameter Int64 position of Member Void write_message(_3S.CoDeSys.Core.Messages.Severity, System.String, _3S.CoDeSys.ScriptEngine.BasicFunctionality.IScriptTreeObject, Int64, Int16) of Type _3S.CoDeSys.ScriptDriverSystem.SystemImpl, ScriptDriverSystem.plugin, Version=3.5.16.30, Culture=neutral, PublicKeyToken=null",
              "Name": "position",
              "Type": "System.Int64, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
            },
            {
              "Id": "Parameter Int16 length of Member Void write_message(_3S.CoDeSys.Core.Messages.Severity, System.String, _3S.CoDeSys.ScriptEngine.BasicFunctionality.IScriptTreeObject, Int64, Int16) of Type _3S.CoDeSys.ScriptDriverSystem.SystemImpl, ScriptDriverSystem.plugin, Version=3.5.16.30, Culture=neutral, PublicKeyToken=null",
              "Name": "length",
              "Type": "System.Int16, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
            }
          ],
          "ReturnValue": null,
          "Name": "write_message",
          "MemberType": "Method",
          "Type": "System.Void, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
        },

Assemblies
TypingImportHints
ExtensionInformations
Log

Gene Parmesan
  • 211
  • 2
  • 8
  • So if I understood it correctly, you want to make a VS Code extension to provide linting for the ScriptEngine API? – Guiorgy Mar 10 '23 at 17:51
  • I believe so, yes. Not 100% sure on a lot of modern software development terminology. I would like VSCode to evaluate my syntax and let me browse functions in the library. – Gene Parmesan Mar 10 '23 at 18:26

0 Answers0