Skip to content

Commit 10f5dc2

Browse files
authored
Update code-description.md
1 parent 86550f5 commit 10f5dc2

File tree

1 file changed

+19
-18
lines changed

1 file changed

+19
-18
lines changed

code-description.md

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,8 @@ We do the following for every tag we encounter during parsing.
463463

464464
Note: that `currentTagEnd` is actually the character after the closing bracket.
465465

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.
467468
- Create a new element in the `versionTags` array, containing these properties:
468469
- **tagID**: The unique ID (`tagCounter` number).
469470
- **tagSet**: The tag set ID (`tagSetID[nestingLevel]` number).
@@ -473,43 +474,43 @@ We do the following for every tag we encounter during parsing.
473474
#### `ifversion`
474475

475476
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.
477478
- 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:
479480
- 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.
483484

484485
#### `elsif`
485486

486487
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+
492493
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.
493494

494495
#### `else`
495496

496497
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.
502501

503502
#### `endif`
504503

505504
When we find an `endif` tag:
506-
- If `cursorIsAfterTag` is true we:
505+
- If `cursorIsAfterTagEnd` is true we:
507506
- 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+
509508
As with `elsif` we again reuse the unmodified `tagSetID[nestingLevel]` value that we set for the `ifversion` tag.
510509

511510
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).
512511

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+
513514
### Regular expression
514515

515516
We use the following regular expression to find version tags in the Markdown file:

0 commit comments

Comments
 (0)