antiboredom / p5.vscode

A VS Code extension to generate new p5.js project files.
Other
52 stars 15 forks source link

IntelliSense not working... #19

Closed ixley closed 2 years ago

ixley commented 3 years ago

I have been unable to get IntelliSense working with P5 definitions and figured I'd report it here in case it's an issue with the extension (or there are known issues with getting it to work).

I'm fairly new to VSCode but have found other IntelliSense definitions seem to be working, such as defaults for javascript or Processing (PDE) definitions via the Processing Language extension...

I'm on the latest version of VSCode (1.52.1, Mac) and the latest version of this extension (p5-vscode-1.2.6). Not sure what else to try..

This snag aside, big thanks for making this extension! The Live Server integration is incredibly helpful and I'm really hoping to get the IntelliSense helpers working too.

ixley commented 3 years ago

I finally found the issue. The built-in TypeScript and JavaScript Language Features in VSCode was not enabled. (I'm not clear if this isn't enabled by default or it just got disabled somehow...) As soon as I enabled it, p5 started working with IntelliSense. 😌

antiboredom commented 3 years ago

Hi @ixley - very glad you're liking it and thanks for posting how you sorted out the intellisense thing. I'll keep this in mind in case other people run into the same issue...

scrich commented 3 years ago

I have a similar issue. I am working on a project that has several sketches in different folders, so I have moved the library to the level above the sketches. Ie, from index.html it is at ../libraries/p5.min.js. Then I have edited settings.json in the project folder so the middle line refers to the libraries folder. Often the intellisense isn't working. How can I turn it back on as @ixley mentions?

To make things more complicated - I am using github to share my code across a Mac and a PC, so the path to .vscode/extensions/samplavigne.p5-vscode-1.2.6/p5types/global.d.ts is not the same on the two machines.

Is it possible to use p5.vscode with a library at a higher level? thanks

antiboredom commented 3 years ago

hi @scrich - I hadn't really considered your use case! I think the best thing for you to do would be to move jsconfig.json file into the topmost folder of your project. To deal mac/pc issue I think the easiest (but not necessarily the best) fix is to copy the folder containing the types into your project folder, and then update jsconfig.json to point to that location.

I do need to find a better solution for this - I'm also pretty sure that the types are getting lost when the extension gets updated...

ixley commented 3 years ago

I also noticed similar limitations of needing to rely on a path in the jsconfig file but I don't know how easy or difficult it is to make the P5 typing definitions available more globally. (Even relying on a static path that changes when the extension version changes makes it a tiny bit more brittle.) If it were possible, making this more globally available definitely would be a nice enhancement. (I believe the Processing Language extension does this for the java version but again, I'm not familiar with how these things are set up.)

I also have multiple projects I keep in a shared directory so I quickly tried moving the jsconfig file up a directory and setting the parent as the workspace directory to test but didn't have any luck. It seemed like my jsconfig file had to be in the same directory as my sketch files for IntelliSense to work, but again, I wasn't sure what else to try to troubleshoot.

antiboredom commented 3 years ago

@ixley thanks - I'll take a look to see how the handle things. One thing that both of you could try would be to use the p5 types package rather than rely on my apparently not-so-thought-out solution. You'd need node installed, and then can run npm install --save @types/p5 from your project's root folder. Might be a good fix while I sort this stuff out...

ixley commented 3 years ago

Thanks for the suggestions, @antiboredom. All in all, these touches I mentioned are all trivial nice-to-haves. As long as the live server feature and IntelliSense are working, I'm pretty happy. 😁

@scrich +1 to @antiboredom's suggestion of using Node to install the types within your project if you need a more local path. If you have it in the top directory of your workspace, and your project directories are all children, just make sure you have the wildcard set to include child directories (which is what I left out before)β€”**/*.js instead of just *.js.

"include": [
    "**/*.js",
    "node_modules/@types/p5/global.d.ts"
scrich commented 3 years ago

@antiboredom @ixley thanks for your advice. I've tried moving the p5types folder into the root of my project, alongside libraries. Then I have this 'jsconfig.json` also in the root:

{
  "include": [
    "**/*.js",
    "libraries/*.js",
    "p5types/global.d.ts"
  ]
}

That seems to have IntelliSense working in the subfolders as long as I remove the local jsconfig.json from those folders. I'm reasonably confident this will work when I commit and work on the code in windows/mac versions of vscode. Thanks!