Access Monaco Editor


I wrote a pretty complex Eclipse RCP e4 Application and am now trying to use Theia for the frontend implementation. To get started, I would like to access the text from monaco and pass it to my Java parser via REST. My first approach was to create a menu entry with a command handler to get the text. But I have some problems to get the text from the editor. I added monaco to the package.json of the extension

“dependencies”: { “@theia/monaco”: “latest” }

added an import statement

import * as meditor from ‘@theia/monaco/lib/browser/monaco-editor-service’;

and added a simple null check in the handler

execute: () => { if( meditor != null){‘Its there’); } });

But yarn outputs a lot of errors like

`…/node_modules/@theia/filesystem/lib/browser/file-tree/file-tree-model.d.ts:49:45 - error TS2304: Cannot find name ‘WebKitEntry’.

49 protected uploadEntry(base: URI, entry: WebKitEntry | null): void;`

Therefore, I tried to add all the dependencies which are listed in package.json from the monaco package to resolve the missing dependencies but it did not help. However, it seems to me that it should not be necessary to have so many dependencies in my extension just to access the text from the text editor. So I guess I am doing something wrong.

Hopefully, somebody can help me. Thank you in advance.

[original thread by No Bbi]

To get around the issue of having errors in declaration files you can add the following to your extensions tsconfig.json

skipLibCheck: true

let me know if the issue persists :slight_smile:

[No Bbi]

Thank you for the hint. That did help a lot. Injecting MonacoEditorService as well as MonacoEditorProvider does work now. But unfortunately, I dont see how I can access the MonacoEditorModel from these services, which seems to have the getText() method. Are the services the right way to get there at all?

[No Bbi]

Solution is

@inject(MonacoWorkspace) private readonly monacoWS: MonacoWorkspace



Thanks for helping