Skip to content

Commit 0ca13c1

Browse files
authored
Add vscode-extension-client example
1 parent 7c0f596 commit 0ca13c1

18 files changed

Lines changed: 4062 additions & 11 deletions

.github/workflows/bridge.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ jobs:
4646

4747
- name: Install dependencies
4848
run: npm ci
49-
working-directory: codegen
49+
working-directory: bridge
5050

5151
- name: Run linter
5252
run: npm run lint
53-
working-directory: codegen
53+
working-directory: bridge

.github/workflows/codeql.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ on:
1010
- 'api/**'
1111
- 'bridge/**'
1212
- 'codegen/**'
13+
- 'examples/**'
1314
- '!**/*.md'
1415

1516
concurrency:

.github/workflows/examples.yml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: examples
2+
on:
3+
push:
4+
branches:
5+
- main
6+
paths:
7+
- '.github/workflows/examples.yml'
8+
- 'examples/**'
9+
- '!**/*.md'
10+
pull_request:
11+
paths:
12+
- '.github/workflows/examples.yml'
13+
- 'examples/**'
14+
- '!**/*.md'
15+
16+
concurrency:
17+
group: ${{ github.workflow }}-${{ github.ref }}
18+
cancel-in-progress: true
19+
20+
permissions:
21+
contents: read
22+
23+
jobs:
24+
tests:
25+
if: |
26+
${{ github.event_name == 'pull_request' }}
27+
timeout-minutes: 15
28+
runs-on: ubuntu-latest
29+
name: 'Test examples'
30+
31+
steps:
32+
- name: Harden the runner (Audit all outbound calls)
33+
uses: step-security/harden-runner@0634a2670c59f64b4a01f0f96f84700a4088b9f0 # v2.12.0
34+
with:
35+
egress-policy: audit
36+
37+
- name: Checkout csolution-rpc repository
38+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
39+
with:
40+
fetch-depth: 0
41+
42+
- name: Set up Node.js
43+
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
44+
with:
45+
node-version: 'lts/*'
46+
47+
- name: Install dependencies
48+
run: npm ci
49+
working-directory: examples/vscode-extension-client
50+
51+
- name: Run linter
52+
run: npm run lint
53+
working-directory: examples/vscode-extension-client

codegen/src/codegen.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ program
1616
.description("json-rpc interface code generator")
1717
.version("0.0.9")
1818
.argument('<schema>', 'openapi.yml schema')
19-
.option("-c, --client <string>", "Generate TypeScript client interface", "./rpc-interface.ts")
20-
.option("-s, --server <string>", "Generate C++ server interface", "./RpcInterface.h")
19+
.option("-c, --client <string>", "Generate TypeScript client interface")
20+
.option("-s, --server <string>", "Generate C++ server interface")
2121
.action((filepath, options) => {
22-
console.log(`Generating intefaces for ${filepath}`);
22+
console.log(`Generating interfaces for ${filepath}`);
2323
const codegen = new Codegen();
2424
const methods = codegen.parseSchema(filepath);
2525
codegen.collectInfo(methods);
@@ -99,14 +99,18 @@ using namespace jsonrpccxx;\n`;
9999
program.parse(argv);
100100
}
101101

102-
public createClient(options: {client: string}, content: string) {
103-
fs.mkdirSync(path.dirname(options.client), { recursive: true });
104-
fs.writeFileSync(options.client, content);
102+
public createClient(options: {client?: string}, content: string) {
103+
if (options.client) {
104+
fs.mkdirSync(path.dirname(options.client), { recursive: true });
105+
fs.writeFileSync(options.client, content);
106+
}
105107
}
106108

107-
public createServer(options: {server: string}, content: string) {
108-
fs.mkdirSync(path.dirname(options.server), { recursive: true });
109-
fs.writeFileSync(options.server, content);
109+
public createServer(options: {server?: string}, content: string) {
110+
if (options.server) {
111+
fs.mkdirSync(path.dirname(options.server), { recursive: true });
112+
fs.writeFileSync(options.server, content);
113+
}
110114
}
111115

112116
public parseSchema(filepath: string) : Record<string, Method> {

csolution-rpc.code-workspace

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
},
99
{
1010
"path": "api"
11+
},
12+
{
13+
"path": "examples/vscode-extension-client"
1114
}
1215
],
1316
"settings": {}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
// See http://go.microsoft.com/fwlink/?LinkId=827846
3+
// for the documentation about the extensions.json format
4+
"recommendations": [
5+
"dbaeumer.vscode-eslint",
6+
"ms-vscode.extension-test-runner"
7+
]
8+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// A launch configuration that compiles the extension and then opens it inside a new window
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
{
6+
"version": "0.2.0",
7+
"configurations": [
8+
{
9+
"name": "Run Extension",
10+
"type": "extensionHost",
11+
"request": "launch",
12+
"args": [
13+
"--extensionDevelopmentPath=${workspaceFolder}"
14+
],
15+
"outFiles": [
16+
"${workspaceFolder}/out/**/*.js"
17+
],
18+
"preLaunchTask": "${defaultBuildTask}"
19+
}
20+
]
21+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Place your settings in this file to overwrite default and user settings.
2+
{
3+
"files.exclude": {
4+
"out": false // set this to true to hide the "out" folder with the compiled JS files
5+
},
6+
"search.exclude": {
7+
"out": true // set this to false to include "out" folder in search results
8+
},
9+
// Turn off tsc task auto detection since we have the necessary tasks as npm scripts
10+
"typescript.tsc.autoDetect": "off"
11+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// See https://go.microsoft.com/fwlink/?LinkId=733558
2+
// for the documentation about the tasks.json format
3+
{
4+
"version": "2.0.0",
5+
"tasks": [
6+
{
7+
"type": "npm",
8+
"script": "watch",
9+
"problemMatcher": "$tsc-watch",
10+
"isBackground": true,
11+
"presentation": {
12+
"reveal": "never"
13+
},
14+
"group": {
15+
"kind": "build",
16+
"isDefault": true
17+
}
18+
}
19+
]
20+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# csolution-rpc-client-example
2+
3+
This example shows how to implement a client for the `csolution-rpc` interface inside a vscode extension.
4+
5+
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.
6+
7+
## Get started
8+
9+
1. Make sure the [`json-rpc-codegen`](../../codegen/README.md) utility is compiled in this workspace.
10+
11+
2. Generate the client interface file `src/rpc-interface.ts` by calling:
12+
```
13+
npm run gen-rpc-interface
14+
```
15+
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.
16+
17+
4. Run the `csolution-rpc` commands from the Command Palette (Ctrl+Shift+P) in the new window:
18+
19+
![Command Palette](./docs/command-palette.png)
20+
21+
The commands `getVersion` and `shutdown` are currently available in this example.
22+
23+
> :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.

0 commit comments

Comments
 (0)