All files / commands/notebook set-notebook-inference.ts

100% Statements 13/13
75% Branches 6/8
100% Functions 1/1
100% Lines 13/13

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 38 39 40 41 42 43 44 45            1x     3x 3x   3x 1x 1x       2x           2x       2x 1x           1x   1x       3x      
import * as vscode from 'vscode';
import { container } from 'tsyringe';
import { ServiceToken } from '@src/services/tokens';
import { IDocumentConnectionService } from '@src/languages/sparql/services';
import { resolveNotebookFromContext } from '../../utilities/vscode/notebook';
 
export const setNotebookInference = {
	id: 'mentor.command.setNotebookInference',
	handler: async (context?: any) => {
		const documentConnectionService = container.resolve<IDocumentConnectionService>(ServiceToken.DocumentConnectionService);
		const notebook = resolveNotebookFromContext(context);
 
		if (!notebook) {
			vscode.window.showWarningMessage('No notebook is currently open.');
			return;
		}
 
		// Show quick pick to select inference setting
		const items = [
			{ label: 'On', description: 'Include inferred triples in query results.', value: true },
			{ label: 'Off', description: 'Only return asserted triples.', value: false },
			{ label: 'Default', description: 'Use connection defaults for each cell.', value: undefined }
		];
 
		const selected = await vscode.window.showQuickPick(items, {
			placeHolder: 'Set inference for all cells in this notebook'
		});
 
		if (selected === undefined) {
			return; // User cancelled
		}
 
		// Update all cells in one bulk edit; the service fires the change event
		// once per cell so URI-scoped consumers (code lenses, FROM-graph linting)
		// re-evaluate each cell against the new setting.
		await documentConnectionService.setInferenceEnabledForNotebook(notebook, selected.value);
 
		const statusText = selected.value === undefined
			? 'Cleared inference settings'
			: selected.value ? 'Enabled inference' : 'Disabled inference';
 
		vscode.window.setStatusBarMessage(`${statusText} for all ${notebook.getCells().length} cells`, 3000);
	}
};