Skip to content

fix(markdown): include embedded document in its containing document - #133

Open
gasparoff wants to merge 1 commit into
volarjs:masterfrom
gasparoff:fix-markdown-anchor-completions
Open

gasparoff wants to merge 1 commit into
volarjs:masterfrom
gasparoff:fix-markdown-anchor-completions

Conversation

@gasparoff

Copy link
Copy Markdown

getContainingDocument() returns a context with children: [] for every embedded document. In vscode-markdown-languageservice, TableOfContents.createForContainingDoc() builds the table of contents only from children when a context is returned. So for embedded Markdown (for example, MDX in mdx-analyzer) the table of contents of the current document is always empty, and completions for same-file anchors ([text](#|)) return nothing.

This lists the embedded document itself as the only child, so its headers are found.

Fixes the same-file case of mdx-js/mdx-analyzer#482.

Verification

  • Checked against mdx-analyzer's language server (with volar-service-markdown patched in node_modules): requesting completion at [x](#|) in an .mdx file with two headings returned [] before and #hello-world, #second-heading after. This now matches plain .md files.
  • All 21 existing mdx-analyzer language-server tests still pass.
  • Document links, link resolution, definitions, diagnostics and ## workspace header completions return the same results before and after. children is only read by createForContainingDoc(), and the other callers of getContainingDocument() only use .uri.
  • pnpm build and pnpm lint pass. I couldn't run dprint locally (the plugin download failed), so formatting was checked by hand.

Not covered: headers of relative .md files that aren't open (also mentioned in mdx-js/mdx-analyzer#482). That needs a different change in getTextDocument().

Prepared with the help of Claude Code; tested as described above.

Co-Authored-By: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant