Skip to content

Commit f71584d

Browse files
authored
VSCode: Make plugin extensible (#96)
See also paiqo/Databricks-VSCode#94 for how this API can be consumed. ![Screenshot 2022-09-14 at 11 03 53](https://user-images.githubusercontent.com/40952/190119140-49d43cb7-2b86-4139-8428-791ee15500e0.png)
1 parent 5b91982 commit f71584d

13 files changed

Lines changed: 318 additions & 226 deletions

File tree

.github/workflows/push.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ jobs:
5555
- run: mkdir -p packages/databricks-vscode/artifacts
5656

5757
- name: Build VSIX
58-
run: yarn workspace databricks package -o artifacts -t darwin-x64
58+
run: yarn workspace databricks-vscode package -o artifacts -t darwin-x64
5959

6060
- name: Upload artifacts
6161
uses: actions/upload-artifact@v3

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ jobs:
129129
timeout_minutes: 10
130130
retry_on: any
131131
command: |
132-
yarn workspace databricks run test:integ:clean
132+
yarn workspace databricks-vscode run test:integ:clean
133133
yarn install --immutable
134134
yarn build
135135
cd packages/databricks-vscode

databricks-vscode.code-workspace

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
{
1212
"path": "packages/databricks-vscode",
1313
"name": "Extension"
14+
},
15+
{
16+
"path": "packages/databricks-vscode-types",
17+
"name": "Extension Types"
1418
}
1519
],
1620
"settings": {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "databricks-vscode",
2+
"name": "@databricks/databricks-vscode",
33
"version": "0.0.1",
44
"private": true,
55
"workspaces": [
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
index.d.ts
2+
index.js
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Databricks Extension for VSCode Interfaces and Types
2+
3+
Package with types and interfaces required for extending the Databricks VSCode extension.
4+
5+
## How to extend the Databricks VSCode extension
6+
7+
### Importing and using the API
8+
9+
package.json
10+
11+
```json
12+
{
13+
...
14+
"extensionDependencies": [
15+
"databricks.databricks-vscode"
16+
],
17+
"devDependencies": {
18+
...
19+
"@databricks/databricks-vscode-types": "*",
20+
}
21+
}
22+
```
23+
24+
src/extension.ts
25+
26+
```js
27+
import {PublicApi} from "@databricks/databricks-vscode-types";
28+
29+
export async function activate(context: vscode.ExtensionContext) {
30+
const dbExtension =
31+
extensions.getExtension < PublicApi > "databricks.databricks-vscode";
32+
33+
if (!dbExtension) {
34+
throw new Error("Databricks extension not installed");
35+
}
36+
await dbExtension.activate();
37+
const dbApi = dbExtension.exports;
38+
//...
39+
}
40+
```
41+
42+
### Adding a view to the Databricks activity bar
43+
44+
```js
45+
"contributes" {
46+
// ...
47+
"views": {
48+
"databricksBar": [
49+
{
50+
"id": "databricksJobs",
51+
"name": "Jobs"
52+
},
53+
// ...
54+
],
55+
// ...
56+
}
57+
}
58+
```
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import {ApiClient} from "@databricks/databricks-sdk";
2+
import {Cluster} from "@databricks/databricks-sdk";
3+
import {Event} from "vscode";
4+
export type ConnectionState = "CONNECTED" | "CONNECTING" | "DISCONNECTED";
5+
6+
export interface PublicApi {
7+
connectionManager: {
8+
onDidChangeState: Event<ConnectionState>;
9+
10+
get profile(): string | undefined;
11+
get me(): string | undefined;
12+
get state(): ConnectionState;
13+
get cluster(): Cluster | undefined;
14+
get apiClient(): ApiClient | undefined;
15+
16+
waitForConnect(): Promise<void>;
17+
};
18+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"name": "@databricks/databricks-vscode-types",
3+
"version": "1.0.0",
4+
"description": "Package with types and interfaces to develop extensions to the Databricks VSCode plugin",
5+
"main": "index.js",
6+
"types": "index.d.ts",
7+
"repository": {
8+
"type": "git",
9+
"url": "git+https://github.com/databricks/databricks-vscode.git"
10+
},
11+
"license": "Apache-2.0",
12+
"bugs": {
13+
"url": "https://github.com/databricks/databricks-vscode/issues"
14+
},
15+
"homepage": "https://github.com/databricks/databricks-vscode#readme",
16+
"scripts": {
17+
"build": "tsc",
18+
"watch": "tsc -w"
19+
},
20+
"devDependencies": {
21+
"@types/vscode": "^1.69.1",
22+
"typescript": "^4.8.3"
23+
},
24+
"dependencies": {
25+
"@databricks/databricks-sdk": "workspace:^"
26+
}
27+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"compilerOptions": {
3+
"module": "CommonJS",
4+
"target": "ES2020",
5+
"declaration": true,
6+
"esModuleInterop": true,
7+
"isolatedModules": true,
8+
"lib": ["ES2020", "ES2021.String"],
9+
"rootDir": ".",
10+
"strict": true /* enable all strict type-checking options */
11+
},
12+
"include": ["*.ts"]
13+
}

packages/databricks-vscode/package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "databricks",
2+
"name": "databricks-vscode",
33
"displayName": "Databricks for Visual Studio Code",
44
"description": "IDE support for Databricks",
55
"publisher": "databricks",
@@ -64,6 +64,7 @@
6464
"onDebugResolve:databricks-workflow"
6565
],
6666
"main": "out/extension.js",
67+
"types": "out/extension.d.ts",
6768
"contributes": {
6869
"commands": [
6970
{
@@ -452,7 +453,7 @@
452453
"test:unit": "yarn run build && node ./out/test/runTest.js",
453454
"test:integ:clean": "yarn run clean && rm -rf /tmp/vscode-test-databricks /tmp/databricks-vscode-test-extensions",
454455
"test:integ:prepare": "CODE_VERSION=1.69.1 && yarn run package && extest get-vscode --code_version $CODE_VERSION --storage /tmp/vscode-test-databricks && extest get-chromedriver --code_version 1.69.1 --storage /tmp/vscode-test-databricks",
455-
"test:integ:install-vsix": "extest install-vsix --storage /tmp/vscode-test-databricks -f databricks-0.0.1.vsix -e /tmp/databricks-vscode-test-extensions",
456+
"test:integ:install-vsix": "extest install-vsix --storage /tmp/vscode-test-databricks -f databricks-vscode*.vsix -e /tmp/databricks-vscode-test-extensions",
456457
"test:integ:run": "yarn run build && node out/test/e2e/scripts/e2e.js -e /tmp/databricks-vscode-test-extensions --storage /tmp/vscode-test-databricks --code_settings src/test/e2e/settings.json 'out/**/*.e2e.js'",
457458
"test:integ": "yarn run test:integ:prepare && yarn run test:integ:install-vsix && yarn run test:integ:run",
458459
"test:cov": "nyc yarn run test:unit",
@@ -461,6 +462,7 @@
461462
},
462463
"dependencies": {
463464
"@databricks/databricks-sdk": "*",
465+
"@databricks/databricks-vscode-types": "workspace:^",
464466
"@vscode/debugadapter": "^1.57.0",
465467
"@vscode/webview-ui-toolkit": "^1.0.1"
466468
},
@@ -505,4 +507,4 @@
505507
],
506508
"report-dir": "coverage"
507509
}
508-
}
510+
}

0 commit comments

Comments
 (0)