Thursday 27 August 2020

The Oracle DB Developer VM: Installing VS Code and first steps

This post is part of my Oracle DB Developers VM series. Based on the previous postings on how to set up Oracle Linux 8 with the Oracle DB on VirtualBox, this post will show how to install Visual Studio Code with the Oracle Integration in this environment on a beginners level.
Gnome, in contrast to KDE, does not come with a good visual editor for developers, so we should install something better. VS Code has gained popularity and Oracle plugins are available, so I use that as an example.
For installing VS Code, just follow the official instructions:

sudo rpm --import https://packages.microsoft.com/keys/microsoft.asc
sudo sh -c 'echo -e "[code]\nname=Visual Studio Code\nbaseurl=https://packages.microsoft.com/yumrepos/vscode\nenabled=1\ngpgcheck=1\ngpgkey=https://packages.microsoft.com/keys/microsoft.asc" > /etc/yum.repos.d/vscode.repo'
sudo dnf check-update
sudo dnf install code
sudo dnf install dotnet-sdk-2.1

We also need to install the .NET Core Runtime for Linux to run the Oracle Developer Tools for VS Code. It is important to use the older version 2.1.
Double check the dotnet installation with

dotnet --list-sdks
dotnet --list-runtimes

That should return something like:
Searching for Code should now show you VS Code in your activities
Moving the icon to the right into the favorites bar makes it also available in the applications menu.
Microsoft did not tag the .desktop file for VS Code correctly, so it does not appear in the applications menu when not put into the favorites. This can be corrected by editing /usr/share/applications/code.desktop and adding ;Programming to the keywords section like this:

[Desktop Entry]
Name=Visual Studio Code
Comment=Code Editing. Redefined.
GenericName=Text Editor
Exec=/usr/share/code/code --no-sandbox --unity-launch %F
Icon=com.visualstudio.code
Type=Application
StartupNotify=false
StartupWMClass=Code
Categories=Utility;TextEditor;Development;IDE;
MimeType=text/plain;inode/directory;
Actions=new-empty-window;
Keywords=vscode;Programming

[Desktop Action new-empty-window]
Name=New Empty Window
Exec=/usr/share/code/code --no-sandbox --new-window %F
Icon=com.visualstudio.code

and here you are:
Start VS Code, go to the extensions tab and search for Oracle.
Choose the official one from Oracle Corporation and click on Install.
After installation of the extension, on the left bar an Oracle DB tab will appear. Click it and in the Oracle Explorer click the plus (+) and insert your credentials.
Double click the newly created connection. Click around, for example choose a table and select Show Data.
Editing stored procedures and functions also works.
To execute some SQL press F1 and choose Oracle: Develop New SQL or PL/SQL
Select your connection
Type some meaningfull SQL and execute it
That should give you the result set.
By choosing View->Editor Layout->Two Rows and moving the results tab into the lower part of the SQL tab, both can be displayed on one page. Of course, code completion also works.

Of course, all of this works also if you install VS Code on your host OS. On Windows, just download and run the installer. The required .dotnet libraries are already part of the OS.

So much for the first steps with VS Code and the Oracle extension. More information can be found on the official Oracle page.