This is an automated email from the ASF dual-hosted git repository.

tiagobento pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-kie-tools.git


The following commit(s) were added to refs/heads/main by this push:
     new c60e8c40b7d kie-issues#2549: Decision Service cannot be recognized in 
columns of decision table (#2684)
c60e8c40b7d is described below

commit c60e8c40b7dc6c5171a23d73675fae1989cdb97b
Author: Daniel José dos Santos <[email protected]>
AuthorDate: Wed Oct 30 15:14:56 2024 -0300

    kie-issues#2549: Decision Service cannot be recognized in columns of 
decision table (#2684)
---
 .../src/parser/VariablesRepository.ts              |  32 +++-
 packages/feel-input-component/package.json         |   1 +
 .../variables-inside-decision-tables/included.dmn  | 106 ++++++++++++
 .../modelWithInclude.dmn                           | 188 +++++++++++++++++++++
 .../tests/semanticTokensProvider.test.ts           | 150 ++++++++++++++++
 pnpm-lock.yaml                                     |   3 +
 6 files changed, 479 insertions(+), 1 deletion(-)

diff --git a/packages/dmn-feel-antlr4-parser/src/parser/VariablesRepository.ts 
b/packages/dmn-feel-antlr4-parser/src/parser/VariablesRepository.ts
index 5f137916a3f..a923a0186f7 100644
--- a/packages/dmn-feel-antlr4-parser/src/parser/VariablesRepository.ts
+++ b/packages/dmn-feel-antlr4-parser/src/parser/VariablesRepository.ts
@@ -379,6 +379,35 @@ export class VariablesRepository {
     this.addVariable(id, "", FeelSyntacticSymbolNature.LocalVariable, parent);
   }
 
+  private addDecisionTableEntryNode(parent: VariableContext, entryId: string) {
+    const ruleInputElementNode = this.addVariable(entryId, "", 
FeelSyntacticSymbolNature.LocalVariable, parent);
+    parent.children.set(ruleInputElementNode.uuid, ruleInputElementNode);
+    this.addVariable(ruleInputElementNode.uuid, "", 
FeelSyntacticSymbolNature.LocalVariable, ruleInputElementNode);
+  }
+
+  private addDecisionTable(parent: VariableContext, decisionTable: 
DmnDecisionTable) {
+    const variableNode = this.addVariable(
+      decisionTable["@_id"] ?? "",
+      "",
+      FeelSyntacticSymbolNature.LocalVariable,
+      parent
+    );
+    parent.children.set(variableNode.uuid, variableNode);
+
+    if (decisionTable.rule) {
+      for (const ruleElement of decisionTable.rule) {
+        ruleElement.inputEntry?.forEach((ruleInputElement) =>
+          this.addDecisionTableEntryNode(parent, ruleInputElement["@_id"] ?? 
"")
+        );
+        ruleElement.outputEntry?.forEach((ruleOutputElement) =>
+          this.addDecisionTableEntryNode(parent, ruleOutputElement["@_id"] ?? 
"")
+        );
+      }
+    }
+
+    this.addVariable(variableNode.uuid, "", 
FeelSyntacticSymbolNature.LocalVariable, parent);
+  }
+
   private addInvocation(parent: VariableContext, element: DmnInvocation) {
     if (element.binding) {
       for (const bindingElement of element.binding) {
@@ -594,7 +623,8 @@ export class VariablesRepository {
         break;
 
       case "decisionTable":
-        // Do nothing because DecisionTable does not define variables
+        // It doesn't define variables but we need it to create its own 
context to use variables inside of Decision Table.
+        this.addDecisionTable(parent, expression);
         break;
 
       case "context":
diff --git a/packages/feel-input-component/package.json 
b/packages/feel-input-component/package.json
index be2dfee300d..da5dc24036d 100644
--- a/packages/feel-input-component/package.json
+++ b/packages/feel-input-component/package.json
@@ -30,6 +30,7 @@
     "@babel/preset-env": "^7.16.0",
     "@babel/preset-react": "^7.16.0",
     "@kie-tools-core/webpack-base": "workspace:*",
+    "@kie-tools/dmn-marshaller": "workspace:*",
     "@kie-tools/eslint": "workspace:*",
     "@kie-tools/jest-base": "workspace:*",
     "@kie-tools/root-env": "workspace:*",
diff --git 
a/packages/feel-input-component/tests-data/variables-inside-decision-tables/included.dmn
 
b/packages/feel-input-component/tests-data/variables-inside-decision-tables/included.dmn
new file mode 100644
index 00000000000..20e48f0279a
--- /dev/null
+++ 
b/packages/feel-input-component/tests-data/variables-inside-decision-tables/included.dmn
@@ -0,0 +1,106 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<definitions
+  xmlns="https://www.omg.org/spec/DMN/20230324/MODEL/";
+  xmlns:dmndi="https://www.omg.org/spec/DMN/20230324/DMNDI/";
+  xmlns:dc="http://www.omg.org/spec/DMN/20180521/DC/";
+  xmlns:di="http://www.omg.org/spec/DMN/20180521/DI/";
+  xmlns:kie="https://kie.org/dmn/extensions/1.0";
+  expressionLanguage="https://www.omg.org/spec/DMN/20230324/FEEL/";
+  namespace="https://kie.org/dmn/_B2A15CAD-A32F-461F-9BEA-4E4BC46B76D6";
+  id="_8D96437B-D31F-437F-8B32-CD54C071A151"
+  name="DMN_B739B18D-74D9-4C75-A8E9-6845E731D3EB"
+>
+  <decisionService name="MyDS" id="_B141585F-BF2D-4A06-AD30-E2B8EC2A6D55">
+    <variable name="MyDS" id="_2C33EB78-3C0F-45E2-9A68-DC9BF1E09DCB" 
typeRef="Any" />
+    <outputDecision href="#_E2884578-AEA4-4CE5-8B23-00060D4C2EC9" />
+    <encapsulatedDecision href="#_0A37D837-F93A-4A5A-A335-E51F55D0070D" />
+    <inputData href="#_8ABF251F-B9D6-478E-BF18-AA8E7724CEE9" />
+  </decisionService>
+  <decision name="RemoteDecision" id="_0A37D837-F93A-4A5A-A335-E51F55D0070D">
+    <variable name="RemoteDecision" id="_3FEA818D-47C3-474D-A2B2-46AB7BB46B90" 
typeRef="Any" />
+    <informationRequirement id="_B64D2B58-DF44-4D4B-ADB4-4888AF677C08">
+      <requiredInput href="#_8ABF251F-B9D6-478E-BF18-AA8E7724CEE9" />
+    </informationRequirement>
+    <literalExpression id="_CADCEE70-2AFB-406A-8943-722C1B1DB1E6" 
typeRef="Any" label="RemoteDecision">
+      <text>Input</text>
+    </literalExpression>
+  </decision>
+  <inputData name="RemoteInput" id="_8ABF251F-B9D6-478E-BF18-AA8E7724CEE9">
+    <variable name="RemoteInput" id="_E30CE2A8-D907-489A-86FF-5E9040C85DA0" 
typeRef="Any" />
+  </inputData>
+  <decision name="AnotherRemoteDecision" 
id="_E2884578-AEA4-4CE5-8B23-00060D4C2EC9">
+    <variable name="AnotherRemoteDecision" 
id="_BCF70EC9-BB49-47F1-B978-F95120D7D6A8" />
+    <informationRequirement id="_A20B4362-1424-46CA-9737-5B5F812DD836">
+      <requiredDecision href="#_0A37D837-F93A-4A5A-A335-E51F55D0070D" />
+    </informationRequirement>
+  </decision>
+  <dmndi:DMNDI>
+    <dmndi:DMNDiagram
+      id="_319C4D28-9892-4521-B714-A0B607DED18F"
+      name="Default DRD"
+      useAlternativeInputDataShape="false"
+    >
+      <di:extension>
+        <kie:ComponentsWidthsExtension>
+          <kie:ComponentWidths 
dmnElementRef="_CADCEE70-2AFB-406A-8943-722C1B1DB1E6">
+            <kie:width>190</kie:width>
+          </kie:ComponentWidths>
+        </kie:ComponentsWidthsExtension>
+      </di:extension>
+      <dmndi:DMNShape
+        id="_B8C611D4-7FC8-46B9-BC24-B0804CC45382"
+        dmnElementRef="_B141585F-BF2D-4A06-AD30-E2B8EC2A6D55"
+        isCollapsed="false"
+        isListedInputData="false"
+      >
+        <dc:Bounds x="220" y="-40" width="320" height="320" />
+        <dmndi:DMNDecisionServiceDividerLine 
id="_6C99D7D5-A864-4D84-95C2-8CCF6C8D521C">
+          <di:waypoint x="220" y="120" />
+          <di:waypoint x="540" y="120" />
+        </dmndi:DMNDecisionServiceDividerLine>
+      </dmndi:DMNShape>
+      <dmndi:DMNShape
+        id="_89705EA9-4E6F-4699-A7FF-C01B433FC20E"
+        dmnElementRef="_0A37D837-F93A-4A5A-A335-E51F55D0070D"
+        isCollapsed="false"
+        isListedInputData="false"
+      >
+        <dc:Bounds x="300" y="160" width="160" height="80" />
+      </dmndi:DMNShape>
+      <dmndi:DMNShape
+        id="_40457313-1A43-4486-A369-BEE1EE1B9845"
+        dmnElementRef="_8ABF251F-B9D6-478E-BF18-AA8E7724CEE9"
+        isCollapsed="false"
+        isListedInputData="false"
+      >
+        <dc:Bounds x="0" y="160" width="160" height="80" />
+      </dmndi:DMNShape>
+      <dmndi:DMNEdge
+        id="_C802FEE9-EFE0-4F17-8A57-4C5BBB0A7CF4"
+        dmnElementRef="_B64D2B58-DF44-4D4B-ADB4-4888AF677C08"
+        sourceElement="_40457313-1A43-4486-A369-BEE1EE1B9845"
+        targetElement="_89705EA9-4E6F-4699-A7FF-C01B433FC20E"
+      >
+        <di:waypoint x="80" y="200" />
+        <di:waypoint x="380" y="200" />
+      </dmndi:DMNEdge>
+      <dmndi:DMNShape
+        id="_19C09A3C-ACCD-47AD-A3C7-C7EB308B053F"
+        dmnElementRef="_E2884578-AEA4-4CE5-8B23-00060D4C2EC9"
+        isCollapsed="false"
+        isListedInputData="false"
+      >
+        <dc:Bounds x="300" y="20" width="160" height="80" />
+      </dmndi:DMNShape>
+      <dmndi:DMNEdge
+        id="_A237BF8B-4CF2-4DE0-8302-9D9D3E730FFC"
+        dmnElementRef="_A20B4362-1424-46CA-9737-5B5F812DD836"
+        sourceElement="_89705EA9-4E6F-4699-A7FF-C01B433FC20E"
+        targetElement="_19C09A3C-ACCD-47AD-A3C7-C7EB308B053F"
+      >
+        <di:waypoint x="380" y="200" />
+        <di:waypoint x="380" y="60" />
+      </dmndi:DMNEdge>
+    </dmndi:DMNDiagram>
+  </dmndi:DMNDI>
+</definitions>
diff --git 
a/packages/feel-input-component/tests-data/variables-inside-decision-tables/modelWithInclude.dmn
 
b/packages/feel-input-component/tests-data/variables-inside-decision-tables/modelWithInclude.dmn
new file mode 100644
index 00000000000..29d96398958
--- /dev/null
+++ 
b/packages/feel-input-component/tests-data/variables-inside-decision-tables/modelWithInclude.dmn
@@ -0,0 +1,188 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<definitions
+  xmlns="https://www.omg.org/spec/DMN/20230324/MODEL/";
+  xmlns:included0="https://kie.org/dmn/_B2A15CAD-A32F-461F-9BEA-4E4BC46B76D6";
+  xmlns:dmndi="https://www.omg.org/spec/DMN/20230324/DMNDI/";
+  xmlns:dc="http://www.omg.org/spec/DMN/20180521/DC/";
+  xmlns:di="http://www.omg.org/spec/DMN/20180521/DI/";
+  xmlns:kie="https://kie.org/dmn/extensions/1.0";
+  expressionLanguage="https://www.omg.org/spec/DMN/20230324/FEEL/";
+  namespace="https://kie.org/dmn/_628EE39C-379C-41F7-951E-F5E8269A7BC0";
+  id="_9BBEBC5E-BD18-4B9F-9D36-2F3E3F41E279"
+  name="DMN_8FFA6199-64DD-4D60-8A29-C53AFC313FA1"
+>
+  <import
+    id="_C1B98160-05F8-4384-9F4C-4BF0FEE9C4A3"
+    name="MyIncludedModel"
+    importType="http://www.omg.org/spec/DMN/20180521/MODEL/";
+    namespace="https://kie.org/dmn/_B2A15CAD-A32F-461F-9BEA-4E4BC46B76D6";
+    locationURI="./included.dmn"
+  />
+  <decision name="New Decision DT" id="_391621EF-40D7-4D35-8A53-0FF271042C70">
+    <variable name="New Decision DT" 
id="_8BF1CB89-D537-482F-BCBB-7BC4D7814E22" typeRef="Any" />
+    <informationRequirement id="_667BE578-F2E8-4523-B4C5-99AC38D40A80">
+      <requiredInput href="#_D847615D-55B2-45D9-A56F-6726F72D0744" />
+    </informationRequirement>
+    <informationRequirement id="_B347AB8A-C5C0-41D5-AAD6-1CD5068A871E">
+      <requiredInput
+        
href="https://kie.org/dmn/_B2A15CAD-A32F-461F-9BEA-4E4BC46B76D6#_8ABF251F-B9D6-478E-BF18-AA8E7724CEE9";
+      />
+    </informationRequirement>
+    <informationRequirement id="_AF5A04E6-0767-4A49-AF11-A26A5F665876">
+      <requiredDecision href="#_7C9E56B7-24A0-4B11-9A5D-2AEA8130BC72" />
+    </informationRequirement>
+    <knowledgeRequirement id="_9AEA1B2D-DE33-490D-9970-07E45332DEF3">
+      <requiredKnowledge
+        
href="https://kie.org/dmn/_B2A15CAD-A32F-461F-9BEA-4E4BC46B76D6#_B141585F-BF2D-4A06-AD30-E2B8EC2A6D55";
+      />
+    </knowledgeRequirement>
+    <decisionTable id="_EF887AF0-B810-4526-8450-01D9A2DF5744" typeRef="Any" 
hitPolicy="UNIQUE" label="New Decision DT">
+      <input id="_A9587AE6-ED62-4D49-9011-A98693141BEC">
+        <inputExpression id="_F7509AD6-2823-4164-A582-C330DE4050D2" 
typeRef="Any">
+          <text>Input</text>
+        </inputExpression>
+      </input>
+      <output id="_D4F60227-308A-407B-A888-C72D293D318F" name="Output-1" />
+      <annotation name="Annotations" />
+      <rule id="_746B9056-8DEE-4901-BF13-D5E675C97E74">
+        <inputEntry id="_4A8D53FF-B85F-421C-8ACA-9E3E8BCA08A1">
+          <text>-</text>
+        </inputEntry>
+        <outputEntry id="_206131ED-0B81-4013-980A-4BB2539A53D0">
+          <text>MyIncludedModel.MyDS(LocalInput) + 
MyIncludedModel.RemoteInput</text>
+        </outputEntry>
+        <annotationEntry>
+          <text />
+        </annotationEntry>
+      </rule>
+      <rule id="_7CB3952B-D4F1-4C22-BF2E-346E8AA57B77">
+        <inputEntry id="_FF468430-942F-46B0-B5D0-242CD58E5508">
+          <text>-</text>
+        </inputEntry>
+        <outputEntry id="_AEC3EEB0-8436-4767-A214-20FF5E5CB7BE">
+          <text>LocalInput + LocalDecision</text>
+        </outputEntry>
+        <annotationEntry>
+          <text />
+        </annotationEntry>
+      </rule>
+      <rule id="_340F549A-96DC-4E9C-A627-B2814FDE8189">
+        <inputEntry id="_B78FD898-21A1-4BD3-8D17-4DA284D1D00B">
+          <text>-</text>
+        </inputEntry>
+        <outputEntry id="_18832484-9481-49BC-BD40-927CB9872C6B">
+          <text>MyIncludedModel.MyDS(LocalInput) + MyIncludedModel.RemoteInput 
+ LocalInput + LocalDecision</text>
+        </outputEntry>
+        <annotationEntry>
+          <text />
+        </annotationEntry>
+      </rule>
+    </decisionTable>
+  </decision>
+  <inputData name="LocalInput" id="_D847615D-55B2-45D9-A56F-6726F72D0744">
+    <variable name="LocalInput" id="_4F60511D-D7E1-4B14-9DBF-73EC28CAA547" />
+  </inputData>
+  <decision name="LocalDecision" id="_7C9E56B7-24A0-4B11-9A5D-2AEA8130BC72">
+    <variable name="LocalDecision" id="_4B1434EB-C78C-43EE-84B8-4355B487DB85" 
/>
+  </decision>
+  <dmndi:DMNDI>
+    <dmndi:DMNDiagram
+      id="_57CDCAB2-EC93-427E-83AD-663AFA4B55B7"
+      name="Default DRD"
+      useAlternativeInputDataShape="false"
+    >
+      <di:extension>
+        <kie:ComponentsWidthsExtension>
+          <kie:ComponentWidths 
dmnElementRef="_EF887AF0-B810-4526-8450-01D9A2DF5744">
+            <kie:width>60</kie:width>
+            <kie:width>118</kie:width>
+            <kie:width>773</kie:width>
+            <kie:width>240</kie:width>
+          </kie:ComponentWidths>
+        </kie:ComponentsWidthsExtension>
+      </di:extension>
+      <dmndi:DMNShape
+        id="_D9924C3E-521F-4318-9140-B42E66F8C6B4"
+        dmnElementRef="_391621EF-40D7-4D35-8A53-0FF271042C70"
+        isCollapsed="false"
+        isListedInputData="false"
+      >
+        <dc:Bounds x="880" y="140" width="160" height="80" />
+      </dmndi:DMNShape>
+      <dmndi:DMNShape
+        id="_6CCFE0B6-5C49-485A-AD7E-D0B73D2BB633"
+        dmnElementRef="included0:_B141585F-BF2D-4A06-AD30-E2B8EC2A6D55"
+      >
+        <dc:Bounds x="420" y="20" width="320" height="320" />
+        <dmndi:DMNDecisionServiceDividerLine 
id="_412A759B-7DA9-4B0E-88C5-1FA9282572EA">
+          <di:waypoint x="420" y="180" />
+          <di:waypoint x="740" y="180" />
+        </dmndi:DMNDecisionServiceDividerLine>
+      </dmndi:DMNShape>
+      <dmndi:DMNShape
+        id="_D3C60B6D-3B89-430B-BB33-5167A3D9414D"
+        dmnElementRef="included0:_0A37D837-F93A-4A5A-A335-E51F55D0070D"
+      >
+        <dc:Bounds x="500" y="80" width="160" height="80" />
+      </dmndi:DMNShape>
+      <dmndi:DMNEdge
+        id="_B03F794E-C049-4F9C-938F-82708F632510"
+        dmnElementRef="_9AEA1B2D-DE33-490D-9970-07E45332DEF3"
+        sourceElement="_6CCFE0B6-5C49-485A-AD7E-D0B73D2BB633"
+        targetElement="_D9924C3E-521F-4318-9140-B42E66F8C6B4"
+      >
+        <di:waypoint x="580" y="180" />
+        <di:waypoint x="960" y="180" />
+      </dmndi:DMNEdge>
+      <dmndi:DMNShape
+        id="_B470D1CD-BA2F-4393-AF5B-2FC4F4DE462A"
+        dmnElementRef="_D847615D-55B2-45D9-A56F-6726F72D0744"
+        isCollapsed="false"
+        isListedInputData="false"
+      >
+        <dc:Bounds x="880" y="300" width="160" height="80" />
+      </dmndi:DMNShape>
+      <dmndi:DMNEdge
+        id="_DE667C39-AB67-4699-B8FE-0131522C6EED"
+        dmnElementRef="_667BE578-F2E8-4523-B4C5-99AC38D40A80"
+        sourceElement="_B470D1CD-BA2F-4393-AF5B-2FC4F4DE462A"
+        targetElement="_D9924C3E-521F-4318-9140-B42E66F8C6B4"
+      >
+        <di:waypoint x="960" y="340" />
+        <di:waypoint x="960" y="180" />
+      </dmndi:DMNEdge>
+      <dmndi:DMNShape
+        id="_894F72DA-9BFC-43B9-AF28-E6219A333FB9"
+        dmnElementRef="included0:_8ABF251F-B9D6-478E-BF18-AA8E7724CEE9"
+      >
+        <dc:Bounds x="820" y="-60" width="160" height="80" />
+      </dmndi:DMNShape>
+      <dmndi:DMNEdge
+        id="_CA4F2371-D04B-4059-A03A-02E20BF13F89"
+        dmnElementRef="_B347AB8A-C5C0-41D5-AAD6-1CD5068A871E"
+        sourceElement="_894F72DA-9BFC-43B9-AF28-E6219A333FB9"
+        targetElement="_D9924C3E-521F-4318-9140-B42E66F8C6B4"
+      >
+        <di:waypoint x="900" y="-20" />
+        <di:waypoint x="960" y="140" />
+      </dmndi:DMNEdge>
+      <dmndi:DMNShape
+        id="_C7023139-BF72-4CE9-8B42-BA52629B8ABA"
+        dmnElementRef="_7C9E56B7-24A0-4B11-9A5D-2AEA8130BC72"
+        isCollapsed="false"
+        isListedInputData="false"
+      >
+        <dc:Bounds x="1120" y="140" width="160" height="80" />
+      </dmndi:DMNShape>
+      <dmndi:DMNEdge
+        id="_35B32768-E16F-4CC7-815E-0F06CC361986"
+        dmnElementRef="_AF5A04E6-0767-4A49-AF11-A26A5F665876"
+        sourceElement="_C7023139-BF72-4CE9-8B42-BA52629B8ABA"
+        targetElement="_D9924C3E-521F-4318-9140-B42E66F8C6B4"
+      >
+        <di:waypoint x="1200" y="180" />
+        <di:waypoint x="1040" y="180" />
+      </dmndi:DMNEdge>
+    </dmndi:DMNDiagram>
+  </dmndi:DMNDI>
+</definitions>
diff --git a/packages/feel-input-component/tests/semanticTokensProvider.test.ts 
b/packages/feel-input-component/tests/semanticTokensProvider.test.ts
index 644547c8dac..44d2261587c 100644
--- a/packages/feel-input-component/tests/semanticTokensProvider.test.ts
+++ b/packages/feel-input-component/tests/semanticTokensProvider.test.ts
@@ -22,6 +22,9 @@ import { BuiltInTypes, DmnDefinitions, FeelVariables } from 
"@kie-tools/dmn-feel
 
 import * as Monaco from "@kie-tools-core/monaco-editor";
 import { Element } from "@kie-tools/feel-input-component/dist/themes/Element";
+import * as fs from "fs";
+import * as path from "path";
+import { getMarshaller } from "@kie-tools/dmn-marshaller";
 
 describe("Semantic Tokens Provider", () => {
   const cancellationTokenMock = {
@@ -286,6 +289,145 @@ ThatShouldFailWhenBreakLine`,
       }
     });
   });
+
+  describe("variables inside Decision Tables", () => {
+    const dmnModelWithIncludesPosixPathRelativeToTheTestFile =
+      "../tests-data/variables-inside-decision-tables/modelWithInclude.dmn";
+    const includedDmnModelPosixPathRelativeToTheTestFile =
+      "../tests-data/variables-inside-decision-tables/included.dmn";
+    const localModel = 
getDmnModelFromFilePath(dmnModelWithIncludesPosixPathRelativeToTheTestFile);
+    const includedModel = 
getDmnModelFromFilePath(includedDmnModelPosixPathRelativeToTheTestFile);
+
+    test("should recognize local nodes", async () => {
+      const expression = "LocalInput + LocalDecision";
+      const id = "_AEC3EEB0-8436-4767-A214-20FF5E5CB7BE";
+      const modelMock = createModelMockForExpression(expression);
+
+      const feelVariables = new FeelVariables(
+        localModel.definitions,
+        new Map([[includedModel.definitions["@_namespace"] ?? "", 
includedModel]])
+      );
+
+      const semanticTokensProvider = new SemanticTokensProvider(feelVariables, 
id, () => {});
+
+      const semanticMonacoTokens = await 
semanticTokensProvider.provideDocumentSemanticTokens(
+        modelMock as unknown as Monaco.editor.ITextModel,
+        null,
+        cancellationTokenMock
+      );
+
+      const expected = [
+        ...getMonacoSemanticToken({
+          startLineRelativeToPreviousLine: 0,
+          startIndexRelativeToPreviousStartIndex: 0,
+          tokenLength: "LocalInput".length,
+        }),
+        ...getMonacoSemanticToken({
+          startLineRelativeToPreviousLine: 0,
+          startIndexRelativeToPreviousStartIndex: "LocalInput".length + 3, // 
+3 because of the " + "
+          tokenLength: "LocalDecision".length,
+        }),
+      ];
+
+      for (let i = 0; i < expected.length; i++) {
+        expect(semanticMonacoTokens?.data[i]).toEqual(expected[i]);
+      }
+    });
+
+    test("should recognize included nodes", async () => {
+      const expression = "MyIncludedModel.MyDS(LocalInput) + 
MyIncludedModel.RemoteInput";
+      const id = "_206131ED-0B81-4013-980A-4BB2539A53D0";
+      const modelMock = createModelMockForExpression(expression);
+
+      const feelVariables = new FeelVariables(
+        localModel.definitions,
+        new Map([[includedModel.definitions["@_namespace"] ?? "", 
includedModel]])
+      );
+
+      const semanticTokensProvider = new SemanticTokensProvider(feelVariables, 
id, () => {});
+
+      const semanticMonacoTokens = await 
semanticTokensProvider.provideDocumentSemanticTokens(
+        modelMock as unknown as Monaco.editor.ITextModel,
+        null,
+        cancellationTokenMock
+      );
+
+      const expected = [
+        ...getMonacoSemanticToken({
+          startLineRelativeToPreviousLine: 0,
+          startIndexRelativeToPreviousStartIndex: 0,
+          tokenLength: "MyIncludedModel.MyDS".length,
+          tokenType: Element.FunctionCall,
+        }),
+        ...getMonacoSemanticToken({
+          startLineRelativeToPreviousLine: 0,
+          startIndexRelativeToPreviousStartIndex: 
"MyIncludedModel.MyDS".length + 1, // +1 because of the "("
+          tokenLength: "LocalInput".length,
+        }),
+        ...getMonacoSemanticToken({
+          startLineRelativeToPreviousLine: 0,
+          startIndexRelativeToPreviousStartIndex: "LocalInput".length + ") + 
".length,
+          tokenLength: "MyIncludedModel.RemoteInput".length,
+        }),
+      ];
+
+      for (let i = 0; i < expected.length; i++) {
+        expect(semanticMonacoTokens?.data[i]).toEqual(expected[i]);
+      }
+    });
+
+    test("should recognize included nodes mixed with included nodes", async () 
=> {
+      const expression = "MyIncludedModel.MyDS(LocalInput) + 
MyIncludedModel.RemoteInput + LocalInput + LocalDecision";
+      const id = "_18832484-9481-49BC-BD40-927CB9872C6B";
+      const modelMock = createModelMockForExpression(expression);
+
+      const feelVariables = new FeelVariables(
+        localModel.definitions,
+        new Map([[includedModel.definitions["@_namespace"] ?? "", 
includedModel]])
+      );
+
+      const semanticTokensProvider = new SemanticTokensProvider(feelVariables, 
id, () => {});
+
+      const semanticMonacoTokens = await 
semanticTokensProvider.provideDocumentSemanticTokens(
+        modelMock as unknown as Monaco.editor.ITextModel,
+        null,
+        cancellationTokenMock
+      );
+
+      const expected = [
+        ...getMonacoSemanticToken({
+          startLineRelativeToPreviousLine: 0,
+          startIndexRelativeToPreviousStartIndex: 0,
+          tokenLength: "MyIncludedModel.MyDS".length,
+          tokenType: Element.FunctionCall,
+        }),
+        ...getMonacoSemanticToken({
+          startLineRelativeToPreviousLine: 0,
+          startIndexRelativeToPreviousStartIndex: 
"MyIncludedModel.MyDS".length + 1, // +1 because of the "("
+          tokenLength: "LocalInput".length,
+        }),
+        ...getMonacoSemanticToken({
+          startLineRelativeToPreviousLine: 0,
+          startIndexRelativeToPreviousStartIndex: "LocalInput".length + ") + 
".length,
+          tokenLength: "MyIncludedModel.RemoteInput".length,
+        }),
+        ...getMonacoSemanticToken({
+          startLineRelativeToPreviousLine: 0,
+          startIndexRelativeToPreviousStartIndex: 
"MyIncludedModel.RemoteInput".length + " + ".length,
+          tokenLength: "LocalInput".length,
+        }),
+        ...getMonacoSemanticToken({
+          startLineRelativeToPreviousLine: 0,
+          startIndexRelativeToPreviousStartIndex: "LocalInput".length + " + 
".length,
+          tokenLength: "LocalDecision".length,
+        }),
+      ];
+
+      for (let i = 0; i < expected.length; i++) {
+        expect(semanticMonacoTokens?.data[i]).toEqual(expected[i]);
+      }
+    });
+  });
 });
 
 function getDmnModelWithContextEntry({
@@ -377,3 +519,11 @@ function createModelMockForExpression(expression: string) {
     getLinesContent: jest.fn().mockReturnValue(expression.split("\n")),
   };
 }
+
+function getDmnModelFromFilePath(modelFilePosixPathRelativeToTheTestFile: 
string) {
+  const { parser } = getMarshaller(
+    fs.readFileSync(path.join(__dirname, 
modelFilePosixPathRelativeToTheTestFile), "utf-8"),
+    { upgradeTo: "latest" }
+  );
+  return parser.parse();
+}
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 89ac815c00d..d553e306137 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -4532,6 +4532,9 @@ importers:
       '@kie-tools-core/webpack-base':
         specifier: workspace:*
         version: link:../webpack-base
+      '@kie-tools/dmn-marshaller':
+        specifier: workspace:*
+        version: link:../dmn-marshaller
       '@kie-tools/eslint':
         specifier: workspace:*
         version: link:../eslint


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to