better formatting
This commit is contained in:
parent
24d577b20b
commit
a4e25b5f3b
2 changed files with 26 additions and 9 deletions
22
index.ts
22
index.ts
|
|
@ -1,18 +1,32 @@
|
||||||
import type { Plugin, Parser } from "prettier";
|
import type { Plugin, Parser } from "prettier";
|
||||||
import { formatSource, type FormatLanguage } from "muddle/formatter";
|
import { formatSource, type FormatLanguage } from "muddle/formatter";
|
||||||
|
|
||||||
interface Document { formatted: string }
|
interface Document {
|
||||||
|
formatted: string;
|
||||||
|
}
|
||||||
const parser = (language: FormatLanguage): Parser<Document> => ({
|
const parser = (language: FormatLanguage): Parser<Document> => ({
|
||||||
astFormat: "muddle-document",
|
astFormat: "muddle-document",
|
||||||
async parse(source, options) { return { formatted: await formatSource(source, language, options) }; },
|
async parse(source, options) {
|
||||||
|
return { formatted: await formatSource(source, language, options) };
|
||||||
|
},
|
||||||
locStart: () => 0,
|
locStart: () => 0,
|
||||||
locEnd: (node) => node.formatted.length,
|
locEnd: (node) => node.formatted.length,
|
||||||
});
|
});
|
||||||
|
|
||||||
const plugin: Plugin<Document> = {
|
const plugin: Plugin<Document> = {
|
||||||
languages: [
|
languages: [
|
||||||
{ name: "SPUG", parsers: ["spug"], extensions: [".spug", ".stpug", ".stug"], vscodeLanguageIds: ["spug"] },
|
{
|
||||||
{ name: "STCSS", parsers: ["stcss"], extensions: [".stcss"], vscodeLanguageIds: ["stcss"] },
|
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") },
|
parsers: { spug: parser("spug"), stcss: parser("stcss") },
|
||||||
printers: { "muddle-document": { print: (path) => path.node.formatted } },
|
printers: { "muddle-document": { print: (path) => path.node.formatted } },
|
||||||
|
|
|
||||||
|
|
@ -3,5 +3,8 @@
|
||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"exports": "./index.ts",
|
"exports": "./index.ts",
|
||||||
"peerDependencies": { "muddle": "*", "prettier": "^3.0.0" }
|
"peerDependencies": {
|
||||||
|
"muddle": "*",
|
||||||
|
"prettier": "^3.0.0"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue