Skip to content

Commit 1cf4986

Browse files
committed
initial commit
0 parents  commit 1cf4986

30 files changed

+3449
-0
lines changed

.eslintrc.json

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"root": true,
3+
"parser": "@typescript-eslint/parser",
4+
"parserOptions": {
5+
"ecmaVersion": 6,
6+
"sourceType": "module"
7+
},
8+
"plugins": [
9+
"@typescript-eslint"
10+
],
11+
"rules": {
12+
"@typescript-eslint/naming-convention": "warn",
13+
"@typescript-eslint/semi": "warn",
14+
"curly": "warn",
15+
"eqeqeq": "warn",
16+
"no-throw-literal": "warn",
17+
"semi": "off"
18+
},
19+
"ignorePatterns": [
20+
"**/*.d.ts"
21+
]
22+
}

.gitattributes

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Set default behavior to automatically normalize line endings.
2+
* text=auto

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
out
2+
node_modules
3+
.vscode-test/
4+
*.vsix

.vscode/extensions.json

+8
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+
"eamodio.tsl-problem-matcher"
7+
]
8+
}

.vscode/launch.json

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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": "pwa-extensionHost",
11+
"request": "launch",
12+
"args": [
13+
"--extensionDevelopmentPath=${workspaceFolder}"
14+
],
15+
"outFiles": [
16+
"${workspaceFolder}/out/**/*.js"
17+
],
18+
"debugWebviews": {
19+
"urlFilter": "*notebookRenderer*"
20+
},
21+
"trace": true,
22+
"preLaunchTask": "npm: dev"
23+
},
24+
{
25+
"name": "Run Extension (no server)",
26+
"type": "extensionHost",
27+
"request": "launch",
28+
"args": [
29+
"--extensionDevelopmentPath=${workspaceFolder}"
30+
],
31+
"outFiles": [
32+
"${workspaceFolder}/out/**/*.js"
33+
],
34+
"debugWebviews": true,
35+
"preLaunchTask": "npm: watch"
36+
},
37+
{
38+
"name": "Extension Tests",
39+
"type": "extensionHost",
40+
"request": "launch",
41+
"args": [
42+
"--extensionDevelopmentPath=${workspaceFolder}",
43+
"--extensionTestsPath=${workspaceFolder}/out/test/suite/index"
44+
],
45+
"outFiles": [
46+
"${workspaceFolder}/out/test/**/*.js"
47+
],
48+
"preLaunchTask": "${defaultBuildTask}"
49+
}
50+
]
51+
}

.vscode/settings.json

+11
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+
}

.vscode/tasks.json

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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": "dev",
9+
"problemMatcher": ["$tsc-watch", "$ts-checker-webpack-watch"],
10+
"isBackground": true,
11+
"presentation": {
12+
"reveal": "never"
13+
},
14+
"group": {
15+
"kind": "build",
16+
"isDefault": true
17+
}
18+
},
19+
{
20+
"type": "npm",
21+
"script": "watch",
22+
"problemMatcher": ["$tsc-watch", "$ts-checker-webpack-watch"],
23+
"isBackground": true,
24+
"presentation": {
25+
"reveal": "never"
26+
},
27+
"group": "build"
28+
},
29+
{
30+
"type": "npm",
31+
"script": "compile",
32+
"problemMatcher": ["$tsc", "$ts-checker-webpack"],
33+
"group": "build"
34+
}
35+
]
36+
}

