rt320 commented on code in PR #292:
URL: https://github.com/apache/daffodil-vscode/pull/292#discussion_r970823649


##########
src/language/providers/closeElement.ts:
##########
@@ -27,59 +27,71 @@ export function getCloseElementProvider() {
         position: vscode.Position
       ) {
         var backpos = position.with(position.line, position.character - 1)
+        const nsPrefix = getNsPrefix(document, position)
         const nearestOpenItem = nearestOpen(document, position)
-        const wholeLine = document
+        const triggerText = document
           .lineAt(position)
           .text.substr(0, position.character)
 
         if (
-          wholeLine.endsWith('>') &&
-          (wholeLine.includes('xs:element') ||
+          !triggerText.includes('</') &&
+          triggerText.endsWith('>') &&
+          (triggerText.includes('<' + nsPrefix + 'element') ||
             nearestOpenItem.includes('element') ||
-            wholeLine.includes('xs:group') ||
+            triggerText.includes('<' + nsPrefix + 'group') ||
             nearestOpenItem.includes('group') ||
-            wholeLine.includes('xs:sequence') ||
+            triggerText.includes('<' + nsPrefix + 'sequence') ||
             nearestOpenItem.includes('sequence') ||
-            wholeLine.includes('xs:simpleType') ||
+            triggerText.includes('<' + nsPrefix + 'simpleType') ||
             nearestOpenItem.includes('simpleType') ||
-            wholeLine.includes('dfdl:defineVariable') ||
+            triggerText.includes('<' + nsPrefix + 'choice') ||
+            nearestOpenItem.includes('choice') ||
+            triggerText.includes('dfdl:defineVariable') ||
             nearestOpenItem.includes('Variable'))
         ) {
           var range = new vscode.Range(backpos, position)
           vscode.window.activeTextEditor?.edit((editBuilder) => {
             editBuilder.replace(range, '')
           })
           if (
-            wholeLine.endsWith('>') &&
-            (wholeLine.includes('xs:element ref') ||
-              wholeLine.includes('xs:group ref'))
+            triggerText.endsWith('>') &&
+            (triggerText.includes('<' + nsPrefix + 'element ref') ||
+              triggerText.includes('<' + nsPrefix + 'group ref'))
           ) {
             insertSnippet(' />\n$0', backpos)
           } else if (
-            wholeLine.endsWith('>') &&
-            (wholeLine.includes('xs:element') ||
+            triggerText.endsWith('>') &&
+            (triggerText.includes('<' + nsPrefix + 'element') ||
               nearestOpenItem.includes('element'))
           ) {
-            insertSnippet('>\n\t$0\n</xs:element>', backpos)
+            insertSnippet('>\n\t$0\n</' + nsPrefix + 'element>', backpos)
           } else if (
-            wholeLine.endsWith('>') &&
-            (wholeLine.includes('xs:group') ||
+            triggerText.endsWith('>') &&
+            (triggerText.includes('<' + nsPrefix + 'group') ||
               nearestOpenItem.includes('group'))
           ) {
-            insertSnippet('>\n\t$0\n</xs:group>', backpos)
+            insertSnippet('>\n\t$0\n</' + nsPrefix + 'group>', backpos)
           } else if (
-            (wholeLine.endsWith('>') && wholeLine.includes('xs:sequence')) ||
+            (triggerText.endsWith('>') &&
+              triggerText.includes('<' + nsPrefix + 'sequence')) ||
             nearestOpenItem.includes('sequence')
           ) {
-            insertSnippet('>\n\t$0\n</xs:sequence>', backpos)
+            insertSnippet('>\n\t$0\n</' + nsPrefix + 'sequence>', backpos)
           } else if (
-            (wholeLine.endsWith('>') && wholeLine.includes('xs:simpleType')) ||
+            (triggerText.endsWith('>') &&
+              triggerText.includes('<' + nsPrefix + 'choice')) ||
+            nearestOpenItem.includes('choice')

Review Comment:
   I pull latest code from main



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to