rust-monaco icon indicating copy to clipboard operation
rust-monaco copied to clipboard

Allow setting `monaco.languages` / tokenizer?

Open max-sixty opened this issue 2 years ago • 8 comments

We're now using rust-monaco successfully at https://lang.prql.builders/editor.html — a live compiler in the browser — thank you very much @siku2 for enabling this.

Next we'd like to allow adding a tokenizer to the editor, so it can highlight a language it doesn't know about. There's an example here: https://microsoft.github.io/monaco-editor/playground.html#extending-language-services-custom-languages.

Is this possible with this library? I couldn't find any references to languages. If not, would you happen to have a vision of how I could do this? I'm happy to do another PR if it's not too difficult. My rust is much better than my JS...

Thank you again!

max-sixty avatar Apr 06 '22 14:04 max-sixty

I'm just as happy as you are. I spent a lot of time on this project but since I didn't have the time to move forward with the project that's using this library I never got to see it in action.

I'll take a look at the language service and see what I can do.

siku2 avatar Apr 06 '22 18:04 siku2

Just pushed an initial version of bindings for the monaco.languages namespace. I replaced a lot of complex types with JsValue to make it easier for me.

Please give it a shot and let me know how it goes.

siku2 avatar Apr 08 '22 19:04 siku2

Awesome, I'll have a go this weekend, thanks @siku2 !

max-sixty avatar Apr 08 '22 19:04 max-sixty

@siku2

Hello! I have been trying to add support for a custom language using your plugin, but I haven't been able to figure how the API works. In order to call register() I need to create a ILanguageExtensionPoint object, but I can't find any way to build one. Is this a limitation of the current API or am I missing something?

Bwallker avatar May 17 '22 13:05 Bwallker

@Bwallker, unfortunately, the bindings are anything but complete. All these little "helper" implementations are still missing for the language bindings because they can't be extracted from the .d.ts file(s). The missing constructor you're referring to is one of these.

You can see how it works for other types here:

https://github.com/siku2/rust-monaco/blob/dfe34f8ebb1fb0bc443815c88b2560f1a93f22b5/src/sys/editor.rs#L18-L26

Basically, you just create an empty js object and cast it to the desired type and then you use the setters to populate it.

If you end up creating constructors for the types you're using, please consider contributing them back to the library.

siku2 avatar May 17 '22 21:05 siku2

@siku2 Thank you so much for the swift reply! I will look into your suggestions

Bwallker avatar May 17 '22 22:05 Bwallker

FWIW, here's one example of doing this: https://github.com/abesto/clox-rs/blob/def4bed61a1c1c6b5d84a67284549a6343c8cd06/web/src/monaco_lox.rs

Maybe it'll be useful for the next person coming along!

abesto avatar Dec 10 '22 21:12 abesto

@abesto @siku2 I'm at the process of creating a custom language that is based heavily on Monaco's MIPS language(the main difference is that our version of the MIPS language has 64-bit instructions), and I was wondering how could I port over the Language Configuration and my MonarchTokensProvider to Rust? Whenever I attempted to register my custom language into the app, the app will not load with a error pertaining to my js file that contains the tokens.

b0x-Cub3d avatar Feb 08 '23 14:02 b0x-Cub3d