VSCode Source Code Study (Part 1): Running Locally

Introduction

Recently, I am going to learn the source code of vscode. The first step is to run it.

The steps I followed are mostly based on the official contribution documentation:

VSCode: How to Contribute

Here are some key steps distilled from there. For accuracy, please refer to the official documentation.

Steps

Since VSCode's compilation involves using node-gyp, which can be troublesome to install on Windows, my plan is to run it in WSL (Windows Subsystem for Linux).

  1. Environment Setup

    Ensure you have Git, Node.js, Yarn, Python, and C++ toolchain installed in your WSL:

    • Git
    • Node.js, x64, version >=18.15.x and <19
    • Yarn 1, version >=1.10.1 and <2, follow the installation guide
    • Python (required for node-gyp; refer to node-gyp readme for supported Python versions)
    • C/C++ compiler toolchain for your platform:
      sudo apt install python3 python-is-python3 libsecret-1-dev libxss1 libx11-dev libxkbfile-dev libasound2 libgtk-3-0 libgdk-pixbuf2.0-0 libnss3 libxtst6 libxi6 libxdamage1 libxcursor1 libxcomposite1 libx11-xcb1 libgbm1
      
    • It's recommended to use VSCode for development. Install VS Code and the Remote - WSL extension.
  2. Install Dependencies

    yarn
    

    Successful yarn installation

  3. Start Electron

    ./scripts/code.sh --no-sandbox
    

    The first execution might be slow; wait for about 2 minutes, and it should start. Successful execution of code.sh

Errors

Error while executing ./scripts/code.sh

If you encounter errors while running ./scripts/code.sh, it might be due to missing C++ toolchain dependencies. Errors like:

Cannot find module 'ternary-stream'

Error: Cannot find module 'ternary-stream'

Cannot find module 'vscode-gulp-watch'

Error: Cannot find module 'vscode-gulp-watch'

gssapi.h error

../src/unix/kerberos_gss.h:21:14: fatal error: gssapi/gssapi.h: No such file or directory

Installing C++ dependencies should resolve these issues.

gyp error during yarn dependency installation

Another common error involving node-gyp:

/bin/sh: 1: pkg-config: not found
gyp: Call to 'pkg-config --cflags libsecret-1' returned exit status 127 while in binding.gyp. while trying to load binding.gyp
gyp ERR! configure error
gyp ERR! stack Error: `gyp` failed with exit code: 1

You can try clearing dependencies and reinstalling them:

# Clear dependencies
git clean -xfd
# Reinstall dependencies
yarn

"not a valid Electron app" warning

This is an official warning. Just take note and execute:

yarn watch

References

Comments