Introducing “GCP Project Switcher” Extension for VS Code — My Weekend Project
Writing, debugging and deploying from Visual Studio Code for Google Cloud Platform is working out great as you have multiple options to interact with Google Cloud products:
- the Terminal pane, to use the gcloud command-line tool
- by using VSCode Tasks to automate commands
- Cloud Code toolbox
All these work based on the project that your environment is setup.
However, the VS Code screen was missing key info: displaying the current project. There was no easy way to switch projects from the IDE. Until now!
Introducing the “GCP Project Switcher” extension for VS Code.
A weekend project with Typescript
So, this weekend in early November, I had some free time as it was without any conference speaking opportunity which I usually do. The weekend turned out to be productive as I was able to release the extension after two days of small work. Also, I share a secret, this is my first project written in Typescript that got into “production”. It was a nice way to learn how Typescript works, compiles and runs.
Developers love to see on which Git branch are. I always was fascinated by how these are smartly applied to shell’s, screen and tmux instances on Linux systems.
Turns out on VS Code you are able to create your own extension that would add functionality to almost any section of the IDE, but my interest was for the status bar.
The GCP Project Switcher extension creates a status bar item. It uses the gcloud tool to obtain the current project, and it’s refreshed in the background so external changes are handled.
When clicking the status bar item a quick pick pane opens, and you are able to search either by project name or by ID. In order for the pane to be fast — as pulling projects list has a latency — all the polling is done in the background and it’s cached.
Suppose there is a new project that is not on the list, there is a refresh icon to force polling the projects lists. This helps to get started quickly on newly created projects.
Limitations: the gcloud utility must be available in your PATH, as the extension is using that to poll and switch the project on your environment. I plan to add a configuration option to customize the path of the gcloud tool for those who don’t have it globally available in the PATH.
Future work is already planned, I want to maintain a list of “recent” used projects, and populate the list with the recent projects at the top.
Grab the extension either from VS Code Extensions pane, or from Marketplace. Also you can post a Review and Rating in the Marketplace.
The extension is open-source, you can contribute via Github.
Bonus: A sample .vscode/tasks.json definition to deploy a Cloud Workflow.