'How do I make IntelliSense in VSCode show completion from other files?

Background:

I wrote a game in Swift. Now I want to translate the game logic (the model) part to JS so that I can write another version of the game which can be played in a browser. Since Swift and JS are so different, I first translated the game to C#, then used Bridge.NET to translate the C# code to JS. Now, I want to write the UI code using the p5.js library, in JS. (Bridge.NET does not support p5.js, so I can't write the UI code in C#)

So basically, I will have an HTML file referring to a JS file containing some p5.js code, and the JS files outputted by Bridge.NET. In the UI code, I need to call some game logic code, which is in the Bridge.NET output files.

According to the Bridge.NET docs, I can call code from the output files just like normal JS, as long as I include all the output files with <script> tags.

However, VSCode, which I'm using to code all of this, does not show IntelliSense for the Bridge.NET output files, nor does it show IntelliSense for p5.js classes and members.

This is my HTML file:

<html>
  <head>
    <meta charset="utf-8" />
    <!-- These are p5.js files -->
    <script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.5.11/p5.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.5.11/addons/p5.dom.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.5.11/addons/p5.sound.min.js"></script>
    <link rel="stylesheet" type="text/css" href="style.css">
  </head>
  <body>
    <script src="scripts/sketch.js"></script> <!-- This is the file containing UI code -->
    <!-- The below are the bridge output files -->
    <script src="scripts/bridge.js"></script>
    <script src="scripts/bridge.console.js"></script>
    <script src="scripts/bridge.meta.js"></script>
    <script src="scripts/MyGame.js"></script>
    <script src="scripts/MyGame.meta.js"></script>
    <script>
    // I should be able to see IntelliSense for all my classes in the line below, but I can't.
    MyGame.
    </script>
  </body>
</html>

I have read somewhere that VSCode only supports IntelliSense for code in the same file. I read somewhere else that I need to add a jsconfig.json, so I added something like this:

{
    "compilerOptions": {
        "target": "ES6"
    }
}

but nothing changes.

There are lots of posts on SO about enabling IntelliSense on VSCode, but they are all about using npm and node, but I am just trying to get IntelliSense for client side code, so I'm not using either of those.

How do I enable IntelliSense for stuff declared in files linked with <script>?



Solution 1:[1]

Auto completion works based on typescript type declaration files - .d.ts. Most libraries already have those files available as npm packages but it doesn't apper to be the case of p5. Search in the files generated by your tool if some of these were created like MyGame.d.ts.If they were, you could add in the script you are writting a reference to it:

///<reference path=" put the filename with path here "/>

Solution 2:[2]

This worked for me after days of google searching:

Adding a jsconfig.json file following this tutorial did work for only some classes that I have created (Try testing it out with simple objects or variables. If they don't show up, you are probably doing something wrong)

After installing jshint and setting it up in vsc, I made some changes inside the problematic class based on its suggestions, which solved the issue. I can now access that class through IntelliSense from other files.

So while I don't know exactly what the issue was, I assume IntelliSense didn't like my code, or my configuration was wrong. I was probably using syntax somewhere in my class that is not recommended to use anymore, and jshint pointed that out.

note that jshint in vsc takes a bit of setup to work properly, so don't skip its configuration.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Jony ive