silverbulletmd / silverbullet

The hackable notebook
https://silverbullet.md
MIT License
2.01k stars 138 forks source link

Feature Request: Erlang/Elexir langauge mode for syntax highlighting #875

Closed MrMugame closed 3 weeks ago

MrMugame commented 4 weeks ago

Basically title.

Erlang

There is a language mode for elexir in the legacy package, so that would just be

import { erlang as erlangLanguage } from "@codemirror/legacy-modes/mode/erlang?external=@codemirror/language&target=es2022";
...
"erlang": StreamLanguage.define(erlangLanguage),

in common/language.ts

Elixir

So this is a little harder, there is a package for elixir, but it is a separate ... package. It just exports elixirLanguage so using it would be easy too.

MrMugame commented 3 weeks ago

Just did some testing and adding the elixir package increases the bundle size from 2056KiB to 2200KiB and the erlang package only then increases the bundle size to 2208KiB. In my opinion a +7% in bundle size for one language mode is a little insane. Erlang is no problem, but IDK what your opinion is on elixir. An alternative would be to load the language modes using dynamic import()s or to switch to more lightweight libraries like highlight.js

For reference: I measured the client.js file and imported the packages like this

"lezer-elixir": "https://esm.sh/lezer-elixir@1.1.1?external=@lezer/highlight,@lezer/lr&target=es2022",
"codemirror-lang-elixir": "https://esm.sh/codemirror-lang-elixir@4.0.0?external=@codemirror/language,@codemirror/view,@codemirror/state,lezer-elixir&target=es2022",
zefhemel commented 3 weeks ago

I'd indeed go for only Erlang in that case. If there's a huge demand for elixir perhaps adding dynamic loading could be a solution, but likely we'd want to do that for many more languages then. Many supported are kind of niche.

MrMugame commented 3 weeks ago

Another Idea would be to completely separate the syntax highlighting into plugs. This way there could be one builtin plug with the most basic stuff and everything else is opt-in.

zefhemel commented 3 weeks ago

Yes, but this would also require extending the capability of plugs significantly. They cannot extend the parser now.