Skip to content

Enhance SQL keyword detection in bracket matcher#535

Open
buzzia2001 wants to merge 3 commits into
codefori:mainfrom
buzzia2001:fixErrorHighlight
Open

Enhance SQL keyword detection in bracket matcher#535
buzzia2001 wants to merge 3 commits into
codefori:mainfrom
buzzia2001:fixErrorHighlight

Conversation

@buzzia2001

Copy link
Copy Markdown
Member

Changes

This PR improves the search for keywords that also manage blocks within SQL statements and excludes them from the analysis.

How to test

Open an RPG source file containing SQL statements with keywords such as IF, and verify that the closing keywords of the block are not highlighted in red

Checklist

  • have tested my change

@buzzia2001 buzzia2001 requested a review from bobcozzi June 13, 2026 09:45
@bobcozzi

bobcozzi commented Jun 13, 2026

Copy link
Copy Markdown
Collaborator

I am seeing two issues:

  1. END-PROC sometimes gets highlighted/flagged in the RED BOX.
  2. The /END-FREE directive always seems to have it END word flagged with the red-box.
  3. Any variables that begins with END is treated as an ENDxx statement and causes the stack to go casters-up.
dcl-proc testClosingKeywordNames;
  dcl-s enddo int(10);   // Variable named 'enddo'
  dcl-s endif int(10);   // Variable named 'endif'
  dcl-s endfor int(10);  // Variable named 'endfor'
  dcl-s endsl int(10);   // Variable named 'endsl'
  dcl-s i int(10);

  enddo = 100;   // Assignment - these are variables, not keywords
  endif = 50;
  endfor = 25;
  endsl = 10;

  // Use them in expressions
  dow i < enddo;  // 'enddo' is a variable here
    if i < endif;  // 'endif' is a variable here
      i += 1;
    endif;  // Real ENDIF keyword closes the IF
  enddo;    // Real ENDDO keyword closes the DOW

  // Use in assignments with operators
  enddo += 5;   // Variable assignment
  endif -= 2;   // Variable assignment
  endfor *= 2;  // Variable assignment
  endsl /= 2;   // Variable assignment

  return;
end-proc;

I am debugging now and will report my results and a likely fix if I can find it.
But the SQL stuff you changed seems to be working well.

Summary of Bug Fixes for PR 535

I've identified and fixed a critical bug that was causing ENDIF, ENDDO, ELSE, and ELSEIF statements to be incorrectly flagged with red error highlights in debug mode.

Root Cause

The isVariableContext() function in both bracketMatcher.ts and blockParser.ts was treating ALL keywords followed by ( as variables. This broke normal control flow statements like:

  • if (condition)
  • dou (condition)
  • elseif (condition)

When these keywords were incorrectly marked as variables, they weren't added to the block stack, causing their corresponding closing statements (ENDIF, ENDDO, ELSE) to have no matching opening keywords - resulting in red error highlights.

Fix Applied

Modified the isVariableContext() function to only treat a keyword followed by ( as a variable if it's also preceded by operators that indicate it's being used as a value in an expression (., (, ,, etc.).

Examples that now work correctly:

  • if (condition) → KEYWORD (control flow) - no preceding operator
  • foo(end) → VARIABLE (function parameter) - preceded by (
  • arr(if) → VARIABLE (array subscript) - preceded by (
  • ds.end(x) → VARIABLE (data structure field) - preceded by .

Files Modified

  1. extension/client/src/language/bracketMatcher.ts - Updated isVariableContext() logic
  2. language/utils/blockParser.ts - Updated isVariableContext() logic
  3. tests/suite/bracketValidation.test.ts - Updated test cases

Testing

Verified the fix resolves the debug mode highlighting issue:

  • Control flow keywords (if, dou, elseif) followed by ( are now correctly identified as keywords
  • Their corresponding closing statements (ENDIF, ENDDO, ELSE) no longer show red error highlights
  • Variables named with keywords in expression contexts still work correctly

The changes have been tested and pushed to the pr-535 branch.

@bobcozzi bobcozzi left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary of Bug Fixes for PR 535

I've identified and fixed a critical bug that was causing ENDIF, ENDDO, ELSE, and ELSEIF statements to be incorrectly flagged with red error highlights in debug mode.

Root Cause

The isVariableContext() function in both bracketMatcher.ts and blockParser.ts was treating ALL keywords followed by ( as variables. This broke normal control flow statements like:

  • if (condition)
  • dou (condition)
  • elseif (condition)

When these keywords were incorrectly marked as variables, they weren't added to the block stack, causing their corresponding closing statements (ENDIF, ENDDO, ELSE) to have no matching opening keywords - resulting in red error highlights.

Fix Applied

Modified the isVariableContext() function to only treat a keyword followed by ( as a variable if it's also preceded by operators that indicate it's being used as a value in an expression (., (, ,, etc.).

Examples that now work correctly:

  • if (condition) → KEYWORD (control flow) - no preceding operator
  • foo(end) → VARIABLE (function parameter) - preceded by (
  • arr(if) → VARIABLE (array subscript) - preceded by (
  • ds.end(x) → VARIABLE (data structure field) - preceded by .

Files Modified

  1. extension/client/src/language/bracketMatcher.ts - Updated isVariableContext() logic
  2. language/utils/blockParser.ts - Updated isVariableContext() logic
  3. tests/suite/bracketValidation.test.ts - Updated test cases

Testing

Verified the fix resolves the debug mode highlighting issue:

  • Control flow keywords (if, dou, elseif) followed by ( are now correctly identified as keywords
  • Their corresponding closing statements (ENDIF, ENDDO, ELSE) no longer show red error highlights
  • Variables named with keywords in expression contexts still work correctly

The changes have been tested and pushed to the pr-535 branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants