vscode icon indicating copy to clipboard operation
vscode copied to clipboard

Using the Monaco Editor in a browser without VSCode

Open Sevin777 opened this issue 11 years ago • 41 comments

Now that VS Code is open source, it also means that the Monaco Editor is open source (at-least to some extent).

I would really like to use this editor in my own web application for editing TypeScript files. The only problem is I can't find any documentation about how to do this. I know its possible because the editor is on TypeScript Playground and a few other places.

As far as I can tell, the open sourcing of VS Code is the first time the source code of the Monaco editor has been made public. Also, I think that the VS Code repository is the primary source of the Monaco editor (someone from Microsoft please confirm?).

So far, there have been many questions about using the Monaco Editor on Stack Overflow and other forums, but I have yet to see an official reply from Microsoft.

Can someone please provide some documentation on using the Monaco Editor in a web site, or perhaps release the source code of TypeScript Playground (There is nothing to hide now that we have the Monaco source in the VS Code repository).

Currently, the only thing keeping me from using TypeScript as a JavaScript replacement is the fact that I can't easily use the Monaco Editor inside of my web application. I'm currently using the ACE Editor with a Tern plugin I created. I don't want to go through all of the work of creating full Intellisense support for TypeScript inside of ACE because its a significant undertaking- Instead I'd rather contribute to the Monaco editor and use it as a replacement for ACE (and replace JavaScript with TypeScript).

Sevin777 avatar Nov 22 '15 13:11 Sevin777

+1 for this. Doing proper context code completion in CodeMirror and Ace is a nightmare. An open source editor that had good hooks to this kind of thing would be gold. We just need some docs on using it ;)

mackenza avatar Nov 22 '15 14:11 mackenza

@sevin7676 you are correct that the Monaco editor is contained in the vscode repository and we are working on making the Monaco Editor more easy to consume independent of VS Code.

egamma avatar Nov 22 '15 21:11 egamma

+1 making some docs on Monaco editor. So far this editor beats both codemirror and ace :)

lzantal avatar Nov 23 '15 04:11 lzantal

This is almost same as #815

malekpour avatar Dec 15 '15 14:12 malekpour

I'm eagerly awaiting this also. Don't forget to close this UserVoice suggestion when it's complete. https://visualstudio.uservoice.com/forums/293070-visual-studio-code/suggestions/7782546-release-monaco-javascript-code-editor

JoshClose avatar Dec 18 '15 19:12 JoshClose

+1, the other options like codemirror or ace does not even come close compared with typescript playground

bobzhang avatar Dec 27 '15 23:12 bobzhang

+1 Waiting for this!

pawsong avatar Dec 29 '15 13:12 pawsong

+1 Any news on this? I'm waiting for this so I can embed the editor on our product's config page where the user can edit custom TypeScripts that are run on a server and provide our API definition. Thanks!

T18970237136 avatar Jan 22 '16 11:01 T18970237136

It is still on our backlog but it didn't make the cut for the GA milestone, sorry.

egamma avatar Jan 22 '16 16:01 egamma

I've been using code mirror to bootstrap http://alm.tools/. Would like to integrate Monaco when it becomes available. I have time. It's a labor of love 🌹

basarat avatar Jan 29 '16 12:01 basarat

fyi @Microsoft/vscode

egamma avatar Jan 30 '16 16:01 egamma

+1 The editor at the typescriptlang playground is amazing! Especially the speed, intellisense, and VS look-and-feel.

Been working a lot with other code editors that offer intellisense, but none come close to Monaco. Eagerly waiting :)

Thanks for keeping us updated, @egamma

joselee avatar Feb 05 '16 21:02 joselee

+1 yes please

verbman avatar Feb 12 '16 07:02 verbman

:+1:

codler avatar Feb 26 '16 20:02 codler

While we wait for official documentation... This HTML hosts the editor (in TypeScript mode) when served from the 'out' directory VSC builds to:

<!DOCTYPE html>
<html>
<head>
<title>VSC Editor</title>
<style>
    html, body { height: 100%; margin: 0; }
    .box { display: flex; flex-flow: column; height: 100%; }
    .box .row { flex: 0 1 auto; }
    .box .row.content { flex: 1 1 auto; }
</style>
</head>
<body>
<div class='box'>
    <div class='row content' id="editor"></div>
</div>
<script type="text/javascript" src="vs/loader.js"></script>
<script type="text/javascript">
'use strict';

(function () {
    require(['vs/editor/editor.main', 'vs/base/browser/ui/aria/aria'], function (main, aria) {
        aria.setARIAContainer(document.body);

        var editor = Monaco.Editor.create(document.getElementById('editor'), {
            value: 'var foo = \'bar\';',
            mode: 'text/typescript'
        });

        window.addEventListener('resize', function () {
            editor.layout();
        });
    });
})();
</script>
</body>
</html>

darrinm avatar Mar 29 '16 19:03 darrinm

I managed to get the editor working using something similar to darrinm's solution but I still haven't figured out how to add extra libraries to the auto completion system. The azure-based playgrounds out there seem to have a way to include code libraries but the API seems different for the version in VS Code and I haven't been able to figure it out yet :(

darrylryan avatar Apr 09 '16 12:04 darrylryan

:+1:

Starcounter-Jack avatar Apr 10 '16 13:04 Starcounter-Jack

@egamma do you have a rough date on when this might be available?

bana-io avatar Apr 19 '16 07:04 bana-io

+1 please make it possible

Cryrivers avatar Apr 20 '16 06:04 Cryrivers

+1 ,I think that this feature will bring closer to this project many people who don't use vs code yet

ghost avatar Apr 20 '16 13:04 ghost