Search code examples
javascriptintellij-ideatypescriptcode-completionnashorn

IntelliJ: Autocomplete object as function-parameter


I'm using IntelliJ IDEA as an IDE for development which also involves JavaScript-development. My fundamental aim is to make code-completion work in the IDE in the following way with my own "library". The "library", to be exact, is Nashorn delegating special calls to Java. I am currently evaluating if TypeScript and DefinitelyTyped could solve my problem of code-completion.

I have a function that I want to be called as follows:

obj.func("", false, {
    xyz: "",
    abf: "",
    f7d: 17.5,
    cccts: true
});

The parameters in detail are just examples. Notice that there is one parameter that is an JavaScript-object and that has a whole bunch of defined but not easy-to-memorize attributes. I want the IDE to code-complete not just the function, but also the possible attributes in the inner object.

My try, using TypeScript, is the following:

function func(
    p1:string,
    p2?:boolean,
    p3?:{
        xyz: string;
        abf: string;
        f7d: number;
        cccts: boolean;
    }
):void;

This works well as the IDE tells me what the functions name is, what parameters it expects and what types are needed. Nevertheless, after typing the opening curly bracket of p3, I get no further code-completion of what should or could be inserted in the object. I can even type something like "ccc", but the IDE has nothing to auto-complete anymore. I wrote down the whole signature in TypeScript - so either I wrote the information down in a wrong way or the IDE does not use it as I expect it to do.

So far is my knowledge - can anyone of you tell me, how to make IntelliJ IDEA autocomplete this objects attributes, too? I hope so!

Best wishes and thanks in advance, Dennis


Solution

  • The intellisence correctly show up on the playground and stuff like atom-typescript :

    enter image description here

    IntelliJ uses its own implementation of the language service. That has its positives (does more) and negatives (does less e.g. in your given example). Solution is to raise a bug with JetBrains and wait for a release (fairly quick).