text:
import * as assert from 'assert';
import { setUnexpectedErrorHandler, errorHandler } from 'vs/base/common/errors';
import { TestInstantiationService } from 'vs/platform/instantiation/test/common/instantiationServiceMock';
import { URI } from 'vs/base/common/uri';
import * as types from 'vs/workbench/api/common/extHostTypes';
import { TextModel as EditorModel } from 'vs/editor/common/model/textModel';
import { TestRPCProtocol } from './testRPCProtocol';
import { MarkerService } from 'vs/platform/markers/common/markerService';
import { IMarkerService } from 'vs/platform/markers/common/markers';
import { ICommandService, CommandsRegistry } from 'vs/platform/commands/common/commands';
import { IModelService } from 'vs/editor/common/services/modelService';
import { ExtHostLanguageFeatures } from 'vs/workbench/api/common/extHostLanguageFeatures';
import { MainThreadLanguageFeatures } from 'vs/workbench/api/browser/mainThreadLanguageFeatures';
import { ExtHostApiCommands } from 'vs/workbench/api/common/extHostApiCommands';
import { ExtHostCommands } from 'vs/workbench/api/common/extHostCommands';
import { MainThreadCommands } from 'vs/workbench/api/browser/mainThreadCommands';
import { ExtHostDocuments } from 'vs/workbench/api/common/extHostDocuments';
import { ExtHostDocumentsAndEditors } from 'vs/workbench/api/common/extHostDocumentsAndEditors';
import { MainContext, ExtHostContext } from 'vs/workbench/api/common/extHost.protocol';
import { ExtHostDiagnostics } from 'vs/workbench/api/common/extHostDiagnostics';
import * as vscode from 'vscode';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import 'vs/workbench/contrib/search/browser/search.contribution';
import { NullLogService } from 'vs/platform/log/common/log';
import { ITextModel } from 'vs/editor/common/model';
import { nullExtensionDescription } from 'vs/workbench/services/extensions/common/extensions';
import { dispose } from 'vs/base/common/lifecycle';

const defaultSelector = { scheme: 'far' };
const model: ITextModel = EditorModel.createFromString(
	[
		'This is the first line',
		'This is the second line',
		'This is the third line',
	].join('\n'),
	undefined,
	undefined,
	URI.parse('far://testing/file.b'));

let rpcProtocol: TestRPCProtocol;
let extHost: ExtHostLanguageFeatures;
let mainThread: MainThreadLanguageFeatures;
let commands: ExtHostCommands;
let disposables: vscode.Disposable[] = [];
let originalErrorHandler: (e: any) => any;

function assertRejects(fn: () => Promise<any>, message: string = 'Expected rejection') {
	return fn().then(() => assert.ok(false, message), _err => assert.ok(true));
}

