API Examples
Event listener
The Code for IBM i API provides an event listener. This allows your extension to fire an event when something happens in Code for IBM i.
Available events
ID | Event |
---|---|
connected | When Code for IBM i connects to a system |
disconnected | When Code for IBM i is disconnected from a system |
deployLocation | When a deploy location changes |
deploy | When a deploy successfully finishes |
Running commands with the user library list
Code for IBM i ships an API (via VS Code command) that can be used by an extension to execute a remote command on the IBM i.
It has a parameter which is an object with some properties:
- Command can also use Promptable fields.
- When executing a command in the
ile
orqsh
environment, it will use the library list from the current connection.
The command returns an object:
You can also provide a custom library list and current library when executing a command in the ile
environment:
Running SQL queries
Code for IBM i has an API that lets you run SQL statements and get a result back.
Get members and streamfiles
It is possible for extensions to utilize the file systems provided by Code for IBM i.
openTextDocument
returns a TextDocument
.
Getting a member
Getting a streamfile
File system options
Both member
and streamfile
file systems support the following query parameters:
Name | Type | Description |
---|---|---|
readonly | boolean | Open the text editor in read only mode. Defaults to false . |
Connect to a system
It is possible for your API to automate connecting to an IBM i instead of the user using the connection view.
VS Code integration
Right click options
It is possible for your extension to add right click options to:
- objects in the Object Browser
- members in the Object Browser
- directories in the IFS Browser
- streamfiles in the IFS Browser
- much more
You would register a command as you’d normally expect, but expect a parameter for the chosen node from the tree view. Here is the sample for deleting a streamfile in the IFS Browser.
Following that, we need to register the command so it has a label. We do this in package.json
Finally, we add it to a context menu:
When adding your command to a menu context, there are lots of possible values for your when
clause:
view
can beifsBrowser
orobjectBrowser
.viewItem
can be different depending on the view:- for
ifsBrowser
, it can bedirectory
orstreamfile
- for
objectBrowser
, it can bemember
(source member),object
(any object),SPF
(source file) orfilter
.
- for
This allows your extension to provide commands for specific types of objects or specific items in the treeview.
Read more about the when clause on the VS Code docs website.
Views
Code for IBM i provides a context so you can control when a command, view, etc, can work. code-for-ibmi.connected
can and should be used if your view depends on a connection. For example
This will show a welcome view when there is no connection:
This will show a view when there is a connection:
FAQs
Getting the temporary library
Please remember that you cannot use QTEMP
between commands since each command runs in a new job. Please refer to instance.getConfig().tempLibrary
for the user temporary library.
Is there a connection?
You can use instance.getConnection()
to determine if there is a connection:
connected
context
If you refer to the Views section, you can make it so the view is only shown when connected. This means by the time the view is used, there should be a connection.
Examples
See the following code bases for large examples of extensions that use Code for IBM i:
vscode-ibmi environment variable
We provide environment variables so Code for IBM i can be controlled by managed environments. See Variables.