35 lines
939 B
TypeScript
35 lines
939 B
TypeScript
import type { Plugin, Parser } from "prettier";
|
|
import { formatSource, type FormatLanguage } from "muddle/formatter";
|
|
|
|
interface Document {
|
|
formatted: string;
|
|
}
|
|
const parser = (language: FormatLanguage): Parser<Document> => ({
|
|
astFormat: "muddle-document",
|
|
async parse(source, options) {
|
|
return { formatted: await formatSource(source, language, options) };
|
|
},
|
|
locStart: () => 0,
|
|
locEnd: (node) => node.formatted.length,
|
|
});
|
|
|
|
const plugin: Plugin<Document> = {
|
|
languages: [
|
|
{
|
|
name: "SPUG",
|
|
parsers: ["spug"],
|
|
extensions: [".spug", ".stpug", ".stug"],
|
|
vscodeLanguageIds: ["spug"],
|
|
},
|
|
{
|
|
name: "STCSS",
|
|
parsers: ["stcss"],
|
|
extensions: [".stcss"],
|
|
vscodeLanguageIds: ["stcss"],
|
|
},
|
|
],
|
|
parsers: { spug: parser("spug"), stcss: parser("stcss") },
|
|
printers: { "muddle-document": { print: (path) => path.node.formatted } },
|
|
};
|
|
export default plugin;
|
|
export const { languages, parsers, printers } = plugin;
|