Repository: FHIR/sushi (ts)

Issue:
SUSHI 2.0.0 Beta 2: "The first index in a Soft Indexing sequence must be "+", an actual index of "0" has been assumed" although the first index is '+'
While using SUSHI 2.0.0 Beta 2 I receive the error "The first index in a Soft Indexing sequence must be "+", an actual index of "0" has been assumed" although the first index is designated as '+'. This happens if using soft indexing **on extensions** like this:

```
* extension[+].url = "testurl"
* extension[=].valueString = "{variable}"
```

SUSHI 2.0.0 Beta 1 and SUSHI stable run through just fine though! 

Pull request:
Fix bug with indentation + soft indexing
Fixes #879, see that issue for further details.

This fixes a bug that happened when a soft indexed path was indented below another path, and the soft indexed path was _not_ a `PathRule`. See https://fshschool.org/FSHOnline/#/share/3sDl7Lm for a minimal example.

This PR fixes that by removing what appears to be a completely un-needed bit of code that was causing this bug. I believe that code was a relic from when I combined the handling of path context for normal rules and `CodeCaretRules`. But please as reviewers take a second to see if you could come up with a test case that would make the reviewed code necessary, because I would like that to get double checked.

Patch:
diff --git a/src/import/FSHImporter.ts b/src/import/FSHImporter.ts
index d612897..5064325 100644
--- a/src/import/FSHImporter.ts
+++ b/src/import/FSHImporter.ts
@@ -2056,14 +2056,9 @@ export class FSHImporter extends FSHVisitor {
       return path;
     }
 
-    // Replace '[+]' with '[=]' in the version of the path to add to pathContext, unless the rule is only used to set a path
-    const newContext = pc.hasPathRule(parentCtx.parentCtx)
-      ? path
-      : path.map(c => c.replace(/\[\+\]/g, '[=]'));
-
     // If the element is not indented, just reset the context
     if (contextIndex === 0) {
-      this.pathContext = [newContext];
+      this.pathContext = [path];
       return path;
     }
 
@@ -2096,7 +2091,7 @@ export class FSHImporter extends FSHVisitor {
         this.pathContext.length - 1
       ].map(c => c.replace(/\[\+\]/g, '[=]'));
     }
-    const fullPath = currentContext.concat(newContext);
+    const fullPath = currentContext.concat(path);
     this.pathContext.push(fullPath);
 
     return fullPath;


Test patch:
diff --git a/test/import/FSHImporter.context.test.ts b/test/import/FSHImporter.context.test.ts
index 986945b..73a6d38 100644
--- a/test/import/FSHImporter.context.test.ts
+++ b/test/import/FSHImporter.context.test.ts
@@ -189,6 +189,27 @@ describe('FSHImporter', () => {
       assertAssignmentRule(instance.rules[1], 'item[=].item[+].linkId', 'bar');
     });
 
+    it('should change + to = when setting context on children of soft indexed rules which are not path rules', () => {
+      const input = leftAlign(`
+      Instance: Foo
+      InstanceOf: Questionnaire
+      * item[+]
+        * linkId = "foo"
+        * item[+].linkId = "bar"
+    `);
+
+      const result = importSingleText(input, 'Context.fsh');
+      expect(loggerSpy.getAllMessages('error')).toHaveLength(0);
+      expect(loggerSpy.getAllMessages('warn')).toHaveLength(0);
+      expect(result.instances.size).toBe(1);
+      const instance = result.instances.get('Foo');
+      expect(instance.name).toBe('Foo');
+      expect(instance.instanceOf).toBe('Questionnaire');
+      expect(instance.rules.length).toBe(2);
+      assertAssignmentRule(instance.rules[0], 'item[+].linkId', 'foo');
+      assertAssignmentRule(instance.rules[1], 'item[=].item[+].linkId', 'bar');
+    });
+
     it('should change nested + to = when setting context on children of soft indexed rules', () => {
       const input = leftAlign(`
       Instance: Foo