How to Add C# Library to Monaco Editor (code completion) and limit possible libraries?
Asked Answered
S

1

9

How can I add my custom C# assemblies to Monaco Editor, so the editor would recognize/complete my assembly types?

And how could I choose and limit the .net libraries that Monaco Editor can use?

Thanks in advance.

Sociolinguistics answered 21/10, 2018 at 1:58 Comment(1)
Hello, did you solve this? Currently I am solving same problem.Accrue
A
8

No simple way. .Net is a framework that could not be easily analyzed with JS, especially if you need to read all types in binary dependencies (dlls).

So you will also need some sort of a backend engine (probably WebApi). Loading a project in Monaco could ask the Backend to read all exported types from the binary references (see Reflection) and send them to the frontend.

If you expect those things to change real time (someone creates a new class, for example), you may get into significantly more complex scenario where you will need to have both - the code in Monaco Editor and the project in the backend constantly synced (see Roslyn).

If you only need to support read + types, you can do something like:

  1. You use the https://microsoft.github.io/monaco-editor/playground.html#extending-language-services-completion-provider-example to register completion provider.
  2. You also load the project in the backend and read all references with C#.
  3. In provideCompletionItems - you get the caret position
  4. You send the file and the coordinates to the backend.
  5. The backend reads the symbol at that position, infers its type (probably with Roslyn)
  6. Tracks down and reflects the type using reflection.
  7. Sends back the members of this type.

If your Monaco editor IS NOT read only - you are also expected to sync the backend and frontend, so positions always match.

Assistance answered 12/7, 2020 at 3:1 Comment(1)
That's not correct, you can run c# in browser - backend is not required.Carducci

© 2022 - 2024 — McMap. All rights reserved.