The Deska blog

Building a VS Code Extension With AI Help

Learn the technical workflow for building a VS Code extension with AI help across the full development lifecycle, from scaffolding to debugging.

· 10 min read

Developing custom tooling for your editor is one of the most effective ways to improve your workflow. Building a VS Code extension with AI help allows you to move rapidly from a concept to a functional plugin by offloading boilerplate generation and API exploration to LLMs. While the VS Code API is extensive and well documented, the learning curve for managing contribution points and registration sequences can be steep. Leveraging artificial intelligence as a pair programmer helps bridge the gap between intent and implementation.

The Architecture of a VS Code Extension

Before writing code, it is essential to understand how VS Code handles extensions. Every extension runs in a dedicated extension host process, which ensures that a faulty plugin does not crash the entire editor UI. This isolation is a core design principle of the platform.

The primary entry point for any extension is the package.json file. This file acts as a manifest where you define your contribution points, such as commands, menus, or custom views. The actual logic resides in an extension.ts or extension.js file, specifically within the activate function. This function is triggered by VS Code based on the activation events you specify.

When you are building a VS Code extension with AI help, the agent needs to understand this manifest-driven architecture. Models often excel at generating the specific JSON keys required for the contributes block, which is frequently the most tedious part of the setup.

Setting Up the Development Environment

Standard development involves using the Yeoman generator (Yo Code) to scaffold the initial project structure. This creates a TypeScript or JavaScript project with all necessary configuration files for bundling and testing.

A common challenge arises when you need to monitor the extension logs and the debug console while also reading documentation and writing code. Traditional single-file editors can become cluttered during this phase. Deska offers an alternative by providing an infinite canvas workspace where you can arrange multiple terminals and code editors side by side.

In a typical setup, you would have one panel running the compiler in watch mode, another for the extension host launch, and a third for the actual source code. This spatial arrangement allows you to see the output of your changes without constantly switching tabs.

Leveraging AI Coding Agents for Logic

The real power of building a VS Code extension with AI help comes during the implementation of complex API features. Working with Tree View Providers or Custom Editors requires boilerplate code that follows specific interfaces.

Command Registration and UI

AI agents are particularly good at generating the registration code for commands and adding them to the command palette. For example, if you want your extension to process text selection, the AI can quickly suggest the correct calls to vscode.window.activeTextEditor and the necessary error handling for cases where no editor is open.

Context Management and State

Handling global or workspace state is a common requirement. The VS Code API provides ExtensionContext, which includes globalState and workspaceState. Large language models can help you wrap these into clean, type-safe services. This ensures that your extension remembers user preferences across sessions.

Tooling Comparison for Extension Development

Various tools can assist in this process. Different environments provide different sets of features.

FeatureVS Code (Native)Deska WorkspaceSpecialized AI IDEs
InterfaceSingle viewInfinite canvasSingle view
Multi-Agent SupportLimitedRuns multiple agentsBuilt-in single agent
Data PrivacyLocal fileslocal-firstVaries by provider
Device SyncSync SettingsMobile appProject sync

While VS Code is the target platform, the environment where you write the extension logic can vary. Deska allows you to run coding agents like Claude Code or OpenCode in parallel panels. This is useful for comparing how different models approach a specific VS Code API implementation problem.

Managing the Workflow with Voice and Chat

Iterating on a plugin often involves repetitive tasks like restarting the debugger or checking the status of the build. Within Deska, the Ask Deska assistant can drive the workspace through voice or chat. You can instruct the assistant to open specific panels or run build commands, allowing you to focus on the code logic rather than window management.

If you are away from your main workstation, the mobile app provides a secure way to monitor your build logs or see the progress of a long-running AI generation task. It uses a secure relay to pair directly with your desktop, ensuring that no ports are exposed to the public internet.

Debugging and Testing Strategies

Validation is the final hurdle. VS Code extensions use a specialized test runner. You must write integration tests that run inside a mock instance of the editor.

  1. Use vscode-test to automate the launching of the test instance.
  2. Verify that your commands are registered correctly in the command registry.
  3. Simulate user interactions, such as clicking a menu item or typing in an input box.
  4. Check the notifications to ensure the user receives the correct feedback.

Building a VS Code extension with AI help makes this testing phase easier. You can provide the AI with the error logs from the debug console, and it can suggest fixes based on the stack trace. Because Deska keeps your data and storage local, you can iterate on these tests without uploading your source code to external servers for every execution.

FAQ

How to use AI for VS Code API?

The most effective way is to provide the AI agent with the specific section of the official documentation or a clear description of the intended behavior. You should ask the model to generate the contributes section of the package.json and the corresponding registration in the activate function together to ensure consistency.

Can AI write complete VS Code extensions?

AI can generate significant portions of an extension, especially for standard UI elements and command structures. However, complex logic involving file system watchers or deep integration with other extensions requires human oversight and manual debugging to ensure performance and security.

Best AI agent for VS Code development?

Multiple agents like Claude Code or Codex CLI are effective. The best results often come from using a local-first approach where the agent has direct access to your local files and can run commands in a terminal to verify the code it generates.

Expanding Your Toolset

Creating custom extensions is a powerful path toward developer productivity. By combining AI assistance with a flexible workspace, you can reduce the overhead of learning new APIs and focus on the unique features of your tool. Deska provides a free environment to orchestrate these modern AI tools alongside your standard development workflow.

You can start building your next project by downloading the app for Mac, Windows, or Linux at /download.

💡 Ideas+🐛 BugsSuggest a feature or report a bug