Skip to content
This repository has been archived by the owner on Apr 23, 2022. It is now read-only.

Commit

Permalink
fix: pnp context value support both array and string (#920)
Browse files Browse the repository at this point in the history
  • Loading branch information
eriolchan authored Feb 18, 2020
1 parent eeefd39 commit b307b3e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,5 @@ export class DigitalTwinConstants {
static readonly REQUIRED_PROPERTY_LABEL = "(required)";
static readonly IOT_MODEL_LABEL = "IoTModel";
static readonly CONTEXT_TEMPLATE = "http://azureiot.com/v1/contexts/IoTModel.json";
static readonly CONTEXT_REGEX = new RegExp("^http://azureiot.com/v[0-9]+/contexts/IoTModel.json$");
static readonly SUPPORT_SEMANTIC_TYPES = new Set<string>(["Telemetry", "Property"]);
}
10 changes: 8 additions & 2 deletions src/DigitalTwin/pnp/src/intelliSense/intelliSenseUtility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,15 @@ export class IntelliSenseUtility {
* @param node json node
*/
static isDigitalTwinContext(node: parser.Node): boolean {
// assume @context is string node
// @context accept both array and string
if (node.type === JsonNodeType.String) {
return DigitalTwinConstants.CONTEXT_REGEX.test(node.value as string);
return (node.value as string) === DigitalTwinConstants.CONTEXT_TEMPLATE;
} else if (node.type === JsonNodeType.Array && node.children) {
for (const child of node.children) {
if (child.type === JsonNodeType.String && (child.value as string) === DigitalTwinConstants.CONTEXT_TEMPLATE) {
return true;
}
}
}
return false;
}
Expand Down

0 comments on commit b307b3e

Please sign in to comment.