stevedlawrence commented on code in PR #117:
URL: https://github.com/apache/daffodil-vscode/pull/117#discussion_r889202072


##########
src/language/providers/attributeCompletion.ts:
##########
@@ -0,0 +1,275 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import * as vscode from 'vscode'
+
+import {
+  nearestOpen,
+  checkBraceOpen,
+  lineCount,
+  checkLastItemOpen,
+  checkSequenceOpen,
+  checkElementOpen,
+  checkSimpleTypeOpen,
+} from './utils'
+
+import { attributeCompletion } from './intellisense/attributeItems'
+
+function getCompletionItems(
+  itemsToUse: string[],
+  preVal: string = '',
+  additionalItems: string = ''
+) {
+  let compItems: vscode.CompletionItem[] = []
+
+  attributeCompletion(preVal, additionalItems).items.forEach((e) => {
+    if (itemsToUse.includes(e.item)) {
+      const completionItem = new vscode.CompletionItem(e.item)
+      completionItem.insertText = new vscode.SnippetString(e.snippetString)
+
+      if (e.markdownString) {
+        completionItem.documentation = new vscode.MarkdownString(
+          e.markdownString
+        )
+      }
+      compItems.push(completionItem)
+    }
+  })
+
+  return compItems
+}
+
+export function getAttributeCompletionProvider() {
+  return vscode.languages.registerCompletionItemProvider(
+    { language: 'dfdl' },
+    {
+      provideCompletionItems(
+        document: vscode.TextDocument,
+        position: vscode.Position
+      ) {
+        const wholeLine = document
+          .lineAt(position)
+          .text.substr(0, position.character)
+        var nearestOpenItem = nearestOpen(document, position)
+
+        if (
+          !checkBraceOpen(document, position) &&
+          !wholeLine.includes('assert') &&
+          !nearestOpenItem.includes('none')
+        ) {
+          if (nearestOpenItem.includes('element')) {
+            var preVal = ''
+            if (!wholeLine.includes('xs:element')) {
+              if (lineCount(document, position) === 1) {
+                preVal = '\t'
+              } else {
+                preVal = ''
+              }
+            }
+            var additionalItems = getDefinedTypes(document)
+
+            if (
+              checkLastItemOpen(document, position) &&
+              (wholeLine.includes('<xs:element name="') ||
+                wholeLine.includes('<xs:element ref="') ||
+                checkElementOpen(document, position))
+            ) {
+              return getCompletionItems(
+                [
+                  'dfdl:defineFormat',
+                  'dfdl:defineEscapeScheme',
+                  'type=',
+                  'minOccurs=',
+                  'maxOccurs=',
+                  'dfdl:occursCount=',
+                  'dfdl:byteOrder=',
+                  'dfdl:occursCountKind=',
+                  'dfdl:length=',
+                  'dfdl:lengthKind=',
+                  'dfdl:encoding=',
+                  'dfdl:alignment=',
+                  'dfdl:lengthUnits=',
+                  'dfdl:lengthPattern=',
+                  'dfdl:inputValueCalc=',
+                  'dfdl:outputValueCalc=',
+                  'dfdl:alignmentUnits=',
+                  'dfdl:terminator=',
+                  'dfdl:outputNewLine=',
+                  'dfdl:choiceBranchKey=',
+                  'dfdl:representation',
+                ],
+                preVal,
+                additionalItems
+              )
+            }
+          }
+
+          if (nearestOpenItem.includes('sequence')) {
+            var preVal = ''
+            if (!wholeLine.includes('xs:sequence')) {
+              if (lineCount(document, position) === 1) {
+                preVal = '\t'
+              } else {
+                preVal = ''
+              }
+            }
+
+            if (
+              checkLastItemOpen(document, position) &&
+              (wholeLine.includes('<xs:sequence') ||
+                checkSequenceOpen(document, position))
+            ) {
+              return getCompletionItems(
+                [
+                  'dfdl:hiddenGroupRef=',
+                  'dfdl:sequenceKind=',
+                  'dfdl:separator=',
+                  'dfdl:separatorPosition=',
+                  'dfdl:separatorSuppressionPolicy',
+                ],
+                preVal
+              )
+            }
+          }
+
+          if (wholeLine.includes('choice')) {
+            if (!wholeLine.includes('>')) {
+              return getCompletionItems([
+                'dfdl:choiceLengthKind=',
+                'dfdl:choiceLength=',
+                'dfdl:intiatedContent=',
+                'dfdl:choiceDispatchKey=',
+                'dfdl:choiceBranchKey=',
+              ])
+            }
+          }
+
+          if (
+            wholeLine.includes('simpleType') ||
+            checkSimpleTypeOpen(document, position)
+          ) {
+            if (!wholeLine.includes('>')) {
+              return getCompletionItems([
+                'dfdl:length=',
+                'dfdl:lengthKind=',
+                'dfdl:simpleType',
+                'dfdl:simpleType',
+                'xs:restriction',
+              ])
+            }
+          }
+
+          if (wholeLine.includes('defineVariable')) {
+            var preVal = ''
+            if (!wholeLine.includes('dfdl:defineVariable')) {
+              if (lineCount(document, position) === 1) {
+                preVal = '\t'
+              } else {
+                preVal = ''
+              }
+            }
+            var additionalItems = getDefinedTypes(document)
+
+            var xmlItems = [
+              {
+                item: 'type=',
+                snippetString:
+                  preVal +
+                  
'type="${1|xs:string,xs:decimal,xs:float,xs:double,xs:integer,xs:nonNegativeInteger,xs:int,xs:unsignedInt,xs:short,xs:unsignedShort,xs:long,xs:unsignedLong,xs:byte,xs:unsignedByte,xs:hexBinary,xs:boolean'
 +

Review Comment:
   Fine with me.



-- 
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