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
+24-28Lines changed: 24 additions & 28 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -334,12 +334,11 @@ Each element of the `versionTags` array is an object containing the following pr
334
334
335
335
This is a recap of what we do for each type of version tag we find when we're parsing through the Markdown file.
336
336
337
-
#### `ifversion`
337
+
#### All tags
338
+
339
+
We do the following for every tag we encounter during parsing.
338
340
339
-
When we find an `ifversion` tag we:
340
341
- 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.
343
342
- 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:
344
343
345
344
```
@@ -355,54 +354,51 @@ When we find an `ifversion` tag we:
355
354
356
355
Note: that `currentTagEnd` is actually the character after the closing bracket.
357
356
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.
363
358
- Create a new element in the `versionTags` array, containing these properties:
364
359
-**tagID**: The unique ID (`tagCounter` number).
365
360
-**tagSet**: The tag set ID (`tagSetID[nestingLevel]` number).
366
-
-**versionDescription**: The version description (`versionDescription` array of strings).
367
361
-**positionVersionTagStart**: The start position of the tag (`positionVersionTagStart` vscode.Position).
368
362
-**positionVersionTagEnd**: The end position of the tag (`positionVersionTagEnd` vscode.Position).
369
363
370
-
#### `elsif`
364
+
#### `ifversion`
371
365
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`
373
376
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:
377
379
- Assign `tagSetID[nestingLevel]` to `currentTagSpan[nestingLevel]`.
378
380
- Get the version from the tag (e.g. "ghec").
379
381
- Assign the version to `versionDescription[nestingLevel]`.
380
382
- 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.
382
384
383
385
#### `else`
384
386
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:
390
389
- Assign `tagSetID[nestingLevel]` to `currentTagSpan[nestingLevel]`.
391
390
- If `nestingLevel` is >0, we set `versionDescription[nestingLevel]` to " AND ".
392
391
- 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.
394
393
395
394
#### `endif`
396
395
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:
402
398
- Set `elsedVersions` to `""`.
403
399
- Delete the last element in the `versionDescription` and `currentTagSpan` arrays.
404
400
- 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.
406
402
407
403
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).
0 commit comments