Skip to content

Commit 4c9913c

Browse files
authored
Update code-description.md
1 parent 8678d1b commit 4c9913c

File tree

1 file changed

+24
-28
lines changed

1 file changed

+24
-28
lines changed

code-description.md

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -334,12 +334,11 @@ Each element of the `versionTags` array is an object containing the following pr
334334

335335
This is a recap of what we do for each type of version tag we find when we're parsing through the Markdown file.
336336

337-
#### `ifversion`
337+
#### All tags
338+
339+
We do the following for every tag we encounter during parsing.
338340

339-
When we find an `ifversion` tag we:
340341
- Increment `tagCounter`, to use as a unique ID for this tag. This variable needs to survive from one tag processing to the next.
341-
- 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
342-
- 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.
343342
- Get the start and end positions of the tag (i.e. the position of `{` and `}`) and assign them to `positionVersionTagStart` and `positionVersionTagEnd`. We do this using the `match` array that contains the tag text (e.g. `{% ifversion ghes %}`) that we found using the regular expression. We do this as follows:
344343

345344
```
@@ -355,54 +354,51 @@ When we find an `ifversion` tag we:
355354

356355
Note: that `currentTagEnd` is actually the character after the closing bracket.
357356

358-
- Check whether the cursor position is after the end position of the tag. If it is, we:
359-
- 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.
360-
- Get the version from the tag (e.g. "ghes"), using `match[1]` from the regular expression.
361-
- Assign the version to `versionDescription[nestingLevel]`.
362-
- Set `elsedVersions` 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.
357+
- Check whether the cursor position is after the end position of the tag. If it is we set `beforeCursor` to false.
363358
- Create a new element in the `versionTags` array, containing these properties:
364359
- **tagID**: The unique ID (`tagCounter` number).
365360
- **tagSet**: The tag set ID (`tagSetID[nestingLevel]` number).
366-
- **versionDescription**: The version description (`versionDescription` array of strings).
367361
- **positionVersionTagStart**: The start position of the tag (`positionVersionTagStart` vscode.Position).
368362
- **positionVersionTagEnd**: The end position of the tag (`positionVersionTagEnd` vscode.Position).
369363

370-
#### `elsif`
364+
#### `ifversion`
371365

372-
When we find an `elsif` tag we:
366+
When we find an `ifversion` tag we:
367+
- 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
368+
- 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.
369+
- If `beforeCursor` is true we:
370+
- 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.
371+
- Get the version from the tag (e.g. "ghes"), using `match[1]` from the regular expression.
372+
- Assign the version to `versionDescription[nestingLevel]`.
373+
- Set `elsedVersions` 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.
374+
375+
#### `elsif`
373376

374-
- Increment `tagCounter`, to use as a unique ID for this tag.
375-
- Get the start and end positions of the tag (i.e. the position of `{` and `}`) and assign them to `positionVersionTagStart` and `positionVersionTagEnd`.
376-
- Check whether the cursor position is after the end position of the tag. If it is, we:
377+
When we find an `elsif` tag:
378+
- If `beforeCursor` is true we:
377379
- Assign `tagSetID[nestingLevel]` to `currentTagSpan[nestingLevel]`.
378380
- Get the version from the tag (e.g. "ghec").
379381
- Assign the version to `versionDescription[nestingLevel]`.
380382
- Set `elsedVersions` to `elsedVersions + " \nAND NOT " + versionDescription[nestingLevel]` (e.g. "NOT ghes \nAND NOT ghec").
381-
- Create a new element in the `versionTags` array, as above. 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.
383+
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.
382384

383385
#### `else`
384386

385-
When we find an `else` tag we:
386-
387-
- Increment `tagCounter`, to use as a unique ID for this tag.
388-
- Get the start and end positions of the tag (i.e. the position of `{` and `}`) and assign them to `positionVersionTagStart` and `positionVersionTagEnd`.
389-
- Check whether the cursor position is after the end position of the tag. If it is, we:
387+
When we find an `else` tag:
388+
- If `beforeCursor` is true we:
390389
- Assign `tagSetID[nestingLevel]` to `currentTagSpan[nestingLevel]`.
391390
- If `nestingLevel` is >0, we set `versionDescription[nestingLevel]` to " AND ".
392391
- Set `versionDescription[nestingLevel]` to `versionDescription[nestingLevel] + elsedVersions`.
393-
- Create a new element in the `versionTags` array, as above, again reusing the unmodified `tagSetID[nestingLevel]` value that we set for the `ifversion` tag.
392+
As with `elsif` we again reuse the unmodified `tagSetID[nestingLevel]` value that we set for the `ifversion` tag.
394393

395394
#### `endif`
396395

397-
When we find an `endif` tag we:
398-
399-
- Increment `tagCounter`, to use as a unique ID for this tag.
400-
- Get the start and end positions of the tag (i.e. the position of `{` and `}`) and assign them to `positionVersionTagStart` and `positionVersionTagEnd`.
401-
- Check whether the cursor position is after the end position of the tag. If it is, we:
396+
When we find an `endif` tag:
397+
- If `beforeCursor` is true we:
402398
- Set `elsedVersions` to `""`.
403399
- Delete the last element in the `versionDescription` and `currentTagSpan` arrays.
404400
- 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).
405-
- Create a new element in the `versionTags` array, as above, again reusing the unmodified `tagSetID[nestingLevel]` value that we set for the `ifversion` tag.
401+
As with `elsif` we again reuse the unmodified `tagSetID[nestingLevel]` value that we set for the `ifversion` tag.
406402

407403
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).
408404

0 commit comments

Comments
 (0)