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:
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:
where:
Step 2. On the path path, place the file HelloContext.js with the following content:
That's all. Now, by clicking on the extension icon in the status bar, the following result should be displayed: Example 2. 'Clock'.Demonstration of access to the status bar.
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: 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: Starting debugging: Restart: Finish debugging and stop the server: It is possible to get many commands from the VS Code itself: 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:
In the script file, two functions are important to the extension:
Also, for debugging purposes, the ctxLog() extension function is available in the global scope, which takes two arguments:
Useful links.The main resource for writing VS Code extensions. And there, among other things:
|