-
Notifications
You must be signed in to change notification settings - Fork 34
Development Process
This guide covers how to set up a development environment, build, and debug the MATLAB extension for VS Code and the associated MATLAB language server.
The MATLAB extension for VS Code and associated language server are TypeScript applications developed with Node.js.
The following software is needed for development:
- Visual Studio Code - The recommended IDE for VS Code extension development.
-
Node.js - A cross-platform JavaScript runtime.
- Includes
npm, used for dependency management, building, and testing.
- Includes
- Git - The version control system used by GitHub, and needed to contribute to GitHub.
-
MATLAB - Needed to run MATLAB code as part of the language server.
- This is optional if not leveraging advanced language server functionality.
Clone the extension repository with submodules (the language server is a Git submodule):
git clone --recursive https://github.com/mathworks/MATLAB-extension-for-vscode.git
cd MATLAB-extension-for-vscode
Next, install all project dependencies:
npm run project-install
VS Code is the recommended IDE for developing VS Code extensions, as it includes integrated tooling for building, running, and debugging extensions.
To get started, simply open the root directory of the cloned repository within VS Code.
The extension's TypeScript code is compiled into JavaScript before running. There are a few ways to do this:
- Auto-rebuild on save:
npm run watch - One-time build:
npm run compile - Create a distributable VSIX (for local install/testing):
This produces a
npm run packagelanguage-matlab-<version>.vsixfile.
A set of VS Code run configurations are provided alongside the extension source code.
To locally run the extension for debugging:
- Ensure the extension repo is open in VS Code
- Open the "Run and Debug" panel
- Choose the "Run & Debug" run configuration from the drop down
- Select the "Play" button (or press F5)
VS Code launches an Extension Development Host window with the MATLAB extension enabled. Open a .m file to activate the extension.
- Set breakpoints in the extension source (your main VS Code window).
- Perform actions in the Extension Development Host window to hit breakpoints.
- There may be a slight delay before the debugger attaches to the language server process.
- If breakpoints appear "unbound", stop and re-run the debugger with the "Run & Debug" configuration (not "Run Extension").
If a workflow runs MATLAB code, you can use the MATLAB Desktop to set MATLAB breakpoints as usual and step through M-code behavior triggered by actions in the Extension Development Host window.
To run the MATLAB Desktop:
- In the Extension Development Host window, run the
MATLAB: Open Command WindowVS Code command. - Run the
desktopcommand in the resulting MATLAB terminal
Tip: For silent exceptions in MATLAB, temporarily wrap suspect code in try/catch and disp the caught error for visibility during debugging.
The extension includes integration tests and language server unit tests.
- Location:
src/test/ - Framework: Mocha
To run these tests, use the following command:
npm run test
- Location:
server/tests/ - Types of tests:
- TypeScript-based (Mocha)
- MATLAB-based
To run the TypeScript unit tests, use the following commands:
cd server
npm run test
To run the MATLAB unit tests, it is recommended to use the MATLAB test features within MATLAB:
- Launch MATLAB (outside VS Code)
- Open the test file in the MATLAB editor
- Run the tests using one of the following:
- "Run Tests" toolstrip button
- Test Browser side panel
-
runtestscommand
- Extension API - Microsoft's resource for VS Code extension development
- Your First Extension - A quick-start guide on creating an extension for VS Code
- Extension Capabilities - Describes the various capabilities which can be leveraged by extensions
- UX Guidelines - A set of guidelines which cover the best practices for creating extensions that seamlessly integrate with VS Code's native interface and patterns.
- Language Extensions - A guide specifically focused on creating extensions which add support for programming languages.
- Contribution Points - A reference for the various contribution points which are available to extensions.
- VS Code API Reference - A reference page for VS Code's extension APIs
-
LSP Overview & Specification - Microsoft's resource for language servers
- Language features (e.g. completion, diagnostics, etc.) are detailed within the spec.