OUR EXPERT
David Bolton
likes creating 6502 assemblers. Now he’s showing how to create an extension in VS Code to run the 6502 assembler he created for Linux Format.
OUR EXPERT
David Bolton likes creating 6502 assemblers. Now he’s showing how to create an extension in VS Code to run the 6502 assembler he created for Linux Format.
The IDE (integrated development environment) was created in 1983, with Borland’s Turbo Pascal considered to be the first example. Before that you edited, compiled and debugged your code with separate programs. It was a clunky process having to switch from the editor to run the compiler and then switch back if a compile error was found. With an IDE, if there is a syntax error, the editor jumps straight to the offending line. With some languages, the errors are identified as you type, without even needing to compile.
Visual Studio Code,
also known as VS Code (see the boxout, opposite), has an extension API that can register commands, configurations, key bindings or context menu items, store workspace or global data, display notification messages, use Quick Pick to collect user input, open the system file picker to let users select files or folders, and use the Progress API to indicate long-running operations.
It can also let you change the colours of your source code through theming, change the colours of the VS Code UI or add custom file icons. For now, we’re going to produce an extension that can run as65 from a command in the VS Code menu and assemble it.
Extension basics
At its simplest it’s just a file, src/extension.ts, containing two functions: export function activate(context: vscode. ExtensionContext): {}
And the corresponding but optional: export function deactivate() {}
The idea is that when your extension is first activated, code in the activate function registers all the commands specified in package.json and provides a mapping for each one in extension.ts.
You can write extensions in either JavaScript or TypeScript. Our personal preference is TypeScript, which if you don’t already know is JavaScript with additional syntax added. The TypeScript compiler does static checking for errors before running it, and helps you avoid those silly JavaScript errors at runtime. You can take any valid JavaScript code and put it in a TypeScript file without worrying about exactly how it is written. Simply rename your .js files to .ts. When you see a file with a .ts file extension, that’s a TypeScript file.
QUICK TIP
You can find many extensions with source code on GitHub. Go to https://github. com and in the search bar at the top type in /extension vscode language: TypeScript or variations of it, like /vscodeextension language: TypeScript .
QUICK TIP
You can find many extensions with source code on GitHub. Go to https://github. com and in the search bar at the top type in /extension vscode language: TypeScript or variations of it, like /vscodeextension language: TypeScript .
A successful launch of Yeoman on Ubuntu 24.04.
Getting started