开发工具桌面应用【免费下载链接】massCodeA free, open-source developer workspace. Snippets, notes, HTTP requests, calculations, and dev tools in one local-first app.项目地址https://gitcode.com/gh_mirrors/ma/massCode点击查看免费下载massCode 是一款本地优先的开源开发者工作台其内置代码编辑器基于 CodeMirror TextMate 语法体系构建官方在 src/renderer/components/editor/README.md 中维护了一份完整的“支持语言清单”共列出 162 种语言。本文以这份清单为骨架结合仓库源码逐层剖析每种语言在languages.ts中如何声明显示名、mode 标识、TextMate scope、语法文件四要素、loadGrammars()如何在启动时通过 onigasm WASM 将语法注册进编辑器、语言选择在界面中如何切换与持久化以及如何基于现有结构为 massCode 扩展新的语言。读完本文你既能完整掌握这 162 种语言与内部标识的对照关系也能理解整套语法加载链路的底层原理。一、语言清单是什么一份 162 种语法的官方索引src/renderer/components/editor/README.md是编辑器子模块的说明文档其正文只有一段引言——“This is a list of language that supports in massCode”随后按字母顺序列出全部支持的语言名称。从 ABAP 到 Zeek共计162 个条目覆盖了主流通用语言C/C、C#、Java、JavaScript/TypeScript、Go、Rust、Python、Ruby、PHP、Swift、Kotlin、Dart、Scala 等Web 前端与样式HTML、CSS、JSX/TSX、Vue、SCSS/SASS/LESS/Stylus 等数据与配置格式JSON/JSON5、YAML、TOML、INI、Properties、Protobuf、Hjson、Nix、Prisma、Gitignore 等数据库与查询SQL、SQLServer、MySQL、pgSQL、GraphQL、Kusto (KQL)、XQuery 等模板引擎EJS、HAML、Handlebars、Pug、Slim、Twig、Liquid、Nunjucks、Soy Template、PHP (Blade Template) 等文档与标记Markdown、AsciiDoc、LaTeX、Tex、Textile、MediaWiki、RST、Diff、Dot 等运维与云Bash、Powershell、BatchFile、Dockerfile、Makefile、Nginx、Apache Conf、Terraform、Puppet、NSIS、Mikrotik 等科学计算与领域语言MATLAB、SAS、R、Julia、Glsl、OpenGL、Gcode、SCAD、MEL、Praat、Csound 系列、LSL、Apex、Drools、Gherkin、Pig、Zeek 等。这份清单不是一份“宣传名录”而是与编辑器实现一一对应的可执行配置索引——清单中的每个名字都能在 languages.ts 的languages数组中找到对应的LanguageOption条目并绑定一个实际的 TextMate 语法文件见下文第三、四节。二、完整语言清单与内部标识对照表清单中的“语言显示名”只是给人看的编辑器内部真正使用的是三类标识其定义见 LanguageOption 接口字段含义示例name下拉框与文档中展示的语言显示名Bashvalue该语言的内部标识作为 CodeMirror 的mode值存储进 snippet 数据shscopeName该语言对应的 TextMate 语法作用域scope是语法匹配的根锚点source.shellgrammar懒加载的*.tmLanguage.json语法文件加载函数() import(./grammars/shell-unix-bash.tmLanguage.json)其中value的取值范围由 Language 联合类型 约束如abap、sh、c_cpp保证类型安全。下面按字母区间给出全部 162 种语言的name → value → scopeName完整对照数据以 languages.ts 为准。A–E语言namevaluescopeNameABAPabapsource.abapABCabctext.abcnotationActionScriptactionscriptsource.actionscript.3ADAadasource.adaAldaaldasource.aldaApache Confapache_confsource.apacheconfApexapexsource.apexApple Scriptapplescriptsource.applescriptAsciiDocasciidoctext.asciidocASLaslsource.aslASP vb.NET (VBScript)asp_vb_netsource.asp.vb.netAssembly x86assembly_x86source.asmAutoHotkey / AutoItautohotkeysource.ahkBashshsource.shellBatchFilebatchfilesource.batchfileBicepbicepsource.bicepC and Cc_cppsource.cppC#csharpsource.csCirrucirrusource.cirruClojureclojuresource.clojureCobolcobolsource.cobolCoffeeScriptcoffeesource.coffeeColdFusioncoldfusiontext.cfml.basicCrystalcrystalsource.crystalCsoundcsound_orchestrasource.csoundCsound Documentcsound_documentsource.csound-documentCsound Scorecsound_scoresource.csound-scoreCSScsssource.cssCurlycurlytext.html.curlyDdsource.dDartdartsource.dartDiffdiffsource.diffDjangodjangosource.python.djangoDockerfiledockerfilesource.dockerfileDotdotsource.dotDroolsdroolssource.droolsEdifactedifacttext.plain.edifactEiffeleiffelsource.eiffelEJSejstext.html.jsElixirelixirsource.elixirElmelmsource.elmErlangerlangsource.erlangF–K语言namevaluescopeNameForthforthsource.forthFortranfortransource.fortranF#fsharpsource.fsharpGcodegcodesource.gcodeGherkingherkintext.gherkin.featureGitignoregitignoresource.gitignoreGlslglslsource.glslGogolangsource.goGraphQLgraphqlschemasource.graphqlGroovygroovysource.groovyHAMLhamltext.hamlHandlebarshandlebarstext.html.handlebarsHaskell Cabalhaskell_cabalsource.cabalHaskellhaskellsource.haskellhaXehaxesource.hxHjsonhjsonsource.hjsonHTML (Elixir)html_elixirtext.html.elixirHTML (Ruby)html_rubytext.html.erbHTMLhtmltext.html.basicINIinisource.iniIoiosource.ioJavajavasource.javaJavaScriptjavascriptsource.jsJSONjsonsource.jsonJSON5json5source.json5JSONiqjsoniqsource.jsoniqJSPjsptext.html.jspJSXjsxsource.jsxJuliajuliasource.juliaKotlinkotlinsource.kotlinKusto (KQL)kustosource.kustoL–R语言namevaluescopeNameLaTeXlatextext.tex.latexLattelattesource.latteLESSlesssource.css.lessLiquidliquidsource.liquidLisplispsource.lispLiveScriptlivescriptsource.livescriptLSLlslsource.lslLualuasource.luaMakefilemakefilesource.makefileMarkdownmarkdowntext.html.markdownMaskmasksource.maskMATLABmatlabsource.matlabMediaWikimediawikitext.html.mediawikiMELmelsource.melMikrotikmikrotiksource.mikrotik-scriptMIPSmipssource.mipsMySQLmysqlsource.sql.mysqlNginxnginxsource.nginxNimnimsource.nimNixnixsource.nixNSISnsissource.nsisNunjucksnunjuckstext.html.nunjucksObjective-Cobjectivecsource.objcOCamlocamlsource.ocamlOpenGLglslsource.glslPascalpascalsource.pascalPerlperlsource.perlpgSQLpgsqlsource.pgsqlPHP (Blade Template)php_laravel_bladetext.html.php.bladePHPphpsource.phpPigpigsource.pigPlain Textplain_texttext.plainPowershellpowershellsource.powershellPraatpraatsource.praatPrismaprismasource.prismaPrologprologsource.prologPropertiespropertiessource.tm-propertiesProtobufprotobufsource.protoPugpugtext.pugPuppetpuppetsource.puppetPythonpythonsource.pythonQMLqmlsource.qmlRrsource.rRakurakusource.perl.6Razorrazortext.aspnetcorerazorRedredsource.redRegExpregexpsource.regexpRSTrstsource.rstRubyrubysource.rubyRustrustsource.rustS–Z语言namevaluescopeNameSASsassource.sasSASSsasssource.sassSCADscadsource.scadScalascalasource.scalaSchemeschemesource.schemesCryptscryptsource.scryptSCSSscsssource.css.scssSJSsjssource.sjsSlimslimtext.slimSmalltalksmalltalksource.smalltalkSmartysmartysource.smartySmithysmithysource.smithySoliditysoliditysource.soliditySoy Templatesoy_templatesource.soySQLsqlsource.sqlSQLServersqlserversource.sqlserverStylusstylussource.stylusSVGsvgtext.xml.svgSwiftswiftsource.swiftTcltclsource.tclTerraformterraformsource.terraformTextextext.texTextiletextiletext.html.textileTOMLtomlsource.tomlTSXtsxsource.tsxTwigtwigtext.html.twigTypeScripttypescriptsource.tsValavalasource.valaVelocityvelocitytext.velocityVerilogverilogsource.systemverilogVHDLvhdlsource.vhdlVisualforcevisualforcetext.visualforce.markupVuevuetext.html.vueWollokwolloksource.wollokXMLxmltext.xmlXSLxsltext.xml.xslXQueryxquerysource.xqueryYAMLyamlsource.yamlZeekzeeksource.zeek从上表可以观察到几类值得留意的细节共享语法文件Glsl与OpenGL的value同为glsl都指向glsl.tmLanguage.jsonSQL与SQLServer虽value不同sql/sqlserver但grammar都指向sql.tmLanguage.jsonStylus则复用了less.tmLanguage.json。语法文件与语言名不完全同名Verilog实际加载的是systemverilog.tmLanguage.jsonMakefile加载的是make.tmLanguage.jsonMarkdown加载的是markdown.tmLanguage.json注意区分grammars/markdown.tmLanguage.json与辅助语法grammars-aux.ts中的source.md。这一层“显示名 → mode → scope → 文件”的间接映射正是语言系统的设计核心。三、语法注册链路loadGrammars()与 onigasm WASM清单中的每一项最终都要变成编辑器里可用的高亮语法这一过程由 grammars.ts 的loadGrammars()完成export const loadGrammars async () { const grammars: Recordstring, GrammarOption {} languages .filter(i i.grammar) .forEach(async i { if (!i.scopeName || !i.grammar) return grammars[i.scopeName] { grammar: i.grammar, language: i.value, priority: defer } }) auxGrammars.forEach(i { grammars[i.source] { grammar: i.grammar, language: i.language as Language, priority: defer } }) await Promise.all( Object.keys(grammars).map(async scopeName { const { grammar, language, priority } grammars[scopeName] const { default: grammarDoc } await grammar() try { addGrammar(scopeName, grammarDoc) if (language) { const prom activateLanguage(scopeName, language, priority) if (priority now) await prom } } catch (err) { console.error(err) } }) ) }其执行逻辑可拆解为四步收集语法遍历languages数组将每个条目按scopeName作为键、{ grammar, language, priority: defer }作为值放入grammars注册表。priority: defer表示延迟激活避免应用启动时同步等待全部语法解析完成。并入辅助语法再将auxGrammars见 grammars-aux.ts共 40 个条目并入同一注册表。辅助语法解决的是嵌入场景——例如source.scss、source.css.nunjucks、source.c、source.x86、text.git-commit、text.jade等 scope它们可能是主语言的子作用域或旧标识的兜底。并行加载Promise.all逐个await grammar()动态导入对应的*.tmLanguage.json。注册与激活调用codemirror-textmate的addGrammar(scopeName, grammarDoc)注册语法再以activateLanguage(scopeName, language, priority)将 TextMate 语法激活到对应mode即该语言的value。这条链路的上游在应用入口 App.vue 中触发loadWASM(onigasmFile)先加载 onigasm 的正则引擎 WASMonigasm 是 TextMate 语法正则匹配的运行时基础随后await loadGrammars()完成全部语法的注册。也就是说这 162 种语言的高亮能力在应用启动阶段就已就绪后续编辑时只需按mode切换。3.1 辅助语法主清单之外的嵌入语法grammars-aux.ts 中的条目不直接对应 README 清单而是为组合语言与边界场景提供支持典型如source.sassdoc→sassdocSass 文档注释source.js.jquery→jquery复用javascript.tmLanguage.json的 jQuery 作用域source.c/source.c/source.cpp.embedded.macroC/C 及其嵌入宏source.x86/source.x86_64汇编的分架构作用域source.json.comments→json-comment带注释的 JSONJSONCsource.regexp.javascript/python/posix/extended多套正则方言text.bibtex、source.gnuplot、source.asymptote、source.arm、text.log、text.git-rebase、text.git-commit、text.html.javadoc、source.postscript等。这些条目证明语言清单只是“顶层入口”真正的语法世界是分层作用域组成的——一个source.css.scss可以嵌套在text.html中这正是 TextMate 语法体系相对传统 CodeMirror mode 的优势。四、语言在界面中如何切换与持久化4.1 编辑器底栏的下拉选择器语言选择入口位于编辑器组件的底部状态栏。在 EditorCodemirror.vue 中select classlang-selector直接遍历languages数组渲染全部 162 个选项select v-modellocalLang classlang-selector option v-fori in languages :keyi.value :valuei.value {{ i.name }} /option /selectlocalLang是双向绑定计算属性get返回当前 snippet 的语言set触发update:lang事件切换后通过editor.setOption(mode, lang)setLang即时更换编辑器 mode。与此同时底栏还实时显示光标行列位置line / column方便定位。4.2 语言值的持久化与埋点语言变更的落库逻辑在 SnippetsView.vueconst lang computed({ get: () snippetStore.currentLanguage || plain_text, set: v { snippetStore.patchCurrentSnippetContentByKey(language, v) track(snippets/set-language, v) } })即语言标识以language键写入当前 snippet 的内容数据patchCurrentSnippetContentByKey并通过track(snippets/set-language, v)记录到分析埋点默认值为plain_text。这意味着每个 snippet 的语言选择是独立持久化的重新打开应用后仍保持上次设置。4.3 语言与预览、截图功能的联动在 SnippetsView.vue 中lang还被透传给多个视图组件EditorCodemirror编辑、EditorPreview代码预览、TheScreenshot截图导出等。也就是说语言标识不只为高亮服务还参与渲染预览、生成带语法样式的截图等下游功能是 snippet 内容模型中的一等公民。五、版本迁移v1 旧语言标识映射massCode 从 v1 升级到当前版本时部分语言的内部标识发生了变化因此 languages.ts 末尾定义了oldLanguageMap用于新旧标识的桥接export const oldLanguageMap: Recordany, Language { azcli: plain_text, bat: sh, cameligo: plain_text, coffeescript: coffee, c: c_cpp, csp: plain_text, go: golang, graphql: graphqlschema, msdax: plain_text, objective-c: objectivec, pascaligo: plain_text, postiats: plain_text, powerquery: plain_text, pug: jade, redis: plain_text, sb: plain_text, shell: sh, sol: plain_text, aes: plain_text, st: plain_text, vb: vbscript }该映射把 v1 时代的旧值如bat、shell、coffeescript、c、go、graphql、objective-c归一化到当前版本的语言标识如sh、coffee、c_cpp、golang、graphqlschema、objectivec其中部分语言在当前版本中已不再作为独立条目提供高亮如cameligo、redis、sol统一回退为plain_textpug → jade则与辅助语法中text.jade复用pug.tmLanguage.json相互印证。这套映射保证了老用户数据在升级后仍能正确解析语言字段。六、语言与格式化Prettier的配合语言标识还决定“格式化代码”功能是否可用。在 EditorCodemirror.vue 的format()中维护了一个 22 种语言的availableLang白名单const availableLang: Language[] [ css, dockerfile, gitignore, graphqlschema, html, ini, jade, java, javascript, json, json5, less, markdown, php, properties, sass, scss, sh, toml, typescript, xml, yaml ]只有当 snippet 的value命中白名单时格式化才被触发且解析器会做一次映射javascript→babelBabel 解析器graphqlschema→graphqldockerfile/gitignore/properties/ini→shshell 风格解析器。格式化请求通过 IPCmain:prettier转发给主进程的 prettier 服务 执行成功后回写内容并埋点snippets/format。这说明语言清单不只是高亮开关也是格式化、预览等编辑能力的路由表。七、如何为 massCode 扩展一种新语言结合源码结构非官方文档声明属实现层面推断新增语言通常只需三步放置语法文件将语言对应的 TextMate 语法 JSON*.tmLanguage.json放入 src/renderer/components/editor/grammars 目录当前该目录已收录 195 个语法文件包含清单 162 项及其变体。声明条目在 languages.ts 的languages数组末尾追加一个LanguageOption对象四要素缺一不可name显示名、value唯一 mode 标识需同步补充到 Language 联合类型、grammar() import(./grammars/xxx.tmLanguage.json)懒加载函数、scopeName语法文件的根 scope。按需补充辅助语法若新语言存在嵌入子作用域可在 grammars-aux.ts 中追加对应条目。由于loadGrammars()在启动时统一遍历languages注册新条目会自动出现在编辑器底栏的下拉框中无需改动任何 UI 代码。同理删除清单条目即可在语言列表中移除对应语言。八、边界情况与注意事项同名异值Glsl与OpenGL共用glslmode切换其中任何一个另一个的代码高亮行为一致——这是从源码中value相同这一事实推断出的行为。语法复用Stylus复用less.tmLanguage.json、Verilog加载systemverilog.tmLanguage.json、Makefile加载make.tmLanguage.json等意味着这些语言的高亮规则继承自其源语法主题色表现可能不完全等同于专用语法。待校对注释languages.ts 与Haskell Cabal条目旁保留了俄语注释// Возможно несоответствие意为“可能存在不匹配”说明ABCscopetext.abcnotation与Haskell Cabalscopesource.cabal两条语法的 scope 声明在仓库中仍标记为待校验项。主题配合语法着色最终还要与主题配合呈现themes 目录 内置 12 个*.tmTheme.jsonDracula、Monokai、One Dark、Tokyo Night 等由 themes.ts 注册到codemirror-textmate。语言 × 主题共同决定最终渲染效果。结语src/renderer/components/editor/README.md这份看似只有语言列表的文档实际上是整个编辑器语法体系的索引入口162 个名字背后是languages.ts的声明、195 个tmLanguage.json语法文件、loadGrammars() onigasm WASM 的注册链路、codemirror-textmate的作用域激活以及语言标识在持久化、格式化和预览中的复用。理解这张对照表与加载链路不仅能帮你快速定位任意语言在 massCode 中的内部标识也为自定义扩展语言提供了清晰的路径。赞分享开发工具桌面应用【免费下载链接】massCodeA free, open-source developer workspace. Snippets, notes, HTTP requests, calculations, and dev tools in one local-first app.项目地址https://gitcode.com/gh_mirrors/ma/massCode点击查看免费下载相关推荐突破语言壁垒为Kilo编辑器扩展多语言语法高亮支持突破语言壁垒为Kilo编辑器扩展多语言语法高亮支持 你是否曾因Kilo编辑器仅支持C/C语法高亮而感到受限作为一款精简到极致的开源文本编辑器不到100代码编辑器CLITabby 终端完整上手指南如何用一款跨平台终端搞定本地 Shell、SSH 与串口调试Tabby 终端完整上手指南如何用一款跨平台终端搞定本地 Shell、SSH 与串口调试 Tabby原名 Terminus是一款面向现代开发者的跨平台终端桌面应用网络通信Cangjie-TPC/editor4cj语言支持扩展教程添加新编程语言Cangjie TPC/editor4cj语言支持扩展教程添加新编程语言 还在为编辑器不支持你心爱的编程语言而烦恼想要为开源编辑器贡献自己的力量却不知从何下OpenHarmonyUI组件代码编辑器前端创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考
阅读完成 · 觉得有帮助?