diff --git a/README.md b/README.md index eadbf54..ce31db4 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,10 @@ It is possible to have multiple Markdoc configurations for the same workspace by In [multi-root workspaces](https://code.visualstudio.com/docs/editor/multi-root-workspaces), a Markdoc configuration file is specific to an individual workspace root. You can have separate Markdoc configuration files for each root. If you need to override the location of the Markdoc language server configuration file in a multi-root workspace, you can use a [folder setting](https://code.visualstudio.com/docs/editor/multi-root-workspaces#_settings) to customize this behavior per root. +# Extending the language server with custom functionality + +The language server is published as a [package on npm](https://www.npmjs.com/package/@markdoc/language-server) in order to support extensibility and customization. You can tailor the functionality to your needs by adding plugins or creating subclasses that substitute built-in plugins. Support for this is somewhat experimental and the APIs exposed by the package are still subject to change. We will not guarantee API stability or backwards compatibility for language server plugins until the 1.0 release. + # Contributing Contributions and feedback are welcomed and encouraged. Feel free to open PRs here, or open issues and discussion threads in the [Markdoc core repo](https://github.com/markdoc/markdoc). diff --git a/client/package.json b/client/package.json index 045cca5..6ec5491 100644 --- a/client/package.json +++ b/client/package.json @@ -3,7 +3,7 @@ "description": "Markdoc Extension", "author": "Ryan Paul", "license": "MIT", - "version": "0.0.2", + "version": "0.0.3", "scripts": { "build": "esbuild index.ts --bundle --outdir=dist --sourcemap=linked --external:vscode --platform=node --format=cjs", "build:server": "esbuild server.ts --bundle --outdir=dist --sourcemap=linked --external:vscode --platform=node --format=cjs" diff --git a/package.json b/package.json index 3d6e51b..82eb5ad 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "author": "Ryan Paul", "publisher": "stripe", "license": "MIT", - "version": "0.0.2", + "version": "0.0.3", "description": "A Markdoc language server and Visual Studio Code extension", "repository": { "type": "git", diff --git a/server/package.json b/server/package.json index 976ff3a..eddfb82 100644 --- a/server/package.json +++ b/server/package.json @@ -1,6 +1,6 @@ { "name": "@markdoc/language-server", - "version": "0.0.2", + "version": "0.0.3", "description": "A Markdoc language server", "main": "dist/index.js", "author": "Ryan Paul", diff --git a/server/plugins/validation.ts b/server/plugins/validation.ts index 7ba87f3..455a468 100644 --- a/server/plugins/validation.ts +++ b/server/plugins/validation.ts @@ -10,9 +10,9 @@ export default class ValidationProvider { protected connection: LSP.Connection, protected services: ServiceInstances ) { - services.Documents.onDidSave(this.onValidate, this); + services.Documents.onDidSave(this.onDidSave, this); services.Documents.onDidClose(this.onDidClose, this); - services.Documents.onDidChangeContent(this.onValidate, this); + services.Documents.onDidChangeContent(this.onDidChangeContent, this); } severity(level: string): LSP.DiagnosticSeverity { @@ -56,7 +56,7 @@ export default class ValidationProvider { return LSP.Range.create(line, 0, line + 1, 0); } - onValidate({ document: { uri } }: TextChangeEvent) { + validate(uri: string) { const doc = this.services.Documents.ast(uri); const schema = this.services.Schema.get(); @@ -64,8 +64,7 @@ export default class ValidationProvider { const config = this.configuration(uri); const errors = Markdoc.validate(doc, config); - const diagnostics = errors.map((err) => this.diagnostic(err)); - this.connection.sendDiagnostics({ uri, diagnostics }); + return errors.map((err) => this.diagnostic(err)); } configuration(uri: string): Markdoc.Config { @@ -81,6 +80,16 @@ export default class ValidationProvider { return { ...Schema?.get(), partials }; } + onDidSave({ document: { uri } }: TextChangeEvent) { + const diagnostics = this.validate(uri); + if (diagnostics) this.connection.sendDiagnostics({ uri, diagnostics }); + } + + onDidChangeContent({ document: { uri } }: TextChangeEvent) { + const diagnostics = this.validate(uri); + if (diagnostics) this.connection.sendDiagnostics({ uri, diagnostics }); + } + onDidClose({ document: { uri } }: TextChangeEvent) { this.connection.sendDiagnostics({ uri, diagnostics: [] }); }