All files / views/trees/definition-tree/nodes/concepts concepts-node.ts

100% Statements 21/21
100% Branches 12/12
100% Functions 7/7
100% Lines 21/21

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 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60            1x       1x       1x       1x 1x   1x       12x 12x   12x       1x       6x 6x   6x 3x         3x 3x 6x   6x       6x 1x     2x    
import * as vscode from "vscode";
import { DefinitionTreeNode } from "../../definition-tree-node";
import { ConceptClassNode } from "./concept-class-node";
 
export class ConceptsNode extends ConceptClassNode {
	override getContextValue(): string {
		return 'concepts';
	}
 
	override getIcon(): vscode.ThemeIcon | undefined {
		return undefined;
	}
 
	override getLabel(): vscode.TreeItemLabel {
		return { label: 'Concepts' };
	}
 
	override getDescription(): string {
		const graphs = this.getDocumentGraphs();
		const concepts = [...this.vocabulary.getConcepts(graphs)];
 
		return concepts.length.toString();
	}
 
	override *getSubClassIris(): IterableIterator<string> {
		const graphs = this.getDocumentGraphs();
		const subject = this.getQueryOptions().definedBy ?? this.uri;
 
		yield* this.vocabulary.getNarrowerConcepts(graphs, subject);
	}
 
	override getTooltip(): vscode.MarkdownString | undefined {
		return undefined;
	}
 
	override resolveNodeForUri(iri: string): DefinitionTreeNode | undefined {
		const graphs = this.getDocumentGraphs();
		const path = this.vocabulary.getConceptSchemePath(graphs, iri);
 
		if (!path || path.length === 0) {
			return undefined;
		}
 
		// The path goes from concept to scheme root — reverse it and drop the
		// scheme itself (which is the ConceptSchemeNode parent, not a child here).
		const rootToTarget = path.reverse();
		const schemeUri = this.getQueryOptions().definedBy ?? this.uri;
		const schemeIndex = rootToTarget.indexOf(schemeUri);
 
		const walkPath = schemeIndex >= 0
			? rootToTarget.slice(schemeIndex + 1)
			: rootToTarget;
 
		if (walkPath.length === 0) {
			return undefined;
		}
 
		return this.walkHierarchyPath(walkPath);
	}
}