|
| 1 | +# Extending Peripheral Inspector |
| 2 | + |
| 3 | +It is possible to extend the Peripheral Inspector with new file extension providers in your VSCode extension. This method will provide reading new file formats and load the peripherals information into the Peripheral Inspector. |
| 4 | + |
| 5 | +## Building your VSCode Extension to extend Peripheral Inspector |
| 6 | + |
| 7 | +This is a guide about how you can register new peripheral providers to Peripheral Inspector in your VSCode extension. Please refer to [VSCode Extension API](https://code.visualstudio.com/api) for more information about developing VSCode extensions. |
| 8 | + |
| 9 | +### Adding Peripheral Inspector to your VSCode extension |
| 10 | + |
| 11 | +You need to install eclipse-cdt-cloud/vscode-peripheral-inspector to access the types information. You can use `npm` or `yarn` with the following arguments described below: |
| 12 | + |
| 13 | +Using with npm: |
| 14 | +```bash |
| 15 | +npm install github:eclipse-cdt-cloud/vscode-peripheral-inspector |
| 16 | +``` |
| 17 | +Using with yarn: |
| 18 | +```bash |
| 19 | +yarn add github:eclipse-cdt-cloud/vscode-peripheral-inspector |
| 20 | +``` |
| 21 | + |
| 22 | +### Developing your extension |
| 23 | + |
| 24 | +To provide the peripherals information to Peripheral Inspector on debug session time, you need register your command which is going to construct the peripherals information. The command will receive `DebugSession` object as an input parameter and expects to return array of type `PeripheralOptions[]`. |
| 25 | + |
| 26 | +You can find the example command implementation below: |
| 27 | + |
| 28 | +```js |
| 29 | +import { ExtensionContext } from 'vscode'; |
| 30 | +import type * as api from "peripheral-inspector/api"; |
| 31 | + |
| 32 | + |
| 33 | +class MyExtensionProvider implements api.IPeripheralsProvider { |
| 34 | + public async getPeripherals (data: string, options: api.IGetPeripheralsArguments): Promise<api.PeripheralOptions[]> { |
| 35 | + // Load your peripherals data |
| 36 | + const peripherals: api.PeripheralOptions[] = ... |
| 37 | + return peripherals; |
| 38 | + } |
| 39 | +} |
| 40 | + |
| 41 | +export async function activate(context: ExtensionContext) { |
| 42 | + ... |
| 43 | + // Get the eclipse-cdt.peripheral-inspector extension |
| 44 | + const peripheralInspectorExtention = extensions.getExtension<api.IPeripheralInspectorAPI>('eclipse-cdt.peripheral-inspector'); |
| 45 | + |
| 46 | + // Check if the eclipse-cdt.peripheral-inspector extension is installed |
| 47 | + if (peripheralInspectorExtention) { |
| 48 | + const peripheralInspectorAPI = await peripheralInspectorExtention.activate(); |
| 49 | + |
| 50 | + // Invoke registerPeripheralsProvider method in eclipse-cdt.peripheral-inspector extension api |
| 51 | + // Register 'MyExtensionProvider' for files *.myext |
| 52 | + peripheralInspectorAPI.registerPeripheralsProvider('myext', new MyExtensionProvider()); |
| 53 | + } |
| 54 | + ... |
| 55 | +} |
| 56 | +``` |
| 57 | + |
| 58 | +For further information about the api definitions, review the [Peripheral Inspector API Definitions](../src/api-types.ts). |
| 59 | + |
| 60 | +### Modifying your package.json |
| 61 | + |
| 62 | +In `package.json` of your VSCode extension project, you need to define the dependency between Peripheral Inspector and your extension. |
| 63 | + |
| 64 | +You need to define Peripheral Inspector in the `extensionDependencies` as shown below: |
| 65 | + |
| 66 | +```json |
| 67 | +{ |
| 68 | + ... |
| 69 | + "extensionDependencies": [ |
| 70 | + "eclipse-cdt.peripheral-inspector" |
| 71 | + ], |
| 72 | + ... |
| 73 | +} |
| 74 | +``` |
0 commit comments