Skip to content

feat: add slot name completions for block components - #99

Open
arashsheyda wants to merge 3 commits into
comarkdown:mainfrom
arashsheyda:feat/slot-name-completions
Open

feat: add slot name completions for block components#99
arashsheyda wants to merge 3 commits into
comarkdown:mainfrom
arashsheyda:feat/slot-name-completions

Conversation

@arashsheyda

@arashsheyda arashsheyda commented Jun 18, 2026

Copy link
Copy Markdown
Collaborator

Description

closes #95

this PR adds intelligent #slot-name completions inside MDC block components (e.g. ::card), with support for multiple slot discovery sources

Supported frameworks: Vue, Svelte, React/TSX, Angular

Screen.Recording.2026-06-18.at.5.23.49.PM.mov

@farnabaz

Copy link
Copy Markdown
Collaborator

Thanks for PR @arashsheyda,
Finding slots directly from files is interesting approach which led to support react and svelte files.

/cc @adamdehaven Would love you have your review on this one :)

Comment thread vitest.config.ts Outdated
Comment thread src/slot-completion-provider.ts Outdated
Comment thread src/slot-completion-provider.ts Outdated
Comment thread src/slot-completion-provider.ts Outdated
Comment thread src/slot-completion-provider.ts Outdated
Comment thread src/slot-completion-provider.ts Outdated
Comment thread test/unit/slot-completion-provider.test.ts Outdated
@arashsheyda
arashsheyda requested a review from adamdehaven June 29, 2026 01:43
Comment on lines +9 to +12
const MDC_COMPONENT_START_REGEX = /^\s*:{2,}([\w-]+)/
/** Regex to match block component closing lines (2+ colons with no name) */
const MDC_COMPONENT_END_REGEX = /^\s*:{2,}\s*$/
const SLOT_PATTERN = /^\s*#([\w-]+)/

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aren't these patterns already defined elsewhere in the repo?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only MDC_COMPONENT_START_REGEX

Comment thread src/utils/document.ts
Comment on lines +10 to +28
export function isInsideYAMLBlock (document: vscode.TextDocument, lineNumber: number): boolean {
let inside = false
for (let i = 0; i < lineNumber; i++) {
const line = document.lineAt(i).text.trim()
if (/^\s*---\s*$/.test(line)) {
inside = !inside
}
}
return inside
}

