Skip to content

Commit 0682ed3

Browse files
authored
Rpaul markdoc 030 (#6)
* Updates to Markdoc 0.3.0 and enables support for slots * Make the formatter respect tokenizer settings
1 parent f7b9a5f commit 0682ed3

File tree

9 files changed

+19
-16
lines changed

9 files changed

+19
-16
lines changed

client/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"description": "Markdoc Extension",
44
"author": "Ryan Paul",
55
"license": "MIT",
6-
"version": "0.0.4",
6+
"version": "0.0.5",
77
"scripts": {
88
"build": "esbuild index.ts --bundle --outdir=dist --sourcemap=linked --external:vscode --platform=node --format=cjs",
99
"build:server": "esbuild server.ts --bundle --outdir=dist --sourcemap=linked --external:vscode --platform=node --format=cjs"

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"author": "Ryan Paul",
88
"publisher": "stripe",
99
"license": "MIT",
10-
"version": "0.0.4",
10+
"version": "0.0.5",
1111
"description": "A Markdoc language server and Visual Studio Code extension",
1212
"repository": {
1313
"type": "git",

server/package-lock.json

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

server/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
{
22
"name": "@markdoc/language-server",
3-
"version": "0.0.4",
3+
"version": "0.0.5",
44
"description": "A Markdoc language server",
55
"main": "dist/index.js",
66
"author": "Ryan Paul",
77
"license": "MIT",
88
"devDependencies": {
9-
"@markdoc/markdoc": "^0.2.1",
9+
"@markdoc/markdoc": "^0.3.0",
1010
"@types/picomatch": "^2.3.0",
1111
"picomatch": "^2.3.1",
1212
"typescript": "^5.0.4",

server/plugins/completion.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ export default class CompletionProvider {
9393
insertText: item.data.block ? text : text.replaceAll("\n", ""),
9494
insertTextFormat: LSP.InsertTextFormat.Snippet,
9595
kind: LSP.CompletionItemKind.Function,
96-
// @ts-expect-error
9796
documentation: config.description ?? "",
9897
};
9998
},

server/plugins/formatting.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ const example1 = `
1313
const example1Formatted = `
1414
# This is a test {% #foo %}
1515
16-
- This is an example [foo](/bar)
16+
* This is an example [foo](/bar)
1717
`;
1818

1919
const example1LastLine = `
20-
- This is an example [foo](/bar)
20+
* This is an example [foo](/bar)
2121
`;
2222

2323
const mockConnection = {

server/plugins/formatting.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,14 @@ import type { Config, ServiceInstances } from "../types";
55
import { TextDocument } from "vscode-languageserver-textdocument";
66

77
export default class FormattingProvider {
8+
protected tokenizer: Markdoc.Tokenizer;
9+
810
constructor(
911
protected config: Config,
1012
protected connection: LSP.Connection,
1113
protected services: ServiceInstances
1214
) {
15+
this.tokenizer = new Markdoc.Tokenizer(config.markdoc ?? {});
1316
connection.onDocumentFormatting(this.onDocumentFormatting.bind(this));
1417
connection.onDocumentRangeFormatting(this.onRangeFormatting.bind(this));
1518
}
@@ -30,7 +33,8 @@ export default class FormattingProvider {
3033
: LSP.Range.create(0, 0, doc.lineCount, 0);
3134

3235
const text = doc.getText(actualRange);
33-
const ast = Markdoc.parse(text);
36+
const tokens = this.tokenizer.tokenize(text);
37+
const ast = Markdoc.parse(tokens, { slots: this.config.markdoc?.slots });
3438
const output = Markdoc.format(ast);
3539

3640
return [LSP.TextEdit.replace(actualRange, output)];

server/services/documents.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export default class Documents<
2727

2828
parse(content: string, file: string) {
2929
const tokens = this.tokenizer.tokenize(content);
30-
return Markdoc.parse(tokens, file);
30+
return Markdoc.parse(tokens, { file, slots: this.config.markdoc?.slots });
3131
}
3232

3333
protected handleClose({ document }: TextChangeEvent) {

server/services/scanner.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export default class Scanner<
7575

7676
parse(content: string, file: string) {
7777
const tokens = this.tokenizer.tokenize(content);
78-
return Markdoc.parse(tokens, file);
78+
return Markdoc.parse(tokens, { file, slots: this.config.markdoc?.slots });
7979
}
8080

8181
async scan() {

0 commit comments

Comments
 (0)