fix: skip inline code spans and YAML front matter in attribute diagnostics#342
Merged
Merged
Conversation
Pandoc attribute syntax wrapped in backticks (for example, while
documenting `{key="value"}` rules in prose) was treated as a real
attribute block. When the example used spaces around `=` the
inline attribute diagnostic falsely reported "Remove spaces around
\"=\" in attribute assignment".
Detect CommonMark inline code spans by matching backtick runs of
equal length and exclude attribute matches whose start lies inside
such a span. Fence-header attributes that contain quoted backticks
in their info string remain unaffected.
Curly braces inside literal block scalars (for example, Typst code under `include-before-body`) were extracted by the attribute regex and triggered the spaces-around-`=` diagnostic on the body of the scalar. Detect the YAML front-matter region with a dedicated TextRange helper and treat it as an additional fenced exclusion in `extractBlocks`, alongside fenced code blocks and inline code spans.
Replace `text.split("\n")` with `indexOf("\n")` walks to avoid
allocating an intermediate line array on every `extractBlocks`
invocation. The function is called per validation (debounced) and
per code-action request, alongside `getCodeBlockRanges` which also
splits, so the redundancy compounded on each call.
Behaviour and test coverage are unchanged.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The inline attribute diagnostics provider extracted any
{...}match in the document and ran syntax-level checks on it. Two cases produced false-positive diagnostics:Documenting Pandoc attribute syntax in prose with backticks, for example
`{key = "value"}`, was treated as a real attribute and the spaces around=were flagged.YAML literal block scalars containing curly braces, for example Typst code under
include-before-body, spanned the closing brace across newlines and thelet text = it.text()body fired the spaces-around-=diagnostic.Detect CommonMark inline backtick code spans and the YAML front matter region with two new TextRange helpers in
src/utils/yamlPosition.ts, and exclude attribute matches whose endpoints fall inside either region. Fence-header attributes that contain quoted backticks in their info string remain unaffected.