All files / commands/definition-tree describe-resource-from-position.ts

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

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                      1x         3x 1x     2x 2x   2x   3x 1x 1x     1x      
import * as vscode from 'vscode';
import { container } from 'tsyringe';
import { ServiceToken } from '@src/services/tokens';
import { IDocumentContextService } from '@src/services/document';
import { executeDescribeQuery } from '../sparql/execute-describe-query';
 
/**
 * Runs a DESCRIBE query for the resource (IRI or prefixed name) at the editor caret.
 * Invoked from the editor context menu; a right-click moves the caret to the clicked
 * token first, so the caret position identifies the clicked resource.
 */
export const describeResourceFromPosition = {
	id: 'mentor.command.describeResourceFromPosition',
	handler: async () => {
		const editor = vscode.window.activeTextEditor;
 
		if (!editor) {
			return;
		}
 
		const contextService = container.resolve<IDocumentContextService>(ServiceToken.DocumentContextService);
		const context = contextService.contexts[editor.document.uri.toString()];
 
		const iri = context?.getIriAtPosition(editor.selection.active);
 
		if (!iri) {
			vscode.window.showInformationMessage('No resource at the cursor position.');
			return;
		}
 
		await executeDescribeQuery.handler(editor.document.uri, iri);
	}
};