2024-07-30 23:33:33 +08:00
|
|
|
import { type Diagnostic, linter } from "@codemirror/lint";
|
2023-11-21 23:24:20 +08:00
|
|
|
import type { Client } from "../client.ts";
|
2024-02-09 04:00:45 +08:00
|
|
|
import { parse } from "$common/markdown_parser/parse_tree.ts";
|
2024-07-30 23:33:33 +08:00
|
|
|
import type { LintEvent } from "../../plug-api/types.ts";
|
2024-02-09 04:00:45 +08:00
|
|
|
import { extendedMarkdownLanguage } from "$common/markdown_parser/parser.ts";
|
2023-11-21 23:24:20 +08:00
|
|
|
|
|
|
|
export function plugLinter(client: Client) {
|
2023-11-21 23:56:21 +08:00
|
|
|
return linter(async (view): Promise<Diagnostic[]> => {
|
|
|
|
const tree = parse(
|
2024-01-24 20:34:12 +08:00
|
|
|
extendedMarkdownLanguage,
|
2023-11-21 23:56:21 +08:00
|
|
|
view.state.sliceDoc(),
|
|
|
|
);
|
2023-11-21 23:24:20 +08:00
|
|
|
const results = (await client.dispatchAppEvent("editor:lint", {
|
2024-01-24 21:44:39 +08:00
|
|
|
name: client.currentPage,
|
2023-11-21 23:56:21 +08:00
|
|
|
tree: tree,
|
|
|
|
} as LintEvent)).flat();
|
2023-11-21 23:24:20 +08:00
|
|
|
return results;
|
|
|
|
});
|
|
|
|
}
|