mirror of
https://github.com/microsoft/vscode-extension-samples.git
synced 2026-04-27 16:55:44 +08:00
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:
@ -9,8 +9,6 @@
|
||||
"categories": [
|
||||
"Other"
|
||||
],
|
||||
"activationEvents": [],
|
||||
"main": "./out/extension/extension.js",
|
||||
"contributes": {
|
||||
"notebookRenderer": [
|
||||
{
|
||||
|
||||
@ -1,5 +0,0 @@
|
||||
.json code {
|
||||
font-family: monospace;
|
||||
font-size: 12px;
|
||||
color: lightblue;
|
||||
}
|
||||
|
||||
@ -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() { }
|
||||
@ -1,8 +0,0 @@
|
||||
{
|
||||
"extends": "../tsconfig-base.json",
|
||||
"compilerOptions": {
|
||||
"rootDir": ".",
|
||||
"outDir": "../../out/extension",
|
||||
},
|
||||
"references": []
|
||||
}
|
||||
@ -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\``,
|
||||
);
|
||||
})();
|
||||
@ -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();
|
||||
@ -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));
|
||||
});
|
||||
});
|
||||
@ -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);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
@ -1,8 +0,0 @@
|
||||
{
|
||||
"extends": "../tsconfig-base.json",
|
||||
"compilerOptions": {
|
||||
"rootDir": ".",
|
||||
"outDir": "../../out/test",
|
||||
},
|
||||
"references": []
|
||||
}
|
||||
@ -3,12 +3,6 @@
|
||||
"references": [
|
||||
{
|
||||
"path": "./src/client"
|
||||
},
|
||||
{
|
||||
"path": "./src/test"
|
||||
},
|
||||
{
|
||||
"path": "./src/extension"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user