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

How to scope intillisense down to just passed in .d.ts defs. #1001

Closed
philcockfield opened this issue Aug 14, 2018 · 7 comments
Closed

How to scope intillisense down to just passed in .d.ts defs. #1001

philcockfield opened this issue Aug 14, 2018 · 7 comments
Assignees

Comments

@philcockfield
Copy link

philcockfield commented Aug 14, 2018

I’m looking at the configuration options for the VSCode MonacoEditor related to specifying intellisense via .d.ts definitions:

Playground: Configure JS Defaults Example

// compiler options
monaco.languages.typescript.javascriptDefaults.setCompilerOptions({
    target: monaco.languages.typescript.ScriptTarget.ES6,
    allowNonTsExtensions: true
});

// extra libraries
monaco.languages.typescript.javascriptDefaults.addExtraLib([
    'declare class Facts {',
    '    /**',
    '     * Returns the next fact',
    '     */',
    '    static next():string',
    '}',
].join('\n'), 'filename/facts.d.ts');

var jsCode = [
    '"use strict";',
    '',
    "class Chuck {",
    "    greet() {",
    "        return Facts.next();",
    "    }",
    "}"
].join('\n');

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

I’m wondering if there is a way to scope intillisense down to just the types passed in via addExtraLib - at the moment the kitchen sink of ES6 is available in the dropdown lists, including all of HTML5 for the browser etc etc.

For my purposes, I’m having the editor run in a tightly constrained environment so most of the API surface area represented in these dropdowns in not relevant.

The target field of setCompilerOptions seems likely, but in playing around with that it doesn’t seem to have any effect on reducing scope, eg all of these options don't narrow scope at all:

image

ref Playground


Any ideas? It feels like this must be somewhere else in the API, yeah?
Thanks 🌵

@yln99517
Copy link

You can pass 'nolib' option to setcompileroption.

@philcockfield
Copy link
Author

philcockfield commented Aug 14, 2018

Thanks @yln99517 - that's great.

Setting nolib to true seems wipes out the HTML/Browser centric intillisense, and I am just getting my passed in .d.ts.

As a follow-on question, how would I go about dealing with this "No Promise" error:

image

I'm setting noLib and then passing in ES2015 to lib as suggested, but no dice:

    const typescript = monaco.languages.typescript;

    typescript.typescriptDefaults.setCompilerOptions({
      noLib: true, 
      lib: ['ESNext', 'ES2015'],
      target: typescript.ScriptTarget.ESNext,
      allowNonTsExtensions: true,
    });

This has the same effect to (dropping the noLib in favor explicitly passing the lib array, which I'm wildly guessing at being the sameis effect:

    const typescript = monaco.languages.typescript;

    typescript.typescriptDefaults.setCompilerOptions({
      lib: ['ESNext', 'ES2015'],
      target: typescript.ScriptTarget.ESNext,
      allowNonTsExtensions: true,
    });

Any ideas? Thanks!

@yln99517
Copy link

You need to extract required libs from default libs then pass to addExtraLib. It solves the problem.

@philcockfield
Copy link
Author

Thanks @yln99517. Where do I find the "default libs" to extract from?

@philcockfield
Copy link
Author

I wonder if you might be able to give me a brief code sample to get me going in the right direction please @yln99517 ?

@yln99517
Copy link

yln99517 commented Aug 16, 2018

Hi ,
Goto this. You can see available libs or default libs. Pack required libs into one file or in a string. Pass the string to addExtraLib.
Hope this helps.
thanks

@philcockfield
Copy link
Author

@yln99517 - sweet! That's perfect, thanks!

@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.
Projects
None yet
Development

No branches or pull requests

4 participants