Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

monaco.languages.typescript.getTypeScriptWorker() ... getEmitOutput #289

Closed
AviPi opened this issue Dec 12, 2016 · 6 comments
Closed

monaco.languages.typescript.getTypeScriptWorker() ... getEmitOutput #289

AviPi opened this issue Dec 12, 2016 · 6 comments
Assignees

Comments

@AviPi
Copy link

AviPi commented Dec 12, 2016

monaco-editor npm version: 0.7.0
Browser: all
OS: Windows Server 2012 R2

I need to access to output which is the JS emitted by the TypeSript language service. My app used getEmitOutput with an old version of monaco but I can make heads and tails of the new API.

        var backgroundEditor = monaco.editor.create($('<div/>').get(0), {
            value: visualTS,
            language: "typescript"
        });
        result.promise = monaco.languages.typescript.getTypeScriptWorker();
        result.promise.then((worker: Worker) => {
            worker.then(function(client) {
                client.getEmitOutput(model.uri.toString()).then((output: monaco.editor.IModeOutput) => {
                    backgroundEditor.dispose();
                });
            });
        });
@grovesNL
Copy link

I am doing it like this, not sure if it's helpful:

const output = ts.transpileModule(editor.getValue(), {
    module: ts.ModuleKind.CommonJS,
    target: ts.ScriptTarget.ES5,
    noLib: true,
    noResolve: true,
    suppressOutputPathCheck: true
})

@jrieken
Copy link
Member

jrieken commented Jan 16, 2017

There is monaco.languages.typescript.get[Type|Java]ScriptWorker which returns a promise which resolves to a proxy of the TypeScript language service API

@jrieken jrieken closed this as completed Jan 16, 2017
@oldrich-s
Copy link

@jrieken : could you please be more explicit? I also have no idea how to proceed. When I call

monaco.languages.typescript.getTypeScriptWorker().then((worker) => { console.log(worker) })

I get back

function (e){for(var t=[],n=1;n<arguments.length;n++)t[n-1]=arguments[n];return s.getLanguageServiceWorker.apply(s,[e].concat(t))}

What shall I do with that function?

@joewood
Copy link

joewood commented Jun 7, 2017

In case other stumble on this, you can do (where uri is the monaco.Uri of the main code file):

const worker = await monaco.languages.typescript.getTypeScriptWorker();
const client = await worker(uri);
const result = await client.getEmitOutput(uri.toString());

@rjamesnw
Copy link

Why is a uri required just to get access to the code in the editor? I don't have a uri to any code file, so none of this makes any sense. I don't know why it has to be so difficult just to get the transpiled output.

@rjamesnw
Copy link

rjamesnw commented Mar 12, 2019

Ok, It was not clear before, but I see now that a model is the code in the editor. You can create models, or you can create an editor with a default model it seems; so monaco.editor.create() returns an editor, and you can use editor.getModel() to get the model associated with the editor. The model then has model.uri, which I guess is the file reference ID of sorts. The example here made it all become more clear.

@vscodebot vscodebot bot locked and limited conversation to collaborators Oct 29, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants