-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: bundle grammars from shiki (#29)
- Loading branch information
Showing
14 changed files
with
98 additions
and
32,739 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { wireTmGrammars } from "monaco-editor-textmate"; | ||
import { Registry, type IGrammarDefinition } from "monaco-textmate"; | ||
|
||
async function dispatchGrammars( | ||
scopeName: string | ||
): Promise<IGrammarDefinition> { | ||
switch (scopeName) { | ||
case "source.vue": | ||
return { | ||
format: "json", | ||
content: await import("shiki/languages/vue.tmLanguage.json"), | ||
}; | ||
case "source.ts": | ||
return { | ||
format: "json", | ||
content: await import("shiki/languages/typescript.tmLanguage.json"), | ||
}; | ||
case "source.js": | ||
return { | ||
format: "json", | ||
content: await import("shiki/languages/javascript.tmLanguage.json"), | ||
}; | ||
case "text.html.basic": | ||
return { | ||
format: "json", | ||
content: await import("shiki/languages/html.tmLanguage.json"), | ||
}; | ||
case "source.css": | ||
return { | ||
format: "json", | ||
content: await import("shiki/languages/css.tmLanguage.json"), | ||
}; | ||
default: | ||
return { | ||
format: "json", | ||
content: { | ||
scopeName: "source", | ||
patterns: [], | ||
}, | ||
}; | ||
} | ||
} | ||
|
||
export async function loadGrammars( | ||
monaco: typeof import("monaco-editor-core"), | ||
editor: import("monaco-editor-core").editor.IStandaloneCodeEditor | ||
) { | ||
const registry = new Registry({ | ||
getGrammarDefinition: async (scopeName) => { | ||
const dispatch = await dispatchGrammars(scopeName); | ||
return JSON.parse(JSON.stringify(dispatch)); | ||
}, | ||
}); | ||
const grammars = new Map(); | ||
grammars.set("vue", "source.vue"); | ||
grammars.set("javascript", "source.js"); | ||
grammars.set("typescript", "source.ts"); | ||
grammars.set("css", "source.css"); | ||
grammars.set("html", "text.html.basic"); | ||
|
||
for (const lang of grammars.keys()) { | ||
monaco.languages.register({ | ||
id: lang, | ||
}); | ||
} | ||
|
||
await wireTmGrammars(monaco as any, registry, grammars, editor as any); | ||
} |
Oops, something went wrong.