import * as parser from "jsonc-parser" ; import * as vscode from "vscode" ; import { Constants } from "../common/constants" ; import { DigitalTwinConstants } from "./digitalTwinConstants" ; import { PropertyNode } from "./digitalTwinGraph" ; import { IntelliSenseUtility , PropertyPair , ModelContent } from "./intelliSenseUtility" ; /**
 * Hover provider for DigitalTwin IntelliSense
 */ export class DigitalTwinHoverProvider implements vscode . HoverProvider { param propertyName private static getContent ( propertyName ) { if ( ! propertyName ) { return Constants . EMPTY_STRING ; } switch ( propertyName ) { case DigitalTwinConstants . ID : return `An identifier for ${ Constants . CHANNEL_NAME } Capability Model or interface` ; case DigitalTwinConstants . TYPE : return `The type of ${ Constants . CHANNEL_NAME } meta model object` ; case DigitalTwinConstants . CONTEXT : return `The context for ${ Constants . CHANNEL_NAME } Capability Model or interface` ; default : { const propertyNode = IntelliSenseUtility . getPropertyNode ( propertyName ) ; return propertyNode && propertyNode . comment ? propertyNode . comment : Constants . EMPTY_STRING ; } } } param document param position provideHover ( document , position ) { if ( ! IntelliSenseUtility . enabled ( ) ) { return undefined ; } const modelContent = IntelliSenseUtility . parseDigitalTwinModel ( document . getText ( ) ) ; if ( ! modelContent ) { return undefined ; } const node = parser . findNodeAtOffset ( modelContent . jsonNode , document . offsetAt ( position ) ) ; if ( ! node || ! node . parent ) { return undefined ; } const propertyPair = IntelliSenseUtility . parseProperty ( node . parent ) ; if ( ! propertyPair ) { return undefined ; } const propertyName = IntelliSenseUtility . resolvePropertyName ( propertyPair ) ; const content = DigitalTwinHoverProvider . getContent ( propertyName ) ; return content ? new vscode . Hover ( content , IntelliSenseUtility . getNodeRange ( document , node . parent ) ) : undefined ; } }