Coder Social home page Coder Social logo

Comments (11)

alexdima avatar alexdima commented on May 21, 2024 2

@jonathanhotono Here is an example: https://microsoft.github.io/monaco-editor/playground.html#extending-language-services-configure-javascript-defaults

You can of course fetch the jquery.d.ts through an xhr and then set the contents, etc.

fyi @jrieken

from monaco-editor.

windischb avatar windischb commented on May 21, 2024 2

I think i found my Problem!
i have always used
"monaco.languages.typescript.javascriptDefaults.addExtraLib" instead of
"monaco.languages.typescript.typescriptDefaults.addExtraLib"...

It works now, thanks!

from monaco-editor.

alexdima avatar alexdima commented on May 21, 2024 1

@jrieken Should we improve the sample at https://microsoft.github.io/monaco-editor/playground.html#extending-language-services-configure-javascript-defaults with a better description and/or showing how to bring in something more realistic like jquery.d.ts instead of the Facts class?

from monaco-editor.

jiron12 avatar jiron12 commented on May 21, 2024

I do understand correctly, that adding code to the language Services on the Monaco object will make 'things' from the referenced file available in all instances of the Editor?

If yes, is it possbile to reference differnent code for different editor instances?

Thanks for any suggestions
Joel

from monaco-editor.

jrieken avatar jrieken commented on May 21, 2024

If yes, is it possbile to reference differnent code for different editor instances?

No the languages are not scoped per editor instance

from monaco-editor.

jiron12 avatar jiron12 commented on May 21, 2024

Thanks for the confirmation.

And there is also no other possibility to reference external code per editor instance?

from monaco-editor.

jonathanhotono avatar jonathanhotono commented on May 21, 2024

Thanks @alexandrudima & @jrieken
monaco.languages.typescript.javascriptDefaults.addExtraLib
Should do fine. When adding this extra lib, is it also capable to read normal javascript file or only typescript reference file? If so this might answer @jiron12 question.

from monaco-editor.

jrieken avatar jrieken commented on May 21, 2024

When adding this extra lib, is it also capable to read normal javascript file or only typescript reference file?

You pass anything the TypeScript compiler given its current options accepts. So, with allowJs you can also get JS files fed into the compiler, however it doesn't really make sense. The extraLib feature is meant for providing ambient type declarations. Such that you get suggestions for a library that you have, lets say jQuery.d.ts

from monaco-editor.

windischb avatar windischb commented on May 21, 2024

I also have troubles with addExtraLib...

For testing i tried to put following in the Playground Editor:

monaco.languages.typescript.javascriptDefaults.addExtraLib([
"declare module foo {",
" export class bar {",
' public getDate():string;',
' }',
'}',
].join('\n'), 'foo.d.ts');

var jsCode = [
"import {bar} from 'foo'",
"",
"var b = new bar();",
"var t = b.getDate();"
].join('\n');

monaco.editor.create(document.getElementById("container"), {
value: jsCode,
language: "typescript"
});

All i'll get is an Error Message wich says that "Cannot find Module foo"...
screen shot 2016-07-15 at 21 31 08

from monaco-editor.

jrieken avatar jrieken commented on May 21, 2024

@windischb You declaration is incorrect - you must enclose the module name in quotes like declare mode "foo" { ... } to make it usable for import {} from "foo"

from monaco-editor.

windischb avatar windischb commented on May 21, 2024

I have tried to enclose the module name in quotes, but it doesn't work either...
image

The only way i didn't get those errors is to set language to "javascript".
Can you give me a simple working example, please?

Many thanks!

from monaco-editor.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.