Remove notebook provider code from renderer examples (#472)

* remove extension code from renderer

* remove notebook provider code from simple renderer
This commit is contained in:
tanhakabir
2021-08-03 11:41:51 -07:00
committed by GitHub
parent 3d5bb2c378
commit 52dce4cdf0
23 changed files with 0 additions and 487 deletions

View File

@ -9,8 +9,6 @@
"categories": [
"Other"
],
"activationEvents": [],
"main": "./out/extension/extension.js",
"contributes": {
"notebookRenderer": [
{

View File

@ -1,5 +0,0 @@
.json code {
font-family: monospace;
font-size: 12px;
color: lightblue;
}

View File

@ -1,13 +0,0 @@
// The module 'vscode' contains the VS Code extensibility API
// Import the module and reference it with the alias vscode in your code below
import * as vscode from 'vscode';
// This method is called when your extension is activated
// your extension is activated the very first time the command is executed
export function activate(context: vscode.ExtensionContext) {
}
// This method is called when your extension is deactivated
export function deactivate() { }

View File

@ -1,8 +0,0 @@
{
"extends": "../tsconfig-base.json",
"compilerOptions": {
"rootDir": ".",
"outDir": "../../out/extension",
},
"references": []
}

View File

@ -1,129 +0,0 @@
// This script checks that the test provider isn't included in the package.json
// or extension.ts. The extension provider is given as a tool for development,
// but should not be published to the marketplace.
//
// This script is not super comprehensive, it's just here to prevent simple mistakes.
import * as ts from 'typescript';
import * as path from 'path';
import { readFileSync, existsSync, writeFileSync } from 'fs';
import { EOL } from 'os';
const rootDir = path.resolve(__dirname, '..', '..');
const packageJson = require('../../package.json');
class DetectedError extends Error {
constructor(message: string, public readonly fix: () => void) {
super(message);
}
}
const checkNotInExtensionTs = () => {
const entrypoint = path.resolve(rootDir, 'src', 'extension', 'extension.ts');
if (!existsSync(entrypoint)) {
return;
}
const contents = readFileSync(entrypoint, 'utf-8');
const program = ts.createSourceFile(
path.basename(entrypoint),
contents,
ts.ScriptTarget.ESNext,
true,
);
const removeRegistration = (node: ts.Node) => () => writeFileSync(
entrypoint,
contents.slice(0, node.pos) + contents.slice(node.end + +(contents[node.end] === ',')),
);
ts.forEachChild(program, function walk(node: ts.Node) {
if (
ts.isCallExpression(node) &&
/(^|\W)registerNotebookContentProvider$/.test(node.expression.getText()) &&
node.arguments[1]?.getText().includes('SampleContentProvider')
) {
throw new DetectedError(
'`registerNotebookContentProvider()` is still called with the SampleContentProvider.',
removeRegistration(node),
);
}
if (
ts.isCallExpression(node) &&
/(^|\W)registerNotebookKernel$/.test(node.expression.getText()) &&
node.arguments[2]?.getText().includes('SampleKernel')
) {
throw new DetectedError(
'`registerNotebookKernel()` is still called with the TestKernel.',
removeRegistration(node),
);
}
ts.forEachChild(node, walk);
});
};
const checkNotInPackageJson = () => {
const providers = packageJson.contributes?.notebookProvider ?? [];
const testIndex = providers.findIndex(
(p: { viewType: string }) => p.viewType === 'test-notebook-renderer',
);
if (testIndex !== -1) {
throw new DetectedError(
`The "test-notebook-renderer" is still registered in the contributes section of your package.json.`,
() => {
providers.splice(testIndex, 1);
writeFileSync(
path.resolve(rootDir, 'package.json'),
JSON.stringify(packageJson, null, 2) + EOL,
);
},
);
}
};
(() => {
if (process.argv.includes('--fix')) {
while (true) {
try {
checkNotInPackageJson();
checkNotInExtensionTs();
} catch (e) {
if (!(e instanceof DetectedError)) {
throw e;
} else {
e.fix();
continue;
}
}
return console.log('Test provider removed!');
}
}
let errors: DetectedError[] = [];
for (const check of [checkNotInPackageJson, checkNotInExtensionTs]) {
try {
check();
} catch (e) {
if (!(e instanceof DetectedError)) {
throw e;
}
errors.push(e);
}
}
if (!errors.length) {
return;
}
const execPath = path.relative(process.cwd(), __filename);
console.error(errors.map((e) => e.message).join(' '));
console.error('');
console.error(
'You should remove the test provider before publishing your extension to avoid ' +
`conflicts. To fix this automatically, run \`node ${execPath} --fix\``,
);
})();

View File

@ -1,23 +0,0 @@
import * as path from 'path';
import { runTests } from 'vscode-test';
async function main() {
try {
// The folder containing the Extension Manifest package.json
// Passed to `--extensionDevelopmentPath`
const extensionDevelopmentPath = path.resolve(__dirname, '../../');
// The path to test runner
// Passed to --extensionTestsPath
const extensionTestsPath = path.resolve(__dirname, './suite/index');
// Download VS Code, unzip it and run the integration test
await runTests({ extensionDevelopmentPath, extensionTestsPath });
} catch (err) {
console.error('Failed to run tests');
process.exit(1);
}
}
main();

View File

@ -1,15 +0,0 @@
import * as assert from 'assert';
// You can import and use all API from the 'vscode' module
// as well as import your extension to test it
import * as vscode from 'vscode';
// import * as myExtension from '../extension';
suite('Extension Test Suite', () => {
vscode.window.showInformationMessage('Start all tests.');
test('Sample test', () => {
assert.strictEqual(-1, [1, 2, 3].indexOf(5));
assert.strictEqual(-1, [1, 2, 3].indexOf(0));
});
});

View File

@ -1,37 +0,0 @@
import * as path from 'path';
import * as Mocha from 'mocha';
import * as glob from 'glob';
export function run(): Promise<void> {
// Create the mocha test
const mocha = new Mocha({
ui: 'tdd',
});
const testsRoot = path.resolve(__dirname, '..');
return new Promise((c, e) => {
glob('**/**.test.js', { cwd: testsRoot }, (err, files) => {
if (err) {
return e(err);
}
// Add files to the test suite
files.forEach(f => mocha.addFile(path.resolve(testsRoot, f)));
try {
// Run the mocha test
mocha.run(failures => {
if (failures > 0) {
e(new Error(`${failures} tests failed.`));
} else {
c();
}
});
} catch (err) {
console.error(err);
e(err);
}
});
});
}

View File

@ -1,8 +0,0 @@
{
"extends": "../tsconfig-base.json",
"compilerOptions": {
"rootDir": ".",
"outDir": "../../out/test",
},
"references": []
}

View File

@ -3,12 +3,6 @@
"references": [
{
"path": "./src/client"
},
{
"path": "./src/test"
},
{
"path": "./src/extension"
}
]
}