Skip to content
| Marketplace
Sign in
Visual Studio Code>Other>VSC Context ScriptNew to Visual Studio Code? Get it now.
VSC Context Script

VSC Context Script

Igor Patievich

|
214 installs
| (0) | Free
🌀 Visual Studio Code (VSC) extension for running a script in the context of the VSC itself.
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

Русский

The extension is intended for writing...extensions without...extensions 🤔 Hm. In short, the extension allows you to write JavaScript code (scripts), which will have access to the VS Code execution context. Below are three small examples:


NOTE

After installing the extension, its icon will appear in the status bar on the left, clicking on which will start/stop the written scripts.

01


Example 1. Traditional 'Hello Context'.

Step 1. In the folder .vscode, in the file setting.json (if there are no such ones yet, you need to create them), we will write the settings for the script:

{
    "contextScripts": [
        {
            "name": "Hello Context",
            "path": "./ctx-scripts/HelloContext.js"
        }
    ]
}

where:

  • name - an arbitrary script name.
  • path - the path where it will be located.

Step 2. On the path path, place the file HelloContext.js with the following content:

// Importing the "vscode" module, which contains the VS Code extensibility API
const vscode = require("vscode");

// ACTIVATION FUNCTION THAT IS TRIGGERED WHEN THE SCRIPT IS RUN
function activate() {

    // An additional function for using message output, as well as displaying error messages in the script
    ctxLog("Hello from the context to the output window!👋😎");

    // Displays the message in VS Code pop-up messages
    vscode.window.showInformationMessage("Hello from the context to pop-up messages!👋😎")

}

// Export the activation function to be called by extension
module.exports = { activate }

That's all. Now, by clicking on the extension icon in the status bar, the following result should be displayed:

02

Example 2. 'Clock'.

Demonstration of access to the status bar.


ATTENTION

However, these are not full-fledged VS Code extensions, so not all the functionality will be available. In particular, the one that is configured via the manifest file package .json (for example, displaying commands in the command panel (Ctrl+Shift+P)).


The steps remain the same (on GitHub, in the repository of this extension, can be viewed as settings file, and scripts examples). Clicking on the icon stops/starts displaying the current time:

03

Example 3. 'Server'.

Perhaps this example is useful in itself. Giving commands (transmitting data) as parameters to the server started by the script, there is a possibility of "indirect" control of VS Code in real time. For example, it is quite convenient to start with the project build scripts, or the task manager (gulp, etc.). In this case, without complicating it, we start, restart, and stop the VS Code debugger with simple GET requests through the browser address bar.

Starting the server:

041

Starting debugging:

042

Restart:

043

Finish debugging and stop the server:

044

It is possible to get many commands from the VS Code itself:

51

52

The work of the extension.

The extension reads the array contextScripts property from the settings.json file, each element of which is a metadata object of a single script. Then, using their path, it connects all the scripts as modules, thereby giving them access to the runtime context of the environment. Each metadata object has the following properties:

  • name - (required) the name of the script (displayed in the error log).
  • path - (required) the path where the script is located.
  • parameters - (optional) an object with data that will be passed to the script as a parameter.

In the script file, two functions are important to the extension:

  • activate(params) {} - (required) is called when the script is run, with an optional parameter that takes the object of the data passed to the script parameters from the settings file.
  • deactivate() {} - (optional) called when scripts are turned off.

Also, for debugging purposes, the ctxLog() extension function is available in the global scope, which takes two arguments:

  • string - (required) is output to the VSContext channel of the extension output.
  • boolean (optional) - if true, each output will start from a new line (by default), if false, it will be without line feed.

Useful links.

The main resource for writing VS Code extensions. And there, among other things:

  • VS Code API - full API of the development environment.
  • Built-in Commands - another small list of commands available for execution by the vscode.commands.ExecuteCommand method.
  • Contact us
  • Jobs
  • Privacy
  • Manage cookies
  • Terms of use
  • Trademarks
© 2025 Microsoft