You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: code-description.md
+19-18Lines changed: 19 additions & 18 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -463,7 +463,8 @@ We do the following for every tag we encounter during parsing.
463
463
464
464
Note: that `currentTagEnd` is actually the character after the closing bracket.
465
465
466
-
- Check whether the cursor position is before the beginning of the tag. If it is we set `cursorIsAfterTag` to false.
466
+
- Check whether the cursor position is after the start of the current tag (in which case the tag may affect the text at the cursor position). If it's not we set `cursorIsAfterTagStart` to `false`.
467
+
- Check whether the cursor position is after the end of the current tag. If it's not we set `cursorIsAfterTagEnd` to `false`. We only use this for `endif` tags.
467
468
- Create a new element in the `versionTags` array, containing these properties:
468
469
-**tagID**: The unique ID (`tagCounter` number).
469
470
-**tagSet**: The tag set ID (`tagSetID[nestingLevel]` number).
@@ -473,43 +474,43 @@ We do the following for every tag we encounter during parsing.
473
474
#### `ifversion`
474
475
475
476
When we find an `ifversion` tag we:
476
-
- Increment `nestingLevel`. Initially this is -1, so this becomes 0 for an un-nested tag set and 1 for the first nesting level. This variable needs to survive from one tag processing to the next
477
+
- Increment `nestingLevel`. Initially this is -1, so this becomes 0 for an un-nested tag set and 1 for the first nesting level. This variable needs to survive from one tag processing to the next.
477
478
- Assign `tagCounter` to `tagSetID[nestingLevel]`. This is the ID of the tag set that this tag belongs to (always the same as the ifversion ID). This array needs to survive from one tag processing to the next.
478
-
- If `cursorIsAfterTag` is true we:
479
+
- If `cursorIsAfterTagStart` is true we:
479
480
- Assign `tagCounter` to `currentTagSpan[nestingLevel]`. This array needs to survive from one tag processing to the next so that we can determine which tag span the cursor is currently within, and therefore which tags we need to highlight.
480
-
- Get the version from the tag (e.g. "ghes"), using `match[1]` from the regular expression.
481
-
- Assign the version to `versionDescription[nestingLevel]`.
482
-
-Set `elsedVersions[nestingLevel]` to `"NOT " + versionDescription[nestingLevel]`(e.g. "NOT ghes"). For nested `ifversion` tags we prepend "\nAND " to the start of the string. This variable needs to survive from one tag processing to the next, so that we can build up a string that describes the versioning for the `else` tag in the tag set.
481
+
- Get the version from the tag (e.g. "ghes"), using `match[2]` from the regular expression.
482
+
- Assign the `match[2]` to `versionDescription[nestingLevel]` for an un-nested tag set. For nested tag sets assign `"AND " + match[2]` (e.g. "AND ghes").
483
+
-Assign `"NOT " + match[2]` to `versionDescription[nestingLevel]`for an un-nested tag set. For nested tag sets assign `"AND NOT " + match[2]` (e.g. "AND NOT ghes"). This variable needs to survive from one tag processing to the next, so that we can build up a string that describes the versioning for the `else` tag in the tag set.
483
484
484
485
#### `elsif`
485
486
486
487
When we find an `elsif` tag:
487
-
- If `cursorIsAfterTag` is true we:
488
-
- Assign `tagSetID[nestingLevel]` to `currentTagSpan[nestingLevel]`.
489
-
-Get the version from the tag (e.g. "ghec").
490
-
-Assign the version to `versionDescription[nestingLevel]`.
491
-
- Set `elsedVersions[nestingLevel]` to `elsedVersions[nestingLevel] + " \nAND NOT " + versionDescription[nestingLevel]` (e.g. "NOT ghes \nAND NOT ghec").
488
+
- If `cursorIsAfterTagStart` is true we:
489
+
- Assign `tagCounter` to `currentTagSpan[nestingLevel]`.
490
+
-Assign the version to `versionDescription[nestingLevel]`, prepending "AND " if we're in a nested tag set.
491
+
-Set `elsedVersions[nestingLevel]`to `elsedVersions[nestingLevel] + " \nAND NOT " + match[2]` (e.g. "NOT ghes \nAND NOT ghec").
492
+
492
493
Note that we don't assign a value to `tagSetID[nestingLevel]` because this tag doesn't start a new tag set. It belongs to the same tag set as the `ifversion` tag. So we use the same `tagSetID[nestingLevel]` value that we set for the `ifversion` tag.
493
494
494
495
#### `else`
495
496
496
497
When we find an `else` tag:
497
-
- If `cursorIsAfterTag` is true we:
498
-
- Assign `tagSetID[nestingLevel]` to `currentTagSpan[nestingLevel]`.
499
-
- If `nestingLevel` is >0, we set `versionDescription[nestingLevel]` to " AND ".
500
-
- Set `versionDescription[nestingLevel]` to `versionDescription[nestingLevel] + elsedVersions[nestingLevel]`.
501
-
As with `elsif` we again reuse the unmodified `tagSetID[nestingLevel]` value that we set for the `ifversion` tag.
498
+
- If `cursorIsAfterTagStart` is true we:
499
+
- Assign `tagCounter` to `currentTagSpan[nestingLevel]`.
500
+
- Assign the `elsedVersions[nestingLevel]` to `versionDescription[nestingLevel]`, prepending "AND " if we're in a nested tag set.
502
501
503
502
#### `endif`
504
503
505
504
When we find an `endif` tag:
506
-
- If `cursorIsAfterTag` is true we:
505
+
- If `cursorIsAfterTagEnd` is true we:
507
506
- Delete the last element in the `currentTagSpan`, `versionDescription` and `elsedVersions` arrays.
508
-
- Decrement `nestingLevel`. At each `endif` we're stepping out of a level of nesting, or out of versioning altogether this is the `endif` for an un-nested tag set (in which case `nestingLevel` returns to -1).
507
+
509
508
As with `elsif` we again reuse the unmodified `tagSetID[nestingLevel]` value that we set for the `ifversion` tag.
510
509
511
510
Note: the cursor can never be within an `endif` tag span, because `endif` tags have no tag span. So we'll never use the `tagID` or `versionDescription` properties of an `endif` tag. We'll only use the `tagSet` property (to identify the `endif` tag to highlight when the cursor is somewhere else within this tag set) and the `positionVersionTagStart` and `positionVersionTagEnd` properties (to tell VS Code which characters to highlight for this tag).
512
511
512
+
After we create the `versionTags` entry for this `endif` tag, we decrement `nestingLevel`. We do this because, after each `endif` tag, we step out of a level of nesting, or out of versioning altogether this is the `endif` for an un-nested tag set (in which case `nestingLevel` returns to -1).
513
+
513
514
### Regular expression
514
515
515
516
We use the following regular expression to find version tags in the Markdown file:
0 commit comments