Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: component and prop suggestions from remote API #43

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
37 changes: 36 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,46 @@ The plugin also enables a document format provider. You may customize the settin
> [!Note]
> Since the format provider utilizes spaces for indention, you may also need to configure your project to insert spaces for tabs within `.mdc` or `.md` files.

### Component name and prop suggestions

The extension provides intelligent auto-completion for MDC components and their properties when provided with a `mdc.componentMetadataURL` in your VS Code settings.

When typing a colon (`:`) in your MDC document, the extension will suggest available component names. Within MDC component YAML frontmatter sections (between `---`), the extension provides contextual prop suggestions (including nested props) with types and documentation where provided.

The endpoint provided to `mdc.componentMetadataURL` should return JSON data in the following format:

```typescript
interface MDCComponentData {
/** The kebab-case name of the markdown component */
mdc_name: string
/** Component description */
description?: string
/** Markdown-formatted documentation */
documentation_markdown?: string
/** URL to component documentation */
docs_url?: string
/** Component metadata from `@nuxtlabs/nuxt-component-meta` */
component_meta: { ... }
}

type MDCMetadataResponse = MDCComponentData[]
```

To configure the metadata URL for your project, create or edit `.vscode/settings.json` in your project's root directory:

```json
{
"mdc.componentMetadataURL": "https://example.com/api/mdc-components",
"mdc.componentMetadataCacheTTL": 360 // Cache duration in minutes
}
```

The extension caches component metadata for 6 hours and provides a command `MDC: Refresh Component Metadata` to manually update the cache. To customize the cache TTL you may customize the value for `mdc.componentMetadataCacheTTL` in settings. Defaults to `360` minutes (6 hours).

### For more information

* [MDC Syntax Reference](https://content.nuxt.com/usage/markdown#introduction)


<!-- Badges -->
[extension-href]: https://marketplace.visualstudio.com/items?itemName=Nuxt.mdc
[extension-version-src]: https://img.shields.io/visual-studio-marketplace/v/Nuxt.mdc?label=Visual%20Studio%20Code&style=flat&colorA=020420&colorB=28CF8D
Expand Down
38 changes: 38 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,38 @@
"path": "./snippets/markdown.code-snippets"
}
],
"configuration": {
"title": "MDC - Markdown Components",
"properties": {
"mdc.componentMetadataURL": {
"type": "string",
"default": "",
"description": "The URL from which to fetch MDC (Markdown Component) metadata."
},
"mdc.componentMetadataCacheTTL": {
"type": "number",
"default": 360,
"description": "The number of minutes to cache the MDC (Markdown Component) metadata. Defaults to 360 (6 hours)."
},
"mdc.debug": {
"type": "boolean",
"default": false,
"description": "Enable component metadata debug logging"
}
}
},
"commands": [
{
"command": "mdc.showOutput",
"title": "Show extension output",
"category": "MDC"
},
{
"command": "mdc.refreshMetadata",
"title": "Refresh component metadata",
"category": "MDC"
}
],
"configurationDefaults": {
"[mdc]": {
"editor.folding": true,
Expand All @@ -91,6 +123,7 @@
"publish": "vsce publish --no-dependencies"
},
"devDependencies": {
"@nuxt/schema": "^3.15.4",
"@nuxtjs/eslint-config-typescript": "^12.1.0",
"@nuxtlabs/monarch-mdc": "^0.5.0",
"@types/node": "^18.19.70",
Expand All @@ -101,6 +134,11 @@
"standard-version": "^9.5.0",
"typescript": "5.2.2",
"vscode": "^1.1.37",
"vscode-textmate": "^9.2.0",
"vue-component-meta": "^2.2.4"
},
"dependencies": {
"scule": "^1.3.0",
"vscode-textmate": "^9.2.0"
}
}
Loading