feat(code): support gdscript (godot)

This commit is contained in:
Elian Doran 2025-05-11 11:18:19 +03:00
parent 55cf7e0c9b
commit 7cd4bce5b0
No known key found for this signature in database
5 changed files with 43 additions and 2 deletions

View File

@ -68,6 +68,7 @@ export const MIME_TYPES_DICT: readonly MimeTypeDefinition[] = Object.freeze([
{ title: "Forth", mime: "text/x-forth" },
{ title: "Fortran", mime: "text/x-fortran", highlightJs: "fortran" },
{ title: "Gas", mime: "text/x-gas" },
{ title: "GDScript (Godot)", mime: "text/x-gdscript" },
{ title: "Gherkin", mime: "text/x-feature", highlightJs: "gherkin" },
{ title: "GitHub Flavored Markdown", mime: "text/x-gfm", highlightJs: "markdown" },
{ title: "Go", mime: "text/x-go", highlightJs: "go", default: true },

View File

@ -68,6 +68,7 @@ export const MIME_TYPES_DICT: readonly MimeTypeDefinition[] = Object.freeze([
{ title: "Forth", mime: "text/x-forth" },
{ title: "Fortran", mime: "text/x-fortran", highlightJs: "fortran" },
{ title: "Gas", mime: "text/x-gas" },
{ title: "GDScript (Godot)", mime: "text/x-gdscript" },
{ title: "Gherkin", mime: "text/x-feature", highlightJs: "gherkin" },
{ title: "GitHub Flavored Markdown", mime: "text/x-gfm", highlightJs: "markdown" },
{ title: "Go", mime: "text/x-go", highlightJs: "go", default: true },

View File

@ -25,6 +25,7 @@
* Emojis.
* [Make it show which node triggered the event when right-clicking on tree](https://github.com/TriliumNext/Notes/pull/1861) by @SiriusXT
* [Only expand/collapse the left pane of the focused window](https://github.com/TriliumNext/Notes/pull/1905) by @SiriusXT
* Code notes now have support for GDScript (Godot).
## 📖 Documentation

View File

@ -0,0 +1,37 @@
/**
* @module
*
* Ported to CodeMirror 6 from https://github.com/RobTheFiveNine/obsidian-gdscript/blob/main/src/main.js
*/
import { simpleMode } from "@codemirror/legacy-modes/mode/simple-mode";
export const gdscript = simpleMode({
start: [
{ regex: /\b0x[0-9a-f]+\b/i, token: "number" },
{ regex: /\b-?\d+\b/, token: "number" },
{ regex: /#.+/, token: 'comment' },
{ regex: /\s*(@onready|@export)\b/, token: 'keyword' },
{ regex: /\b(?:and|as|assert|await|break|breakpoint|const|continue|elif|else|enum|for|if|in|is|master|mastersync|match|not|null|or|pass|preload|puppet|puppetsync|remote|remotesync|return|self|setget|static|tool|var|while|yield)\b/, token: 'keyword' },
{ regex: /[()\[\]{},]/, token: "meta" },
// The words following func, class_name and class should be highlighted as attributes,
// so push onto the definition stack
{ regex: /\b(func|class_name|class|extends|signal)\b/, token: "keyword", push: "definition" },
{ regex: /@?(?:("|')(?:(?!\1)[^\n\\]|\\[\s\S])*\1(?!"|')|"""(?:[^\\]|\\[\s\S])*?""")/, token: "string" },
{ regex: /\$[\w\/]+\b/, token: 'variable' },
{ regex: /\:[\s]*$/, token: 'operator' },
{ regex: /\:[ ]*/, token: 'meta', push: 'var_type' },
{ regex: /\->[ ]*/, token: 'operator', push: 'definition' },
{ regex: /\+|\*|-|\/|:=|>|<|\^|&|\||%|~|=/, token: "operator" },
{ regex: /\b(?:false|true)\b/, token: 'number' },
{ regex: /\b[A-Z][A-Z_\d]*\b/, token: 'operator' },
],
var_type: [
{ regex: /(\w+)/, token: 'attribute', pop: true },
],
definition: [
{ regex: /(\w+)/, token: "attribute", pop: true }
]
});

View File

@ -70,6 +70,7 @@ const byMimeType: Record<string, (() => Promise<StreamParser<unknown> | (() => L
"text/x-fortran": async () => (await import('@codemirror/legacy-modes/mode/fortran')).fortran,
"text/x-fsharp": async () => (await import('@codemirror/legacy-modes/mode/mllike')).fSharp,
"text/x-gas": async () => (await import('@codemirror/legacy-modes/mode/gas')).gas,
"text/x-gdscript": async () => (await import('./languages/gdscript.js')).gdscript,
"text/x-gfm": null,
"text/x-go": async () => (await import('@codemirror/legacy-modes/mode/go')).go,
"text/x-groovy": async () => (await import('@codemirror/legacy-modes/mode/groovy')).groovy,
@ -159,8 +160,8 @@ const byMimeType: Record<string, (() => Promise<StreamParser<unknown> | (() => L
"text/x-xu": async () => (await import('@codemirror/legacy-modes/mode/mscgen')).xu,
"text/x-yacas": async () => (await import('@codemirror/legacy-modes/mode/yacas')).yacas,
"text/x-yaml": async () => (await import('@codemirror/legacy-modes/mode/yaml')).yaml,
"text/x-z80": async () => (await import('@codemirror/legacy-modes/mode/z80')).z80
"text/xml": async () => (await import('@codemirror/legacy-modes/mode/xml')).xml,
"text/x-z80": async () => (await import('@codemirror/legacy-modes/mode/z80')).z80,
"text/xml": async () => (await import('@codemirror/legacy-modes/mode/xml')).xml
}
export default byMimeType;