All files / commands delete-prefixes.ts

100% Statements 8/8
100% Branches 4/4
100% Functions 2/2
100% Lines 7/7

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          1x     3x   3x 2x 2x 2x 1x        
import * as vscode from 'vscode';
import { container } from 'tsyringe';
import { ServiceToken } from '@src/services/tokens';
import { TurtlePrefixDefinitionService } from '../languages/turtle/services/turtle-prefix-definition-service';
 
export const deletePrefixes = {
	id: 'mentor.command.deletePrefixes',
	handler: async (documentUri: vscode.Uri, prefixes: string[]) => {
		const document = vscode.workspace.textDocuments.find(doc => doc.uri.toString() === documentUri.toString());
		
		if (document) {
			const service = container.resolve<TurtlePrefixDefinitionService>(ServiceToken.TurtlePrefixDefinitionService);
			const edit = await service.deletePrefixes(document, prefixes);
			if (edit.size > 0) {
				await vscode.workspace.applyEdit(edit);
			}
		}
	}
};