All files / commands create-document.ts

100% Statements 11/11
100% Branches 4/4
100% Functions 1/1
100% Lines 11/11

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37          1x     5x 5x   5x         5x 10x             5x       5x 2x     3x 2x      
import * as vscode from 'vscode';
import { container } from 'tsyringe';
import { ServiceToken } from '@src/services/tokens';
import { IDocumentFactory } from '@src/services/document/document-factory.interface';
 
export const createDocument = {
	id: 'mentor.command.createDocument',
	handler: async () => {
		const items: any[] = [];
		const documentFactory = container.resolve<IDocumentFactory>(ServiceToken.DocumentFactory);
 
		items.push({
			label: '$(mentor-notebook) Mentor Notebook',
			command: 'mentor.command.createNotebook'
		});
 
		for (const lang of await documentFactory.getSupportedLanguagesInfo()) {
			items.push({
				label: `$(${lang.icon})  ${lang.typeName}`,
				command: 'mentor.command.createDocumentFromLanguage',
				args: lang.id
			});
		}
 
		const selected = await vscode.window.showQuickPick(items, {
			placeHolder: 'Select document type',
		});
 
		if (!selected) {
			return;
		}
 
		if (selected.command) {
			await vscode.commands.executeCommand(selected.command, selected.args);
		}
	}
};