/**
* Determines if the current position is inside a fenced code block.
*
* @param {vscode.TextDocument} document - The VS Code text document
* @param {number} lineNumber - The 0-based line number of the current cursor position
* @returns {boolean} - True if inside a code block, false otherwise
*/
export function isInsideCodeBlock (document: vscode.TextDocument, lineNumber: number): boolean {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't these two functions already exist in the repo?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you check the code you can see that it's been moved to utils ?

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds #slot-name completion support inside MDC block components by introducing a new slot completion provider that can source slot names from component metadata, in-document usage, open documents, and framework component source files (Vue/Svelte/React/Angular). It also refactors shared “inside YAML/code block” detection into a utility module and expands the Vitest include pattern so new src/**/*.test.ts tests are executed.

Changes:

  • Add slot extraction utilities for Vue/Svelte/React/Angular and corresponding unit tests.
  • Introduce a slot completion provider with caching and multi-source slot discovery, plus tests for core parsing helpers.
  • Refactor YAML/code-block detection into src/utils/document.ts, update docs, and ensure new tests are included in Vitest runs.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
vitest.config.ts Expands test include globs to run new src/**/*.test.ts unit tests.
src/utils/slot-extractors.ts Adds framework-specific slot name extraction helpers.
src/utils/slot-extractors.test.ts Adds unit tests covering the new slot extraction helpers.
src/utils/document.ts Adds reusable helpers to detect YAML frontmatter blocks and fenced code blocks.
src/utils/document.test.ts Adds tests for the YAML/code-block detection helpers.
src/slot-completion-provider.ts Implements slot completion with metadata + discovery + workspace file scanning and caching.
src/slot-completion-provider.test.ts Adds tests for document-scoped slot parsing helpers used by the provider.
src/extension.ts Registers the new slot completion provider and adds cache invalidation hooks.
src/completion-providers.ts Switches to the new shared YAML/code-block helpers (removes duplicated logic).
README.md Documents the new slot completion feature and its discovery sources.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread README.md
Comment thread src/extension.ts
Comment on lines +195 to +199
// Invalidate slot cache when component source files change
const componentWatcher = vscode.workspace.createFileSystemWatcher('**/*.{vue,svelte,tsx,jsx}')
componentWatcher.onDidChange(() => invalidateSlotCache())
componentWatcher.onDidCreate(() => invalidateSlotCache())
componentWatcher.onDidDelete(() => invalidateSlotCache())
@coldtea-pr-lens

coldtea-pr-lens Bot commented Sep 3, 2026

Copy link
Copy Markdown

◈ PR Lens

🟢 +3 new · 🟠 ~3 changed · 🔴 -0 removed · 2 flows · 10 files · commit 240e8c2


Architecture

Architecture diagram for comarkdown/vscode-comark at 240e8c2

6 components touched across 4 lanes.

Open full size


Inside the changed components — 1 view

Component view — Slot completion provider

Internal decomposition of the slot completion engine into document syntax validation, framework-specific slot extractors, and metadata resolution.

Architecture view of Component view — Slot completion provider in comarkdown/vscode-comark

Data flow

Data flow diagram for comarkdown/vscode-comark at 240e8c2

Resolving slot completions · Invalidating slot cache on file change

Open full size


The other flows — 1 sequence

Invalidating slot cache on file change

Sequence diagram of Invalidating slot cache on file change in comarkdown/vscode-comark

Drill down
Extension Core — 5 components
🟡 CHANGED Extension Controller

Activates extension capabilities, registers the '#' trigger slot completion provider alongside existing completion providers, and manages workspace file watchers for slot cache invalidation.

🟡 CHANGED Completion Engine

Provides IntelliSense completion items for MDC block component names and properties, delegating syntax block boundary checks to shared document utilities.

🟢 NEW Slot Completion Provider

Resolves '#' slot completions within block components by querying component metadata, scanning open markdown documents, searching workspace component files, and filtering out already-used slots.

🟢 NEW Slot Extractors

Extracts slot and snippet definitions from Vue SFCs, Svelte components, React/TSX props interfaces, and Angular component templates.

🟢 NEW Document Utilities

Detects whether cursor positions reside within YAML frontmatter blocks or fenced markdown code blocks to suppress invalid completion triggers.

Tooling & Delivery — 1 component
🟡 CHANGED Manifest Unit Tests

Vitest test configuration and unit test suite, updated to execute unit tests across src for slot providers, extractors, and document utilities.


View

  • Architecture lens
  • Data flow lens
  • Expand every detail
  • Show unchanged neighbours

Tip

Draw a diff before it is even a pull request: npx @coldtea/pr-lens-cli analyze --base origin/main reads the diff with your own model key, and npx @coldtea/pr-lens-cli render .pr-lens/graph.json draws the same lenses on your machine.

🪧 More tips
  • Run PR Lens on your own machine: npx skills add coldteadotai/pr-lens installs the agent skill. Then tell your coding agent: "Diagram the change you just made with PR Lens and attach it to the pull request."
  • The boxes under View are live. Tick Architecture lens or Data flow lens to choose which diagrams appear, or Expand every detail to open every drill-down at once. The comment redraws in place a few seconds later.
  • Show unchanged neighbours lists the components this change did not touch alongside the ones it did, so the drill-down shows what the changed code sits next to.
  • GitHub will not let you zoom an image in a comment. The link under each diagram opens it full size on a page of its own, where you can.
  • The CLI's render picks up .github/pr-lens.yml automatically and applies your corrections (renames, exclusions, lane pins) at draw time.
  • Would you rather run it from CI on a key of your own? Add .github/workflows/pr-lens.yml with coldteadotai/pr-lens/packages/action@v0 and a model key in your repository secrets, say GEMINI_API_KEY. The Action asks Gemini by default, or OpenAI and any endpoint speaking /chat/completions through its provider input.
  • PR Lens is free for open source. A star on the repository is what keeps it going.
  • Push a new commit and the whole comment re-renders for the new head. An older run never overwrites a newer one, so a slow render cannot put a stale diagram back.
  • The diagrams follow your GitHub theme, so dark mode gets the dark render and light mode the light one, and the moving dots show this pull request's data in motion.

◈ Rendered by PR Lens · crafted with ❤️ by the Coldtea team · Something drawn wrong?

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.

[Feature Request]: slot name completions

5 participants