If you want to have GitHub Copilot AI doing pair-programming with you when you program in Delphi, you need Visual Studio Code and this plugin.
This Delphi plugin will create a "Tools->Open In Visual Studio Code" menù item in your RAD Studio IDE.
Selecting this option will do just these two simple things:
- All modified files opened in your ide will be saved.
- The Delphi source file you were editing will be opened in Visual Studio Code, at the exact line you were editing in Rad Studio.
- Existing Visual Studio Code instances will be reused (the same source file won't be opened multiple times in different editors)
What's so great about using Visual Studio Code as a code editor?
- Copilot with Delphi: (this is the main reason I wrote this plugin): if you have the Copilot extension installed in Visual Studio Code, it will work perfectly with your Delphi code. This is an incredible game-changer.
- Visual Studio Code is simply a far better code editor than the one integrated into the RAD Studio IDE (for example it supports multiple cursors).
Copilot is an AI specifically trained for programming and it will run inside your visual studio instance: it will understand your code (and your comments!) and it will suggest you code unbelievable code completions. It will really feel like you are coding with the help of another programmer working side by side with you.
Here are some simple screenshots of Copilot suggesting code:
Here it is completing the TDaysOfTheWeek
enum (the suggestion is the part in gray: you just have to press "TAB" to accept it)
Same for the TLanguages
enum:
Here it suggests a whole function implementation:
You can also chat with the Copilot about a portion of the code you have selected and ask it to explain what it does:
This is just the tip of the iceberg: you can ask the Copilot to modify your code (with prompts like "use meaningful variable names", "use italian for variable names", "refactor this function by using simpler and smaller local functions", "add comments to this code", "write xml documentation for this class").
- Download the source code from this repository
- Open the package project, build it and install it.
- You need to activate this option in Delphi (under Tools->Options->Editor->Language->Delphi->Code Insight). (This is necessary to make the LSP Visual Studio Code extension work correctly).
- (optional) Disable the confirmation requests about reloading a file that is unchanged in the IDE and has been changed externally. This will make Delphi reload automatically a file that has been changed on the file system (this applies only if you don't have any pending changes in the editor). This will make it more "fluid" to switch back from Visual Studio Code to Delphi.
-
Download and install VSCode from here https://code.visualstudio.com/download
-
Launch VSCode and install the DelphiLSP extension from its marketplace
You will also need the copilot extensions:
-
Create a GitHub account (if you already haven't one)
-
Subscribe for Copilot (look for the menu option "Your Copilot" in the popup menu that opens when you click on your avatar in the top-right corner). The first 30 days are a free trial, then it costs 10 dollars/month... I think it is worth every penny.)
-
Back in Visual Studio Code, sign in with copilot.
This will make Visual Studio save automatically all the changes to the source file, so whenever you switch back to Delphi you will find in Delphi all the changes you made. If you disabled the reload prompt in Delphi as I suggested, you will get a much better experience. Just remember that Delphi does NOT do an auto-save when you switch back to Visual Studio Code, unless you switch from Delphi to VSC by using the tools->Open In Visual Studio Code menu option
This is quite easy, just check this option in the File menu:
By default, VSC opens all source files using the UTF8 encoding. It is very likely that you still have some Delphi source files encoded in your local ANSI 8-bit charset.
Search the "Auto Guess Encoding" under VSCode settings, and enable it
you can access the settings tab by pressing "CTRL+," (at least this is the key combination on my Italian keyboard), or by clicking the "gear" icon in the bottomleft corner of vsc.
This is just something "fancy" but I like it. Maybe you'll like it too: If you use a ligature-supporting font like firacode you type ">=" but you see "≥": all special character sequences commonly used in programming languages get rendered as the symbol that they should actually represent.
- Install this font in Windows: https://github.com/tonsky/FiraCode
- look for "Font Family" inside VSCode settings tab and insert "'Fira Code'" as the first font in the comma-separated list (my current setup contains this string, for example, "'Fira Code', Consolas, 'Courier New', monospace")
- look for "ligatures" in vscode settings. You will see that you have to select "edit in settings.json" to modify it. Press that "edit in settings.json" link and add "editor.fontLigatures": true, to your configuration file, right before the line about autoGuessEncoding. Mine looks like this: