rthomas320 commented on PR #1334:
URL: https://github.com/apache/daffodil-vscode/pull/1334#issuecomment-3117457304

   > +1
   > 
   > The changes resolve the issue, however, from a readability standpoint it 
can be a lot to keep track of when pattern matching strings from the variety of 
`.includes(...)`, `.startsWith(...)`, etc..
   > 
   > It would be nice to extract multiple constraints within the conditionals 
into a single call
   > 
   > ```ts
   > const triggerText = document.lineAt(lineNum).text
   > if(textMatches( 
   >    triggerText, 
   >    /* array of predicates to match */
   > ) return lineCount
   > ```
   
   I'll take a look at it. There is no "textMatches" function in TypeScript, 
but I assume you meant to create a function with string.match() which use regex 
expressions. Though I'm not sure regex expressions are easier to understand 
than the string functions they would be replacing considering I would need to 
use an expression that includes some strings '<' + the value for nsPrefix + the 
value for tag and excludes the character '>' or in some instances the 
characters '/>' or '</'
   
   For instance, this works:
   `  let testVal: string = '<' + nsPrefix + tag
     let testPattern: string = '^"' + testVal + '".*[^>]'
     let regex: RegExp = new RegExp(testPattern)
     if (currentText.match(regex) === null) {
       ...
     }
   `
   but is it easier to understand than this:
   `  if (
       triggerText.trim().startsWith('<' + nsPrefix + tag) &&
       triggerText.indexOf('>', tagPos) < 0 //if tag ending character is 
missing will return -1
     ) {
      ...
     }
   `


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