Autocomplete in Javascript for custom API

Hi all,

First of all: Thanks a lot for an amazing piece of software! I was wondering what my options are for having the autocomplete suggest methods and variables for a custom API in Javascript. We have a rather large API supporting stuff like this:

const foo = new SomethingClass();

Now, I would like to have autocomplete when I get to “foo.”, so that it lists the possible methods and member variables for SomethingClass (which I have in a structure). Getting the instance variable name (“foo”) seems pretty straightforward (using the myCompletions example), however I need to analyze further to be able to deduce the type of foo, and then show the relevant API documentation. Is there any support for doing this in the existing Javascript parser in CM? Or, could I at least use the syntaxTree somehow to get the various statements and try to figure out the type of “foo”? This does not have to be bullet proof (just like most intellisense-solutions seem to be…), but it would be nice if it worked on the easiest examples at least.

All help is highly appreciated :slight_smile:


Doing type inference (to figure out what type to complete properties from) on JavaScript is far from trivial. You could write something simple that catches a few cases, or try to somehow wire up a TypeScript language server to your editor (TypeScript is pretty good at analyzing plain JavaScript too).

1 Like