suite('ExtHostLanguageFeatureCommands', function () {

	suiteSetup(() => {

		originalErrorHandler = errorHandler.getUnexpectedErrorHandler();
		setUnexpectedErrorHandler(() => { });

		// Use IInstantiationService to get typechecking when instantiating
		let inst: IInstantiationService;
		{
			let instantiationService = new TestInstantiationService();
			rpcProtocol = new TestRPCProtocol();
			instantiationService.stub(ICommandService, {
				_serviceBrand: undefined,
				executeCommand(id: string, args: any): any {
					const command = CommandsRegistry.getCommands().get(id);
					if (!command) {
						return Promise.reject(new Error(id + ' NOT known'));
					}
					const { handler } = command;
					return Promise.resolve(instantiationService.invokeFunction(handler, args));
				}
			});
			instantiationService.stub(IMarkerService, new MarkerService());
			instantiationService.stub(IModelService, <IModelService>{
				_serviceBrand: IModelService,
				getModel(): any { return model; },
				createModel() { throw new Error(); },
				updateModel() { throw new Error(); },
				setMode() { throw new Error(); },
				destroyModel() { throw new Error(); },
				getModels() { throw new Error(); },
				onModelAdded: undefined!,
				onModelModeChanged: undefined!,
				onModelRemoved: undefined!,
				getCreationOptions() { throw new Error(); }
			});
			inst = instantiationService;
		}

		const extHostDocumentsAndEditors = new ExtHostDocumentsAndEditors(rpcProtocol);
		extHostDocumentsAndEditors.$acceptDocumentsAndEditorsDelta({
			addedDocuments: [{
				isDirty: false,
				versionId: model.getVersionId(),
				modeId: model.getLanguageIdentifier().language,
				uri: model.uri,
				lines: model.getValue().split(model.getEOL()),
				EOL: model.getEOL(),
			}]
		});
		const extHostDocuments = new ExtHostDocuments(rpcProtocol, extHostDocumentsAndEditors);
		rpcProtocol.set(ExtHostContext.ExtHostDocuments, extHostDocuments);

		commands = new ExtHostCommands(rpcProtocol, new NullLogService());
		rpcProtocol.set(ExtHostContext.ExtHostCommands, commands);
		rpcProtocol.set(MainContext.MainThreadCommands, inst.createInstance(MainThreadCommands, rpcProtocol));
		ExtHostApiCommands.register(commands);

		const diagnostics = new ExtHostDiagnostics(rpcProtocol);
		rpcProtocol.set(ExtHostContext.ExtHostDiagnostics, diagnostics);

		extHost = new ExtHostLanguageFeatures(rpcProtocol, null, extHostDocuments, commands, diagnostics, new NullLogService());
		rpcProtocol.set(ExtHostContext.ExtHostLanguageFeatures, extHost);

		mainThread = rpcProtocol.set(MainContext.MainThreadLanguageFeatures, inst.createInstance(MainThreadLanguageFeatures, rpcProtocol));

		return rpcProtocol.sync();
	});

	suiteTeardown(() => {
		setUnexpectedErrorHandler(originalErrorHandler);
		model.dispose();
		mainThread.dispose();
	});

	teardown(() => {
		disposables = dispose(disposables);
		return rpcProtocol.sync();
	});

	// --- workspace symbols

	test('WorkspaceSymbols, invalid arguments', function () {
		let promises = [
			assertRejects(() => commands.executeCommand('vscode.executeWorkspaceSymbolProvider')),
			assertRejects(() => commands.executeCommand('vscode.executeWorkspaceSymbolProvider', null)),
			assertRejects(() => commands.executeCommand('vscode.executeWorkspaceSymbolProvider', undefined)),
			assertRejects(() => commands.executeCommand('vscode.executeWorkspaceSymbolProvider', true))
		];
		return Promise.all(promises);
	});

	test('WorkspaceSymbols, back and forth', function () {

		disposables.push(extHost.registerWorkspaceSymbolProvider(nullExtensionDescription, <vscode.WorkspaceSymbolProvider>{
			provideWorkspaceSymbols(query): any {
				return [
					new types.SymbolInformation(query, types.SymbolKind.Array, new types.Range(0, 0, 1, 1), URI.parse('far://testing/first')),
					new types.SymbolInformation(query, types.SymbolKind.Array, new types.Range(0, 0, 1, 1), URI.parse('far://testing/second'))
				];
			}
		}));

		disposables.push(extHost.registerWorkspaceSymbolProvider(nullExtensionDescription, <vscode.WorkspaceSymbolProvider>{
			provideWorkspaceSymbols(query): any {
				return [
					new types.SymbolInformation(query, types.SymbolKind.Array, new types.Range(0, 0, 1, 1), URI.parse('far://testing/first'))
				];
			}
		}));

		return rpcProtocol.sync().then(() => {
			return commands.executeCommand<vscode.SymbolInformation[]>('vscode.executeWorkspaceSymbolProvider', 'testing').then(value => {

				for (let info of value) {
					assert.ok(info instanceof types.SymbolInformation);
					assert.equal(info.name, 'testing');
					assert.equal(info.kind, types.SymbolKind.Array);
				}
				assert.equal(value.length, 3);
			});
		});
	});

	test('executeWorkspaceSymbolProvider should accept empty string, #39522', async function () {

		disposables.push(extHost.registerWorkspaceSymbolProvider(nullExtensionDescription, {
			provideWorkspaceSymbols(query): vscode.SymbolInformation[] {
				return [new types.SymbolInformation('hello', types.SymbolKind.Array, new types.Range(0, 0, 0, 0), URI.parse('foo:bar')) as vscode.SymbolInformation];
			}
		}));

		await rpcProtocol.sync();
		let symbols = await commands.executeCommand<vscode.SymbolInformation[]>('vscode.executeWorkspaceSymbolProvider', '');
		assert.equal(symbols.length, 1);

		await rpcProtocol.sync();
		symbols = await commands.executeCommand<vscode.SymbolInformation[]>('vscode.executeWorkspaceSymbolProvider', '*');
		assert.equal(symbols.length, 1);
	});

	// --- definition

	test('Definition, invalid arguments', function () {
		let promises = [
			assertRejects(() => commands.executeCommand('vscode.executeDefinitionProvider')),
			assertRejects(() => commands.executeCommand('vscode.executeDefinitionProvider', null)),
			assertRejects(() => commands.executeCommand('vscode.executeDefinitionProvider', undefined)),
			assertRejects(() => commands.executeCommand('vscode.executeDefinitionProvider', true, false))
		];

		return Promise.all(promises);
	});

	test('Definition, back and forth', function () {

		disposables.push(extHost.registerDefinitionProvider(nullExtensionDescription, defaultSelector, <vscode.DefinitionProvider>{
			provideDefinition(doc: any): any {
				return new types.Location(doc.uri, new types.Range(0, 0, 0, 0));
			}
		}));
		disposables.push(extHost.registerDefinitionProvider(nullExtensionDescription, defaultSelector, <vscode.DefinitionProvider>{
			provideDefinition(doc: any): any {
				return [
					new types.Location(doc.uri, new types.Range(0, 0, 0, 0)),
					new types.Location(doc.uri, new types.Range(0, 0, 0, 0)),
					new types.Location(doc.uri, new types.Range(0, 0, 0, 0)),
				];
			}
		}));

		return rpcProtocol.sync().then(() => {
			return commands.executeCommand<vscode.Location[]>('vscode.executeDefinitionProvider', model.uri, new types.Position(0, 0)).then(values => {
				assert.equal(values.length, 4);
				for (let v of values) {
					assert.ok(v.uri instanceof URI);
					assert.ok(v.range instanceof types.Range);
				}
			});
		});
	});

	// --- declaration

	test('Declaration, back and forth', function () {

		disposables.push(extHost.registerDeclarationProvider(nullExtensionDescription, defaultSelector, <vscode.DeclarationProvider>{
			provideDeclaration(doc: any): any {
				return new types.Location(doc.uri, new types.Range(0, 0, 0, 0));
			}
		}));
		disposables.push(extHost.registerDeclarationProvider(nullExtensionDescription, defaultSelector, <vscode.DeclarationProvider>{
			provideDeclaration(doc: any): any {
				return [
					new types.Location(doc.uri, new types.Range(0, 0, 0, 0)),
					new types.Location(doc.uri, new types.Range(0, 0, 0, 0)),
					new types.Location(doc.uri, new types.Range(0, 0, 0, 0)),
				];
			}
		}));

		return rpcProtocol.sync().then(() => {
			return commands.executeCommand<vscode.Location[]>('vscode.executeDeclarationProvider', model.uri, new types.Position(0, 0)).then(values => {
				assert.equal(values.length, 4);
				for (let v of values) {
					assert.ok(v.uri instanceof URI);
					assert.ok(v.range instanceof types.Range);
				}
			});
		});
	});

	// --- type definition

	test('Type Definition, invalid arguments', function () {
		const promises = [
			assertRejects(() => commands.executeCommand('vscode.executeTypeDefinitionProvider')),
			assertRejects(() => commands.executeCommand('vscode.executeTypeDefinitionProvider', null)),
			assertRejects(() => commands.executeCommand('vscode.executeTypeDefinitionProvider', undefined)),
			assertRejects(() => commands.executeCommand('vscode.executeTypeDefinitionProvider', true, false))
		];

		return Promise.all(promises);
	});

	test('Type Definition, back and forth', function () {

		disposables.push(extHost.registerTypeDefinitionProvider(nullExtensionDescription, defaultSelector, <vscode.TypeDefinitionProvider>{
			provideTypeDefinition(doc: any): any {
				return new types.Location(doc.uri, new types.Range(0, 0, 0, 0));
			}
		}));
		disposables.push(extHost.registerTypeDefinitionProvider(nullExtensionDescription, defaultSelector, <vscode.TypeDefinitionProvider>{
			provideTypeDefinition(doc: any): any {
				return [
					new types.Location(doc.uri, new types.Range(0, 0, 0, 0)),
					new types.Location(doc.uri, new types.Range(0, 0, 0, 0)),
					new types.Location(doc.uri, new types.Range(0, 0, 0, 0)),
				];
			}
		}));

		return rpcProtocol.sync().then(() => {
			return commands.executeCommand<vscode.Location[]>('vscode.executeTypeDefinitionProvider', model.uri, new types.Position(0, 0)).then(values => {
				assert.equal(values.length, 4);
				for (const v of values) {
					assert.ok(v.uri instanceof URI);
					assert.ok(v.range instanceof types.Range);
				}
			});
		});
	});

	// --- references

	test('reference search, back and forth', function () {

		disposables.push(extHost.registerReferenceProvider(nullExtensionDescription, defaultSelector, <vscode.ReferenceProvider>{
			provideReferences(doc: any) {
				return [
					new types.Location(URI.parse('some:uri/path'), new types.Range(0, 1, 0, 5))
				];
			}
		}));

		return commands.executeCommand<vscode.Location[]>('vscode.executeReferenceProvider', model.uri, new types.Position(0, 0)).then(values => {
			assert.equal(values.length, 1);
			let [first] = values;
			assert.equal(first.uri.toString(), 'some:uri/path');
			assert.equal(first.range.start.line, 0);
			assert.equal(first.range.start.character, 1);
			assert.equal(first.range.end.line, 0);
			assert.equal(first.range.end.character, 5);
		});
	});

	// --- outline

	test('Outline, back and forth', function () {
		disposables.push(extHost.registerDocumentSymbolProvider(nullExtensionDescription, defaultSelector, <vscode.DocumentSymbolProvider>{
			provideDocumentSymbols(): any {
				return [
					new types.SymbolInformation('testing1', types.SymbolKind.Enum, new types.Range(1, 0, 1, 0)),
					new types.SymbolInformation('testing2', types.SymbolKind.Enum, new types.Range(0, 1, 0, 3)),
				];
			}
		}));

		return rpcProtocol.sync().then(() => {
			return commands.executeCommand<vscode.SymbolInformation[]>('vscode.executeDocumentSymbolProvider', model.uri).then(values => {
				assert.equal(values.length, 2);
				let [first, second] = values;
				assert.ok(first instanceof types.SymbolInformation);
				assert.ok(second instanceof types.SymbolInformation);
				assert.equal(first.name, 'testing2');
				assert.equal(second.name, 'testing1');
			});
		});
	});

	test('vscode.executeDocumentSymbolProvider command only returns SymbolInformation[] rather than DocumentSymbol[] #57984', function () {
		disposables.push(extHost.registerDocumentSymbolProvider(nullExtensionDescription, defaultSelector, <vscode.DocumentSymbolProvider>{
			provideDocumentSymbols(): any {
				return [
					new types.SymbolInformation('SymbolInformation', types.SymbolKind.Enum, new types.Range(1, 0, 1, 0))
				];
			}
		}));
		disposables.push(extHost.registerDocumentSymbolProvider(nullExtensionDescription, defaultSelector, <vscode.DocumentSymbolProvider>{
			provideDocumentSymbols(): any {
				let root = new types.DocumentSymbol('DocumentSymbol', 'DocumentSymbol#detail', types.SymbolKind.Enum, new types.Range(1, 0, 1, 0), new types.Range(1, 0, 1, 0));
				root.children = [new types.DocumentSymbol('DocumentSymbol#child', 'DocumentSymbol#detail#child', types.SymbolKind.Enum, new types.Range(1, 0, 1, 0), new types.Range(1, 0, 1, 0))];
				return [root];
			}
		}));

		return rpcProtocol.sync().then(() => {
			return commands.executeCommand<(vscode.SymbolInformation & vscode.DocumentSymbol)[]>('vscode.executeDocumentSymbolProvider', model.uri).then(values => {
				assert.equal(values.length, 2);
				let [first, second] = values;
				assert.ok(first instanceof types.SymbolInformation);
				assert.ok(!(first instanceof types.DocumentSymbol));
				assert.ok(second instanceof types.SymbolInformation);
				assert.equal(first.name, 'DocumentSymbol');
				assert.equal(first.children.length, 1);
				assert.equal(second.name, 'SymbolInformation');
			});
		});
	});

	// --- suggest

	test('Suggest, back and forth', function () {
		disposables.push(extHost.registerCompletionItemProvider(nullExtensionDescription, defaultSelector, <vscode.CompletionItemProvider>{
			provideCompletionItems(doc, pos): any {
				let a = new types.CompletionItem('item1');
				let b = new types.CompletionItem('item2');
				b.textEdit = types.TextEdit.replace(new types.Range(0, 4, 0, 8), 'foo'); // overwite after
				let c = new types.CompletionItem('item3');
				c.textEdit = types.TextEdit.replace(new types.Range(0, 1, 0, 6), 'foobar'); // overwite before & after

				// snippet string!
				let d = new types.CompletionItem('item4');
				d.range = new types.Range(0, 1, 0, 4);// overwite before
				d.insertText = new types.SnippetString('foo$0bar');
				return [a, b, c, d];
			}
		}, []));

		return rpcProtocol.sync().then(() => {
			return commands.executeCommand<vscode.CompletionList>('vscode.executeCompletionItemProvider', model.uri, new types.Position(0, 4)).then(list => {

				assert.ok(list instanceof types.CompletionList);
				let values = list.items;
				assert.ok(Array.isArray(values));
				assert.equal(values.length, 4);
				let [first, second, third, fourth] = values;
				assert.equal(first.label, 'item1');
				assert.equal(first.textEdit!.newText, 'item1');
				assert.equal(first.textEdit!.range.start.line, 0);
				assert.equal(first.textEdit!.range.start.character, 0);
				assert.equal(first.textEdit!.range.end.line, 0);
				assert.equal(first.textEdit!.range.end.character, 4);

				assert.equal(second.label, 'item2');
				assert.equal(second.textEdit!.newText, 'foo');
				assert.equal(second.textEdit!.range.start.line, 0);
				assert.equal(second.textEdit!.range.start.character, 4);
				assert.equal(second.textEdit!.range.end.line, 0);
				assert.equal(second.textEdit!.range.end.character, 8);

				assert.equal(third.label, 'item3');
				assert.equal(third.textEdit!.newText, 'foobar');
				assert.equal(third.textEdit!.range.start.line, 0);
				assert.equal(third.textEdit!.range.start.character, 1);
				assert.equal(third.textEdit!.range.end.line, 0);
				assert.equal(third.textEdit!.range.end.character, 6);

				assert.equal(fourth.label, 'item4');
				assert.equal(fourth.textEdit, undefined);
				assert.equal(fourth.range!.start.line, 0);
				assert.equal(fourth.range!.start.character, 1);
				assert.equal(fourth.range!.end.line, 0);
				assert.equal(fourth.range!.end.character, 4);
				assert.ok(fourth.insertText instanceof types.SnippetString);
				assert.equal((<types.SnippetString>fourth.insertText).value, 'foo$0bar');
			});
		});
	});

	test('Suggest, return CompletionList !array', function () {
		disposables.push(extHost.registerCompletionItemProvider(nullExtensionDescription, defaultSelector, <vscode.CompletionItemProvider>{
			provideCompletionItems(): any {
				let a = new types.CompletionItem('item1');
				let b = new types.CompletionItem('item2');
				return new types.CompletionList(<any>[a, b], true);
			}
		}, []));

		return rpcProtocol.sync().then(() => {
			return commands.executeCommand<vscode.CompletionList>('vscode.executeCompletionItemProvider', model.uri, new types.Position(0, 4)).then(list => {
				assert.ok(list instanceof types.CompletionList);
				assert.equal(list.isIncomplete, true);
			});
		});
	});

	test('Suggest, resolve completion items', async function () {

		let resolveCount = 0;

		disposables.push(extHost.registerCompletionItemProvider(nullExtensionDescription, defaultSelector, <vscode.CompletionItemProvider>{
			provideCompletionItems(): any {
				let a = new types.CompletionItem('item1');
				let b = new types.CompletionItem('item2');
				let c = new types.CompletionItem('item3');
				let d = new types.CompletionItem('item4');
				return new types.CompletionList([a, b, c, d], false);
			},
			resolveCompletionItem(item) {
				resolveCount += 1;
				return item;
			}
		}, []));

		await rpcProtocol.sync();

		let list = await commands.executeCommand<vscode.CompletionList>(
			'vscode.executeCompletionItemProvider',
			model.uri,
			new types.Position(0, 4),
			undefined,
			2 // maxItemsToResolve
		);

		assert.ok(list instanceof types.CompletionList);
		assert.equal(resolveCount, 2);

	});

	test('"vscode.executeCompletionItemProvider" doesnot return a preselect field #53749', async function () {
		disposables.push(extHost.registerCompletionItemProvider(nullExtensionDescription, defaultSelector, <vscode.CompletionItemProvider>{
			provideCompletionItems(): any {
				let a = new types.CompletionItem('item1');
				a.preselect = true;
				let b = new types.CompletionItem('item2');
				let c = new types.CompletionItem('item3');
				c.preselect = true;
				let d = new types.CompletionItem('item4');
				return new types.CompletionList([a, b, c, d], false);
			}
		}, []));

		await rpcProtocol.sync();

		let list = await commands.executeCommand<vscode.CompletionList>(
			'vscode.executeCompletionItemProvider',
			model.uri,
			new types.Position(0, 4),
			undefined
		);

		assert.ok(list instanceof types.CompletionList);
		assert.equal(list.items.length, 4);

		let [a, b, c, d] = list.items;
		assert.equal(a.preselect, true);
		assert.equal(b.preselect, undefined);
		assert.equal(c.preselect, true);
		assert.equal(d.preselect, undefined);
	});

	test('executeCompletionItemProvider doesn\'t capture commitCharacters #58228', async function () {
		disposables.push(extHost.registerCompletionItemProvider(nullExtensionDescription, defaultSelector, <vscode.CompletionItemProvider>{
			provideCompletionItems(): any {
				let a = new types.CompletionItem('item1');
				a.commitCharacters = ['a', 'b'];
				let b = new types.CompletionItem('item2');
				return new types.CompletionList([a, b], false);
			}
		}, []));

		await rpcProtocol.sync();

		let list = await commands.executeCommand<vscode.CompletionList>(
			'vscode.executeCompletionItemProvider',
			model.uri,
			new types.Position(0, 4),
			undefined
		);

		assert.ok(list instanceof types.CompletionList);
		assert.equal(list.items.length, 2);

		let [a, b] = list.items;
		assert.deepEqual(a.commitCharacters, ['a', 'b']);
		assert.equal(b.commitCharacters, undefined);
	});

	// --- signatureHelp

	test('Parameter Hints, back and forth', async () => {
		disposables.push(extHost.registerSignatureHelpProvider(nullExtensionDescription, defaultSelector, new class implements vscode.SignatureHelpProvider {
			provideSignatureHelp(_document: vscode.TextDocument, _position: vscode.Position, _token: vscode.CancellationToken, context: vscode.SignatureHelpContext): vscode.SignatureHelp {
				return {
					activeSignature: 0,
					activeParameter: 1,
					signatures: [
						{
							label: 'abc',
							documentation: `${context.triggerKind === 1 /* vscode.SignatureHelpTriggerKind.Invoke */ ? 'invoked' : 'unknown'} ${context.triggerCharacter}`,
							parameters: []
						}
					]
				};
			}
		}, []));

		await rpcProtocol.sync();

		const firstValue = await commands.executeCommand<vscode.SignatureHelp>('vscode.executeSignatureHelpProvider', model.uri, new types.Position(0, 1), ',');
		assert.strictEqual(firstValue.activeSignature, 0);
		assert.strictEqual(firstValue.activeParameter, 1);
		assert.strictEqual(firstValue.signatures.length, 1);
		assert.strictEqual(firstValue.signatures[0].label, 'abc');
		assert.strictEqual(firstValue.signatures[0].documentation, 'invoked ,');
	});

	// --- quickfix

	test('QuickFix, back and forth', function () {
		disposables.push(extHost.registerCodeActionProvider(nullExtensionDescription, defaultSelector, {
			provideCodeActions(): vscode.Command[] {
				return [{ command: 'testing', title: 'Title', arguments: [1, 2, true] }];
			}
		}));

		return rpcProtocol.sync().then(() => {
			return commands.executeCommand<vscode.Command[]>('vscode.executeCodeActionProvider', model.uri, new types.Range(0, 0, 1, 1)).then(value => {
				assert.equal(value.length, 1);
				let [first] = value;
				assert.equal(first.title, 'Title');
				assert.equal(first.command, 'testing');
				assert.deepEqual(first.arguments, [1, 2, true]);
			});
		});
	});

	test('vscode.executeCodeActionProvider results seem to be missing their `command` property #45124', function () {
		disposables.push(extHost.registerCodeActionProvider(nullExtensionDescription, defaultSelector, {
			provideCodeActions(document, range): vscode.CodeAction[] {
				return [{
					command: {
						arguments: [document, range],
						command: 'command',
						title: 'command_title',
					},
					kind: types.CodeActionKind.Empty.append('foo'),
					title: 'title',
				}];
			}
		}));

		return rpcProtocol.sync().then(() => {
			return commands.executeCommand<vscode.CodeAction[]>('vscode.executeCodeActionProvider', model.uri, new types.Range(0, 0, 1, 1)).then(value => {
				assert.equal(value.length, 1);
				const [first] = value;
				assert.ok(first.command);
				assert.equal(first.command!.command, 'command');
				assert.equal(first.command!.title, 'command_title');
				assert.equal(first.kind!.value, 'foo');
				assert.equal(first.title, 'title');

			});
		});
	});

	// --- code lens

	test('CodeLens, back and forth', function () {

		const complexArg = {
			foo() { },
			bar() { },
			big: extHost
		};

		disposables.push(extHost.registerCodeLensProvider(nullExtensionDescription, defaultSelector, <vscode.CodeLensProvider>{
			provideCodeLenses(): any {
				return [new types.CodeLens(new types.Range(0, 0, 1, 1), { title: 'Title', command: 'cmd', arguments: [1, true, complexArg] })];
			}
		}));

		return rpcProtocol.sync().then(() => {
			return commands.executeCommand<vscode.CodeLens[]>('vscode.executeCodeLensProvider', model.uri).then(value => {
				assert.equal(value.length, 1);
				const [first] = value;

				assert.equal(first.command!.title, 'Title');
				assert.equal(first.command!.command, 'cmd');
				assert.equal(first.command!.arguments![0], 1);
				assert.equal(first.command!.arguments![1], true);
				assert.equal(first.command!.arguments![2], complexArg);
			});
		});
	});

	test('CodeLens, resolve', async function () {

		let resolveCount = 0;

		disposables.push(extHost.registerCodeLensProvider(nullExtensionDescription, defaultSelector, <vscode.CodeLensProvider>{
			provideCodeLenses(): any {
				return [
					new types.CodeLens(new types.Range(0, 0, 1, 1)),
					new types.CodeLens(new types.Range(0, 0, 1, 1)),
					new types.CodeLens(new types.Range(0, 0, 1, 1)),
					new types.CodeLens(new types.Range(0, 0, 1, 1), { title: 'Already resolved', command: 'fff' })
				];
			},
			resolveCodeLens(codeLens: types.CodeLens) {
				codeLens.command = { title: resolveCount.toString(), command: 'resolved' };
				resolveCount += 1;
				return codeLens;
			}
		}));

		await rpcProtocol.sync();

		let value = await commands.executeCommand<vscode.CodeLens[]>('vscode.executeCodeLensProvider', model.uri, 2);

		assert.equal(value.length, 3); // the resolve argument defines the number of results being returned
		assert.equal(resolveCount, 2);

		resolveCount = 0;
		value = await commands.executeCommand<vscode.CodeLens[]>('vscode.executeCodeLensProvider', model.uri);

		assert.equal(value.length, 4);
		assert.equal(resolveCount, 0);
	});

	test('Links, back and forth', function () {

		disposables.push(extHost.registerDocumentLinkProvider(nullExtensionDescription, defaultSelector, <vscode.DocumentLinkProvider>{
			provideDocumentLinks(): any {
				return [new types.DocumentLink(new types.Range(0, 0, 0, 20), URI.parse('foo:bar'))];
			}
		}));

		return rpcProtocol.sync().then(() => {
			return commands.executeCommand<vscode.DocumentLink[]>('vscode.executeLinkProvider', model.uri).then(value => {
				assert.equal(value.length, 1);
				let [first] = value;

				assert.equal(first.target + '', 'foo:bar');
				assert.equal(first.range.start.line, 0);
				assert.equal(first.range.start.character, 0);
				assert.equal(first.range.end.line, 0);
				assert.equal(first.range.end.character, 20);
			});
		});
	});

	test('Color provider', function () {

		disposables.push(extHost.registerColorProvider(nullExtensionDescription, defaultSelector, <vscode.DocumentColorProvider>{
			provideDocumentColors(): vscode.ColorInformation[] {
				return [new types.ColorInformation(new types.Range(0, 0, 0, 20), new types.Color(0.1, 0.2, 0.3, 0.4))];
			},
			provideColorPresentations(color: vscode.Color, context: { range: vscode.Range, document: vscode.TextDocument }): vscode.ColorPresentation[] {
				const cp = new types.ColorPresentation('#ABC');
				cp.textEdit = types.TextEdit.replace(new types.Range(1, 0, 1, 20), '#ABC');
				cp.additionalTextEdits = [types.TextEdit.insert(new types.Position(2, 20), '*')];
				return [cp];
			}
		}));

		return rpcProtocol.sync().then(() => {
			return commands.executeCommand<vscode.ColorInformation[]>('vscode.executeDocumentColorProvider', model.uri).then(value => {
				assert.equal(value.length, 1);
				let [first] = value;

				assert.equal(first.color.red, 0.1);
				assert.equal(first.color.green, 0.2);
				assert.equal(first.color.blue, 0.3);
				assert.equal(first.color.alpha, 0.4);
				assert.equal(first.range.start.line, 0);
				assert.equal(first.range.start.character, 0);
				assert.equal(first.range.end.line, 0);
				assert.equal(first.range.end.character, 20);
			});
		}).then(() => {
			const color = new types.Color(0.5, 0.6, 0.7, 0.8);
			const range = new types.Range(0, 0, 0, 20);
			return commands.executeCommand<vscode.ColorPresentation[]>('vscode.executeColorPresentationProvider', color, { uri: model.uri, range }).then(value => {
				assert.equal(value.length, 1);
				let [first] = value;

				assert.equal(first.label, '#ABC');
				assert.equal(first.textEdit!.newText, '#ABC');
				assert.equal(first.textEdit!.range.start.line, 1);
				assert.equal(first.textEdit!.range.start.character, 0);
				assert.equal(first.textEdit!.range.end.line, 1);
				assert.equal(first.textEdit!.range.end.character, 20);
				assert.equal(first.additionalTextEdits!.length, 1);
				assert.equal(first.additionalTextEdits![0].range.start.line, 2);
				assert.equal(first.additionalTextEdits![0].range.start.character, 20);
				assert.equal(first.additionalTextEdits![0].range.end.line, 2);
				assert.equal(first.additionalTextEdits![0].range.end.character, 20);
			});
		});
	});

	test('"TypeError: e.onCancellationRequested is not a function" calling hover provider in Insiders #54174', function () {

		disposables.push(extHost.registerHoverProvider(nullExtensionDescription, defaultSelector, <vscode.HoverProvider>{
			provideHover(): any {
				return new types.Hover('fofofofo');
			}
		}));

		return rpcProtocol.sync().then(() => {
			return commands.executeCommand<vscode.Hover[]>('vscode.executeHoverProvider', model.uri, new types.Position(1, 1)).then(value => {
				assert.equal(value.length, 1);
				assert.equal(value[0].contents.length, 1);
			});
		});
	});

	// --- selection ranges

	test('Selection Range, back and forth', async function () {

		disposables.push(extHost.registerSelectionRangeProvider(nullExtensionDescription, defaultSelector, <vscode.SelectionRangeProvider>{
			provideSelectionRanges() {
				return [
					new types.SelectionRange(new types.Range(0, 10, 0, 18), new types.SelectionRange(new types.Range(0, 2, 0, 20))),
				];
			}
		}));

		await rpcProtocol.sync();
		let value = await commands.executeCommand<vscode.SelectionRange[]>('vscode.executeSelectionRangeProvider', model.uri, [new types.Position(0, 10)]);
		assert.equal(value.length, 1);
		assert.ok(value[0].parent);
	});

});

redpajama_set_name: RedPajamaGithub


text:
Q: How does cx_freeze compile a Python script? Does cx_freeze contain its own compiler that goes from Python -> binary? Or does it translate it (e.g. to C), and compile the translated code?
Edit: It appears to be compiled to byte-code. So does this mean a cx_freeze exe is just the byte-code -> binary part of the Python interpreter?

A: cx_Freeze doesn't really compile your code. It really just packages up your Python code along with the Python interpreter, so that when you launch your application, it sets up a Python interpreter and starts running your Python code. It has the necessary machinery to run from either Python source code or bytecode, but it mostly stores modules as bytecode, because that's quicker to load.
Options like Cython and Nuitka go a step further - they translate your code to C and compile it to machine code, but they still use the Python VM machinery. It's just compiled code calling Python functionality rather than the VM running Python bytecode.

redpajama_set_name: RedPajamaStackExchange


text:
Congress makes huge gains in Gujarat, Himachal, defies pollsters
Rahul lost; Modi won but this was not the kind of win the prime minister was expecting for his party. Photograph:( Others )
WION Web Team New Delhi, Delhi, India Dec 18, 2017, 04.32 AM (IST)
The predictions made by exit polls for Gujarat seem to be a little off the mark with BJP and Congress locked in a close battle. Most of the pollsters had given BJP anywhere between 100-120 seats, and that might happen if the party is able to convert early leads into results, but Congress is emerging as the real winner.
If the early leads convert into results, the Congress is doing much better than expected. All pollsters had predicted a comfortable win for the BJP and the trends are proving pollsters wrong. Gujarat has been the BJP's laboratory and the party has held the state from 1995. Today's results not withstanding, the party will have to go back to the drawing board to see what has resulted in this massive dent in their support base in the state.
A party needs 92 seats in the 182-seat Gujarat assembly to form the government. When the campaign was launched in November, BJP president Amit Shah had claimed then party would win 150 seats. But that seems to be a very difficult target the achieve now.
In the 2012 assembly elections in Gujarat, the Congress had 61 seats and was a distant second to the BJP which had won 115. In the 2014 Lok Sabha elections, the BJP had won all the 26 parliamentary seats in the state.
In Himachal Pradesh, trends indicate it's a close race between the Congress and the BJP with the BJP ahead in 33 of the 55 seats for which trends are available. The Congress is ahead in 19 and Chief Minister Virbhadra Singh, who was embattled with graft charges, is doing better that expected.
The state has 68 assembly seats and most pollsters predicted a comfortable victory for the BJP, giving the party 45-50 seats. That Congress wipeout doesn't seem to be happening.
Every pollster had predicted a BJP win in Himachal Pradesh. The India Today-Axis poll gave BJP 47-55 seats out of a total of 68. The ruling Congress, they said, was expected to slump to anywhere between 13-20 seats.
Today's Chanakya, another prominent pollster, had predicted 55 seats for the BJP in Himachal Pradesh and 13 for Congress.
Pakistan opens its air space five months after closing it in aftermath of Balakot airstrikes

redpajama_set_name: RedPajamaCommonCrawl


JL-JX Edition Aero Rock Guards made from carbon fiber with 2x2 glossy weave and custom vented design. The JL-JX Edition Aero Rock Guards for Jeep focus on lightweight strength & performance while retaining the off road capabilities of the Jeep. The rock guards are a direct bolt on replacement part engineered, designed and manufactured directly by Venomrex in Garden Grove, CA in the United States. Our carbon parts are fully guaranteed and tested to ensure proper fitment and the highest quality construction.


I saw Julie Reulbach use Zombies to explore exponential growth and lead into logarithms. I really liked Julie's use of the situation to prompt the need for logarithms.
My introduction was similar to Julie's introduction: Zombies are attacking the class. But I decided to act it out a little bit to come to terms with the "reality" (hah) of a zombie attack. Namely, exponential growth might overestimate the infection rate since when there are already a lot of zombies, its hard to find normal healthy humans to devour their brains.
Finally, I wrapped up the discussion by pulling up some population graphs for human civilization. Noted that we don't know where the supply caps are, or which caps might be solved in the future (such as how the development of agriculture allowed new growth, or more recently, how antibiotics allowed new growth). I felt this was a nice attempt to connect my math classroom to other subjects such as history (ka-ching, that rare humanities connection) and biology.