.vscodeignore

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
.vscode/**
2+
.vscode-test/**
3+
out/test/**
4+
src/**
5+
.gitignore
6+
.yarnrc
7+
vsc-extension-quickstart.md
8+
**/tsconfig.json
9+
**/.eslintrc.json
10+
**/*.map
11+
**/*.ts
12+
**/*.tsbuildinfo

.yarnrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--ignore-engines true

CHANGELOG.md

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Change Log
2+
3+
All notable changes to the "sqlnotebook" extension will be documented in this file.
4+
5+
Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file.
6+
7+
## [Unreleased]
8+
9+
- Initial release

README.md

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# sqlnotebook
2+
3+
⚠️ Work-in-progress starter code for custom notebook renderers in VS Code. Expect this to change as notebooks matures. ⚠️
4+
5+
This starter includes:
6+
7+
- 🖥️ TypeScript code to create a simple `NotebookOutputRenderer`
8+
- 📦 A Webpack build for renderer client code
9+
- ⚡ Support for hot module reloading and safe boilerplate
10+
- 🎨 CSS modules support
11+
12+
### Running this Sample
13+
14+
1. `cd sqlnotebook`
15+
1. `code-insiders .`: Open the folder in VS Code Insiders
16+
1. Hit `F5` to build+debug
17+
18+
### Structure
19+
20+
A Notebook Renderer consists of code that runs in the VS Code Extension Host (Node.js), which registers the renderer and passes data into the UI code running inside a WebView (Browser/DOM).
21+
22+
This uses TypeScript project references. There are three projects in the `src` directory:
23+
24+
- `extension` contains the code running in Node.js extension host. It's compiled with `tsc`.
25+
- `client` is the UI code, built by Webpack, with access to the DOM.
26+
- `common` contains code shared between the extension and client.
27+
28+
When you run `watch`, `compile`, or `dev`, we invoke both `tsc` and `webpack` to compile the extension and the client portion of the code.

package.json

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
{
2+
"name": "sqlnotebook",
3+
"displayName": "sqlnotebook",
4+
"description": "A notebook for exploratory SQL work.",
5+
"version": "0.0.1",
6+
"engines": {
7+
"vscode": "^1.59.0"
8+
},
9+
"categories": [
10+
"Other"
11+
],
12+
"activationEvents": [],
13+
"main": "./out/extension/extension.js",
14+
"contributes": {
15+
"notebookRenderer": [
16+
{
17+
"id": "sqlnotebook",
18+
"entrypoint": "./out/client/index.js",
19+
"displayName": "SQL Notebook",
20+
"mimeTypes": ["x-application/sample-json-renderer"]
21+
}
22+
]
23+
},
24+
"scripts": {
25+
"vscode:prepublish": "npm run compile && node out/test/checkNoTestProvider.js",
26+
"compile": "npm run compile:extension && npm run compile:client",
27+
"compile:extension": "tsc -b",
28+
"compile:client": "webpack --mode production",
29+
"lint": "eslint src --ext ts",
30+
"watch": "concurrently -r \"npm:watch:*\"",
31+
"watch:extension": "tsc -b --watch",
32+
"watch:client": "webpack --mode development --watch",
33+
"dev": "concurrently -r npm:watch:extension npm:watch:client",
34+
"pretest": "npm run compile && npm run lint",
35+
"test": "node ./out/test/runTest.js"
36+
},
37+
"devDependencies": {
38+
"@types/glob": "^7.1.3",
39+
"@types/mocha": "^8.2.2",
40+
"@types/node": "14.x",
41+
"@types/webpack-env": "^1.16.0",
42+
"@typescript-eslint/eslint-plugin": "^4.26.0",
43+
"@typescript-eslint/parser": "^4.26.0",
44+
"@types/vscode-notebook-renderer": "^1.57.8",
45+
"@types/vscode": "^1.59.0",
46+
"concurrently": "^5.3.0",
47+
"css-loader": "^4.2.0",
48+
"eslint": "^7.27.0",
49+
"fork-ts-checker-webpack-plugin": "^5.0.14",
50+
"glob": "^7.1.7",
51+
"mocha": "^8.4.0",
52+
"style-loader": "^1.2.1",
53+
"ts-loader": "^9.2.2",
54+
"typescript": "^4.3.2",
55+
"vscode-notebook-error-overlay": "^1.0.1",
56+
"vscode-test": "^1.5.2",
57+
"webpack": "^5.38.1",
58+
"webpack-cli": "^4.7.0"
59+
}
60+
}

src/client/css.d.ts

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
declare module '*.css' {
2+
const classes: { [className: string]: string };
3+
export = classes;
4+
}

src/client/index.ts

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { render } from './render';
2+
import errorOverlay from 'vscode-notebook-error-overlay';
3+
import type { ActivationFunction } from 'vscode-notebook-renderer';
4+
5+
// Fix the public path so that any async import()'s work as expected.
6+
declare const __webpack_relative_entrypoint_to_root__: string;
7+
declare const scriptUrl: string;
8+
9+
__webpack_public_path__ = new URL(scriptUrl.replace(/[^/]+$/, '') + __webpack_relative_entrypoint_to_root__).toString();
10+
11+
// ----------------------------------------------------------------------------
12+
// This is the entrypoint to the notebook renderer's webview client-side code.
13+
// This contains some boilerplate that calls the `render()` function when new
14+
// output is available. You probably don't need to change this code; put your
15+
// rendering logic inside of the `render()` function.
16+
// ----------------------------------------------------------------------------
17+
18+
export const activate: ActivationFunction = context => {
19+
return {
20+
renderOutputItem(outputItem, element) {
21+
let shadow = element.shadowRoot;
22+
if (!shadow) {
23+
shadow = element.attachShadow({ mode: 'open' });
24+
const root = document.createElement('div');
25+
root.id = 'root';
26+
shadow.append(root);
27+
}
28+
const root = shadow.querySelector<HTMLElement>('#root')!;
29+
errorOverlay.wrap(root, () => {
30+
root.innerHTML = '';
31+
const node = document.createElement('div');
32+
root.appendChild(node);
33+
34+
render({ container: node, mime: outputItem.mime, value: outputItem.json(), context });
35+
});
36+
},
37+
disposeOutputItem(outputId) {
38+
// Do any teardown here. outputId is the cell output being deleted, or
39+
// undefined if we're clearing all outputs.
40+
}
41+
};
42+
};

src/client/render.ts

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// We've set up this sample using CSS modules, which lets you import class
2+
// names into JavaScript: https://github.com/css-modules/css-modules
3+
// You can configure or change this in the webpack.config.js file.
4+
import * as style from './style.css';
5+
import type { RendererContext } from 'vscode-notebook-renderer';
6+
7+
interface IRenderInfo {
8+
container: HTMLElement;
9+
mime: string;
10+
value: any;
11+
context: RendererContext<unknown>;
12+
}
13+
14+
// This function is called to render your contents.
15+
export function render({ container, mime, value }: IRenderInfo) {
16+
// Format the JSON and insert it as <pre><code>{ ... }</code></pre>
17+
// Replace this with your custom code!
18+
const pre = document.createElement('pre');
19+
pre.classList.add(style.json);
20+
const code = document.createElement('code');
21+
code.textContent = `mime type: ${mime}\n\n${JSON.stringify(value, null, 2)}`;
22+
pre.appendChild(code);
23+
container.appendChild(pre);
24+
}
25+
26+
if (module.hot) {
27+
module.hot.addDisposeHandler(() => {
28+
// In development, this will be called before the renderer is reloaded. You
29+
// can use this to clean up or stash any state.
30+
});
31+
}

src/client/style.css

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.json code {
2+
font-family: monospace;
3+
font-size: 12px;
4+
color: lightblue;
5+
}

src/client/tsconfig.json

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"extends": "../tsconfig-base.json",
3+
"compilerOptions": {
4+
// noEmit prevents the default tsc from building this--we use webpack instead
5+
"noEmit": true,
6+
"rootDir": ".",
7+
"module": "esnext",
8+
"lib": ["ES2019", "dom"],
9+
"types": ["webpack-env", "vscode-notebook-renderer"],
10+
}
11+
}

src/extension/extension.ts

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// The module 'vscode' contains the VS Code extensibility API
2+
// Import the module and reference it with the alias vscode in your code below
3+
import * as vscode from 'vscode';
4+
5+
6+
// This method is called when your extension is activated
7+
// your extension is activated the very first time the command is executed
8+
export function activate(context: vscode.ExtensionContext) {
9+
throw new Error("failed to activie");
10+
}
11+
12+
// This method is called when your extension is deactivated
13+
export function deactivate() { }

src/extension/tsconfig.json

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"extends": "../tsconfig-base.json",
3+
"compilerOptions": {
4+
"rootDir": ".",
5+
"outDir": "../../out/extension",
6+
},
7+
"references": []
8+
}

src/extension/types/.gitkeep

Whitespace-only changes.

0 commit comments

Comments
 (0)