@williamcachamwri/markui-language-service
v0.2.0
Published
Editor-neutral diagnostics, completions, hover, and quick fixes for MarkUI Markdown
Maintainers
Readme
@williamcachamwri/markui-language-service
Editor-neutral diagnostics, completions, hover information, and safe quick fixes for MarkUI Markdown.
Install
npm install @williamcachamwri/markui-language-serviceCreate a service
import { createMarkUILanguageService } from '@williamcachamwri/markui-language-service'
const service = createMarkUILanguageService()The service uses the same compiler and directive validator as the Vite plugin and CLI. Editor results therefore match markui check and production builds.
Diagnostics
const diagnostics = service.validate(source, '/workspace/src/pages/index.md')Diagnostics include the stable MarkUI code, severity, filename, line, column, source range, and repair hint where available.
Completions
const items = service.complete(source, {
line: 4,
column: 8,
})Completion items cover:
- leaf and container directive names;
- unused component properties;
- enum values from component schemas;
- schema details and insertion text.
Positions are one-based to match MarkUI diagnostics.
Hover
const hover = service.hover(source, {
line: 4,
column: 6,
})Hover results describe a component or property and return the exact source range under the cursor.
Quick fixes
for (const diagnostic of service.validate(source)) {
const fixes = service.codeActions(source, diagnostic)
}The initial safe fixes cover:
- closing an unclosed container;
- removing an unexpected closing marker;
- converting a leaf component from
:::to::syntax.
The service intentionally returns no edit when a repair cannot be made safely.
Custom component registry
import { ComponentRegistry } from '@williamcachamwri/markui-core'
import { createMarkUILanguageService } from '@williamcachamwri/markui-language-service'
const registry = new ComponentRegistry([
{
name: 'hero',
allowChildren: true,
description: 'Page hero section',
props: {
tone: {
type: 'string',
enum: ['light', 'dark'],
},
},
},
])
const service = createMarkUILanguageService({ registry })Custom registries affect validation, completions, and hover information consistently.