text:
Prague, Czech Republic / Klein-Winternheim, Germany, Oct 23, 2014
SYSGO and UniControls build safe and secure Railway Platform
At the Berlin rail fair InnoTrans, SYSGO and UniControls agreed on the development of a joint COTS (Commercial-of-the-Shelf) platform for the railway industry targeting the highest safety level. With CS-C01, UniControls contributes a Freescale QorlQ P3041 Quadcore communication processor based hardware, which is supported by SYSGO's hypervisor PikeOS. PikeOS already runs on Freescale's P3041DS Hydra and is certified to the highest level SIL 4 of the railway safety standard EN 50128. UniControls…
Quimper, France / Klein-Winternheim, Germany, Oct 16, 2014
SYSGO and Interface Concept join Efforts to port PikeOS on OpenVPX Core i7 Platforms
SYSGO with PikeOS and Interface Concept with its Core i7 Intel VPX 3U and 6U platforms collaborate to offer processing solutions for the embedded defense and aerospace market. These solutions benefit from the most recent technologies available in the design of OpenVPX COTS Single Board Computers while offering high performance real-time processing capabilities.
Malmö, Sweden / Klein-Winternheim, Germany, Oct 09, 2014
SYSGO picks Nohau as Distributor for Nordic Countries
"Local presence is important for a successful and reliable long-term cooperation with our customers, especially when their applications are focused on solutions for safe and secure applications," explains Norbert Kuhrt, VP of Sales at SYSGO. "We are happy to get Nohau on board as a distributor and certified partner for our activities in Norway, Sweden and Denmark." Kuhrt is sure that Nohau's experience in the local embedded market combined with SYSGO's product portfolio will provide optimized…
Klein-Winternheim, Germany, Oct 01, 2014
SYSGO welcomes Certification expert Sven Nordhoff on Board
Devices and machinery for the Internet of Things are highly complex systems that must be tested according to industry-specific standards and protected against enemy attacks. The product development in this area usually takes several years, in which an optimal cooperation between manufacturers and suppliers is critical to the success of the project. With the newly created position of Director Certification, SYSGO bundles the human, technical and organizational responsibilities of these projects…
Berlin / Klein-Winternheim, Germany, Sep 23, 2014
SYSGO and Kontron show safe Railway Platform at InnoTrans
At the Berlin railway technology fair InnoTrans, SYSGO and Kontron present a joint platform for safe rail systems. SYSGO's hypervisor PikeOS is certified to the highest level SIL 4 of railway safety standard EN 50128 and runs on the Kontron VX3035 3U Single Board Computer with Intel Multi-Core i7 processor. At the booth of Kontron (booth no. 320 in hall 2.1), visitors can learn about the safety-tested platform.
Klein-Winternheim, Germany, Jul 31, 2014
ELinOS 6.0 ensures effective embedded Linux Projects
Only two weeks after the release of its hypervisor PikeOS 3.5, SYSGO presents today the new version 6.0 of the embedded Linux distribution ELinOS. Core element of the update is the redesigned in-house development environment CODEO 5.1, which now combines all the tools for the development of industrial Linux projects under one user interface. For use in embedded systems, ELinOS features an optimized Linux kernel 3.12. The latest CPUs for embedded systems have been added to the list of supported…
PikeOS 3.5 includes Hardware Virtualization
SYSGO announces today the release of version 3.5 of its hypervisor PikeOS. Focus of the innovation is the support of hardware virtualization enabling the execution of guest operating systems without any adaption. Additionally, PikeOS 3.5 is equipped with an enhanced PikeOS Native personality and improved Linux support by using ELinOS 6.0 and Android 4.3.1. The integrated development environment CODEO has also been updated and speeds up the configuration process of ELinOS and Android…
Paris, France / Klein-Winternheim, Germany, Jul 11, 2014
New VP Sales at SYSGO
SYSGO appoints Norbert Kuhrt as Vice President Sales to further accelerate the company's growth in safety-critical systems. With many years of experience in the embedded software market, Nobert Kuhrt will lead the global sales teams and sales activities.
Providence, RI, USA / Klein-Winternheim, Germany, Jun 18, 2014
Vector Software strengthens Partnership with SYSGO GmbH
Vector Software, the world's leading provider of innovative software solutions for testing safety and mission critical embedded applications, announced today that the company has partnered with SYSGO GmbH to offer the VectorCAST™ software test tool in an integration with the latest version of microkernel based real-time operating system (RTOS) PikeOS 3.4. Certified to the highest safety and security standards, this RTOS is used in safety-critical applications such as aircraft, rail, medical…
Klein-Winterheim, Germany, Jun 10, 2014
PikeOS comes with full Virtualization for Renesas R-Car H2
SYSGO expands its virtualization platform PikeOS with support for the high-end infotainment system Renesas R-CAR H2 for the automotive market. PikeOS provides full hardware virtualization for the high performance system-on-chip platform and achieves almost identical benchmarks for virtualized as for native systems.
Warsaw, Poland / Klein-Winternheim, Germany, Jun 04, 2014
Certification of Safety and Security-Critical Applications on Multi-Core presented at DASIA
SYSGO's Stuart Fisher talks at DASIA in Warsaw to system and software designers about the key role of the operating system to meet the standards necessary to promote multi-core CPU's in products requiring safety and/or security certification.
Klein-Winternheim, Germany, May 27, 2014
SYSGO receives US Patent
SYSGO's "Method for distributing computing time in a computer system" is now patented in the US. This method is the basis of SYSGO's Safe & Secure Virtualization RTOS PikeOS that was built from scratch to meet safety and security requirements at the highest level.
PikeOS running Renesas R-Car Board
SYSGO is bringing hardware virtualization to the automotive market. By using the virtualization technology of SYSGO's RTOS PikeOS the company succeeded in demonstrating a high end cluster running on the latest automotive hardware: the R-Car H2 from Renesas based on ARM®Cortex™-A15 Quad. Thanks to PikeOS the cluster application is running in parallel to an open application in a safe and secure way.
EN | DE | FR
Höhenkirchen-Siegertsbrunn / Klein-Winternheim, Germany, Apr 10, 2014
Lauterbach's TRACE32® now supports SYSGO's PikeOS and ELinOS in a seamless Environment
PikeOS developers were already able to use TRACE32 from Lauterbach, a debugging capability that applies to a full range of items, from bootstrap code to interrupt routines and drivers. The PikeOS awareness provides easy access to PikeOS resources such as partitions, processes and threads. Because PikeOS is also a virtualization platform, it is important to be able to debug any application, whatever partition or type of partition (called Guest OS) this application belongs to.
Klein-Winternheim, Germany, Apr 03, 2014
SYSGO and OSADL join Forces to run extensive Testing on the next Version of ELinOS
SYSGO is actively working on the new 6.0 release of ELinOS. In addition to its own in-house test suites always used for new versions, SYSGO is using an extensive test suite provided by OSADL which focuses on stability and capabilities of the real-time Linux kernel.