Search code examples
node.jsexpressvisual-studio-codecode-completion

VS code, code completion on parsed variables


I am seeking a suggestion for the code completion in VS Code. We are developing a node/express application in VS Code. We have a main javascript document app.js, which calls each page business logic based on routes which calls functions from other documents.

app.js looks like:

const uploadFunction = require("./router/uploadFunction.js);
const commonFunctions =  require("./functions/commonFunctions.js);
...
app.post("/fileupload", function(req, res) {uploadFunction.someFunction(req,res,commonFunctions)});

In the uploadFunction document we would like to use auto completion fx.

function someFunction(req, res, commonFunctions){
commonFunctions.anotherFunction <= We want this to show on the code completion list
}

I hope it makes sense, and someone have a good suggestion


Solution

  • Vs code completion works best using classes but it also can determine the content of just functions. Classess automatically expose all public functions and vars to autocompletion. Using classes implies types. Types are always good for autocompletion.

    Interface definitions work too. A class is an interface.

    For plain ole functions, any function returing one or more functions will be picked up by autocompletion.

    Also function input and return parameters are seen automatically by autocompletion. This is also true for all public properties.

    Javascript objects should work to discover key names, but types are not knowable as all things in Javascript are of type any and can morph at will.