Guru: Getting Started With The Code 4 i Extension Within VS Code
January 22, 2024 Gregory Simmons
The Code for IBM i extension is growing in popularity and has certainly become my favorite source code editor. This article is not an attempt to convince you to drop RDi and switch to VS Code. Rather, I aim to share with you a few of my favorite settings and features in VS Code.
Join In The Discussion
Can’t figure out how to do something? Have a suggestion for a new enhancement? I am continually impressed with the speed at which I get responses when I post something. The team of coders and contributors to the Code for IBM i project are really great! Here are a couple of great articles to help you get involved.
- Come read along and join the discussion here: https://github.com/orgs/codefori/discussions
- Found a bug? https://www.seidengroup.com/2023/07/10/how-to-report-an-issue-with-vs-code-for-ibm-i/
When Do You Want Your Content Assist?
By default, you get content assist anytime you press the spacebar. I found this to be annoying far more often than useful. For example, in this case, I just wanted to indent the line of code for better formatting. This popped up, so I had to hit Escape to close the popup.
To change this setting, use Ctl+, (Control+Comma) to open settings, search for suggestOnTriggerCharacters and turn it off. The content assist will now be off for spacebar and when you want the content assist you can still access it with Ctl+Spacebar.
How About Some Next Level Content Assist? Get Yourself A Pair Programmer
The GitHub Copilot extension has quite literally changed the way I write code! I used to be rather proud of my code snippets; tweaking them to be just right. But lately, I find that I never use them because my AI pair programmer nearly always not only suggests what the snippet would have templated for me, but also suggests the full contents of the section of code. It’s not perfect, but the majority of the time, when it suggests something, I’ll accept it then make a minor tweak here and there.
One place I find it really shines is where I am performing mundane tasks. For instance, after every SQL statement I embed into RPG, I check if SQLCODE is negative. If it is negative, at a minimum, I will call a procedure that will write to our log file system. Check out a short demo on my post on LinkedIn.
Set Up Your Editor Rulers!
Being able to see certain columns can be quite handy. True, long ago we RPG programmers were relieved of the shackles of fixed format, but there are still situations where knowing the column is useful. If your code is not fully free format (**FREE) or if you are editing DDS source; PF, LF, DSPF, PRTF, etc.
You need to set these up by language as the rulers make sense in different positions. In the code sample below, I have rulers defined for rpgle and dds.pf. In the first, I demonstrate how you can choose your preferred colors and in the latter is the simpler version where the ruler lines will just be dark gray.
To set up your columns in VS Code, press F1 to open the command palette. Then type ‘settings.json’ and press enter. Find a logical place to insert some new JSON and paste this code in.
"[rpgle]": { "editor.rulers": [ { "column": 80, // spacing of 1st column from left "color": "#FFB612" }, 100, // 2nd ruler with no color option { "column": 120, // third ruler "color": "#e31837" } ] }, "[dds.pf]": { "editor.rulers": [16, 18, 28, 34, 44] }
Time To Switch?
I do still have a license for RDi, but I only use RDi in fewer and fewer scenarios. For example:
- Service Entry Points. Code for i (as of this writing) does not yet support SEPs. So, when I need to debug a program running in batch, I switch over to RDi. They are working on SEP support in the Code for i extension, though, and I am excited to test it out once it’s been implemented.
- Copying source from one connection to another. Not something I need to do often, but when I do, RDi makes this too easy. Simply right click and select copy on the source member on one connection, then find the target source physical file on the desired connection and paste. Since Code for i is geared towards being connected to one IBM i at a time, there isn’t a comparable solution. VS Code is very light and easy to open a second iteration and connect to a different IBM i, and while yes, you can open the same source member on the two different connections and simply copy/paste the source code member by member, this is not ideal.
- For example, in RDi, I could multi-select more than one source member, click copy, then paste them all into a source physical file on another connection of my choosing. This would be time consuming, though doable, in two iterations of VS Code.
So, I’m not saying make the switch from RDi to VS Code, but I definitely think you should give it a try! I’m not there yet, but I think I think the day is coming when I well tell my manager, “No thanks, you don’t need to continue my RDi license.”
Until next time, happy coding.
Gregory Simmons is a software engineer with PC Richard & Son. He started on the IBM i platform in 1994, graduated with a degree in Computer Information Systems in 1997 and has been working on the OS/400 and IBM i platform ever since. He has been a registered instructor with the IBM Academic Initiative since 2007, and holds a COMMON Application Developer certification. When he’s not trying to figure out how to speed up legacy programs, he enjoys speaking at technical conferences, running, backpacking, hunting, and fishing.
RELATED STORIES
Guru: Procedure Driven RPG Means Keeping Your Variables Local
Guru: Procedure Driven RPG With Linear-Main Programs
Guru: Speeding Up RPG By Reducing I/O Operations, Part 2
Guru: Speeding Up RPG By Reducing I/O Operations, Part 1
Guru: Watch Out For This Pitfall When Working With Integer Columns
When will an alternate light weight GUI editor to RDi come for Screen & Print files (like Code/400)???
Some errata: 1) In the section about setting up rulers, it says “Find a logical place to insert some new JSON and paste this code in.”, but then there is no JSON.
2) In the section “Time to switch”, it says, “click copy, then past them all into a source physical file” I think “past” should be “paste”.
Other than that, good article!
I’ve never used it, but you might want to check out the IBM i Renderer extension.