Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/bridge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ jobs:

- name: Install dependencies
run: npm ci
working-directory: codegen
working-directory: bridge

- name: Run linter
run: npm run lint
working-directory: codegen
working-directory: bridge
1 change: 1 addition & 0 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ on:
- 'api/**'
- 'bridge/**'
- 'codegen/**'
- 'examples/**'
- '!**/*.md'

concurrency:
Expand Down
53 changes: 53 additions & 0 deletions .github/workflows/examples.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: examples
on:
push:
branches:
- main
paths:
- '.github/workflows/examples.yml'
- 'examples/**'
- '!**/*.md'
pull_request:
paths:
- '.github/workflows/examples.yml'
- 'examples/**'
- '!**/*.md'

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

permissions:
contents: read

jobs:
tests:
if: |
${{ github.event_name == 'pull_request' }}
timeout-minutes: 15
runs-on: ubuntu-latest
name: 'Test examples'

steps:
- name: Harden the runner (Audit all outbound calls)
uses: step-security/harden-runner@0634a2670c59f64b4a01f0f96f84700a4088b9f0 # v2.12.0
with:
egress-policy: audit

- name: Checkout csolution-rpc repository
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
fetch-depth: 0

- name: Set up Node.js
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
with:
node-version: 'lts/*'

- name: Install dependencies
run: npm ci
working-directory: examples/vscode-extension-client

- name: Run linter
run: npm run lint
working-directory: examples/vscode-extension-client
22 changes: 13 additions & 9 deletions codegen/src/codegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ program
.description("json-rpc interface code generator")
.version("0.0.9")
.argument('<schema>', 'openapi.yml schema')
.option("-c, --client <string>", "Generate TypeScript client interface", "./rpc-interface.ts")
.option("-s, --server <string>", "Generate C++ server interface", "./RpcInterface.h")
.option("-c, --client <string>", "Generate TypeScript client interface")
.option("-s, --server <string>", "Generate C++ server interface")
.action((filepath, options) => {
console.log(`Generating intefaces for ${filepath}`);
console.log(`Generating interfaces for ${filepath}`);
const codegen = new Codegen();
const methods = codegen.parseSchema(filepath);
codegen.collectInfo(methods);
Expand Down Expand Up @@ -99,14 +99,18 @@ using namespace jsonrpccxx;\n`;
program.parse(argv);
}

public createClient(options: {client: string}, content: string) {
fs.mkdirSync(path.dirname(options.client), { recursive: true });
fs.writeFileSync(options.client, content);
public createClient(options: {client?: string}, content: string) {
if (options.client) {
fs.mkdirSync(path.dirname(options.client), { recursive: true });
fs.writeFileSync(options.client, content);
}
}

public createServer(options: {server: string}, content: string) {
fs.mkdirSync(path.dirname(options.server), { recursive: true });
fs.writeFileSync(options.server, content);
public createServer(options: {server?: string}, content: string) {
if (options.server) {
fs.mkdirSync(path.dirname(options.server), { recursive: true });
fs.writeFileSync(options.server, content);
}
}

public parseSchema(filepath: string) : Record<string, Method> {
Expand Down
3 changes: 3 additions & 0 deletions csolution-rpc.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
},
{
"path": "api"
},
{
"path": "examples/vscode-extension-client"
}
],
"settings": {}
Expand Down
8 changes: 8 additions & 0 deletions examples/vscode-extension-client/.vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
// See http://go.microsoft.com/fwlink/?LinkId=827846
// for the documentation about the extensions.json format
"recommendations": [
"dbaeumer.vscode-eslint",
"ms-vscode.extension-test-runner"
]
}
21 changes: 21 additions & 0 deletions examples/vscode-extension-client/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// A launch configuration that compiles the extension and then opens it inside a new window
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
{
"version": "0.2.0",
"configurations": [
{
"name": "Run Extension",
"type": "extensionHost",
"request": "launch",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}"
],
"outFiles": [
"${workspaceFolder}/out/**/*.js"
],
"preLaunchTask": "${defaultBuildTask}"
}
]
}
11 changes: 11 additions & 0 deletions examples/vscode-extension-client/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Place your settings in this file to overwrite default and user settings.
{
"files.exclude": {
"out": false // set this to true to hide the "out" folder with the compiled JS files
},
"search.exclude": {
"out": true // set this to false to include "out" folder in search results
},
// Turn off tsc task auto detection since we have the necessary tasks as npm scripts
"typescript.tsc.autoDetect": "off"
}
20 changes: 20 additions & 0 deletions examples/vscode-extension-client/.vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
{
"version": "2.0.0",
"tasks": [
{
"type": "npm",
"script": "watch",
"problemMatcher": "$tsc-watch",
"isBackground": true,
"presentation": {
"reveal": "never"
},
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
23 changes: 23 additions & 0 deletions examples/vscode-extension-client/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# csolution-rpc-client-example

This example shows how to implement a client for the `csolution-rpc` interface inside a vscode extension.

It uses the Microsoft [vscode-jsonrpc](https://www.npmjs.com/package/vscode-jsonrpc) npm module which is typically the base messaging protocol spoken between a VSCode language server and a client.

## Get started

1. Make sure the [`json-rpc-codegen`](../../codegen/README.md) utility is compiled in this workspace.

2. Generate the client interface file `src/rpc-interface.ts` by calling:
```
npm run gen-rpc-interface
```
3. Inside the editor, open `src/extension.ts` and press F5 or run the command `Debug: Start Debugging` from the Command Palette (Ctrl+Shift+P). This will compile and run the extension in a new Extension Development Host window.

4. Run the `csolution-rpc` commands from the Command Palette (Ctrl+Shift+P) in the new window:

![Command Palette](./docs/command-palette.png)

The commands `getVersion` and `shutdown` are currently available in this example.

> :memo: Note: The `csolution` binary must have the RPC server functionality and must be in the system PATH. Install the CMSIS-Toolbox from [nightly artifacts](https://github.com/Open-CMSIS-Pack/cmsis-toolbox/actions/workflows/nightly.yml) or build it in your local environment.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 28 additions & 0 deletions examples/vscode-extension-client/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import typescriptEslint from "@typescript-eslint/eslint-plugin";
import tsParser from "@typescript-eslint/parser";

export default [{
files: ["**/*.ts"],
}, {
plugins: {
"@typescript-eslint": typescriptEslint,
},

languageOptions: {
parser: tsParser,
ecmaVersion: 2022,
sourceType: "module",
},

rules: {
"@typescript-eslint/naming-convention": ["warn", {
selector: "import",
format: ["camelCase", "PascalCase"],
}],

curly: "warn",
eqeqeq: "warn",
"no-throw-literal": "warn",
semi: "warn",
},
}];
Loading