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


##########
src/language/providers/utils.ts:
##########
@@ -283,6 +293,31 @@ export function checkSetVariableOpen(
   return false
 }
 
+//returns an empty value or a prefix plus a colon
+export function getXsdNsPrefix(
+  document: vscode.TextDocument,
+  position: vscode.Position
+) {
+  var initialLineNum = position.line
+  var lineNum = 0
+  while (initialLineNum !== 0 && lineNum <= initialLineNum) {
+    const lineText = document
+      .lineAt(lineNum)
+      .text.substr(0, document.lineAt(lineNum).range.end.character)
+    // returns either empty prefix value or a prefix plus a colon
+    if (lineText.includes('schema')) {

Review Comment:
   I'm not sure if we need this check if a line includes `schema`. We can just 
run the regex and it will return null if there's no match, which you already do.



##########
src/language/providers/utils.ts:
##########
@@ -17,6 +17,8 @@
 
 import * as vscode from 'vscode'
 
+const schemaPrefixRegEx = new RegExp('<(.*?)schema')

Review Comment:
   This is maybe a bit too broad of a regex? For example, it would match this:
   
   ```xml
   <xs:import schemaLocation="..." />
   ```
   
   And the capture group would be `xs:import `.
   
   The regex would also match this:
   
   ```xml
   </xs:schema>
   ```
   And the capture group would be `/xs:` with the `/` included. 
   
   So an alternative regex would be:
   
   ```js
   new RegExp('</?(|[^ ]+:)schema')
   ```
   This ensures the only thing that can match between `<` and `schema` is 
either the empty string or one or more non-space characters followed by a 
colon. It also makes the leading slash optional.
   
   It's a bit more complex (and it feels like this is some toy regex to use as 
many special characters as possible :smile:), but it is probably the most 
accurate regex to avoid false positives, especially if this ends up getting 
using in more places as the extension gets bigger and more complex.



##########
src/language/providers/utils.ts:
##########
@@ -283,6 +293,31 @@ export function checkSetVariableOpen(
   return false
 }
 
+//returns an empty value or a prefix plus a colon
+export function getXsdNsPrefix(
+  document: vscode.TextDocument,
+  position: vscode.Position
+) {
+  var initialLineNum = position.line
+  var lineNum = 0
+  while (initialLineNum !== 0 && lineNum <= initialLineNum) {
+    const lineText = document
+      .lineAt(lineNum)
+      .text.substr(0, document.lineAt(lineNum).range.end.character)
+    // returns either empty prefix value or a prefix plus a colon
+    if (lineText.includes('schema')) {
+      let text = lineText.match(schemaPrefixRegEx)
+      if (text != null) {
+        console.log(text[1])

Review Comment:
   Remove this log.



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